Deep Learning & Neural Networks

Chapter 1
Deep Learning Foundations and Mathematical Essentials

Advance Diploma in Artificial Intelligence and Machine Learning
Deep Learning & Neural Networks   •   Advance Diploma

Deep Learning Foundations and Mathematical Essentials

Introduction

Artificial intelligence (AI) is the broad discipline concerned with constructing systems that perform tasks commonly associated with human intelligence, including perception, reasoning, language understanding, planning and decision-making. Machine learning (ML) is a major approach within AI in which systems infer patterns from data rather than being programmed with a complete set of explicit rules. Deep learning (DL) is a subfield of ML that uses neural networks with multiple computational layers to learn increasingly abstract representations of data.

The distinction is important. A rule-based fraud detector may specify that a transaction above a threshold is suspicious. A machine-learning fraud detector may learn risk patterns from labelled historical transactions. A deep-learning detector may learn representations directly from transaction sequences, text, device information and behavioural signals, often reducing the need for manually designed features.

Deep learning is powerful because it combines three capabilities: representation learning, nonlinear function approximation and scalable optimization. However, these capabilities depend on mathematical foundations. Vectors represent observations and parameters; matrices represent transformations; tensors organize multidimensional data; probability describes uncertainty; statistics supports estimation and evaluation; calculus supplies gradients; and optimization adjusts model parameters to reduce error.

This chapter develops these foundations for practical neural-network work. It emphasizes interpretation, assumptions, dimensional correctness and responsible application rather than memorization of isolated formulas.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Distinguish AI, ML and DL and explain how they are related.
  2. Describe supervised, unsupervised and reinforcement learning.
  3. Represent data using scalars, vectors, matrices and tensors.
  4. Perform and interpret common vector and matrix operations.
  5. Explain probability, random variables, expectation, variance, covariance and Bayes’ theorem.
  6. Use derivatives, partial derivatives and the chain rule to understand backpropagation.
  7. Explain loss functions, gradient descent, learning rate and regularization.
  8. Apply these concepts to a small neural-network problem.
  9. Identify practical, ethical and governance risks in deep-learning systems.

1. Artificial Intelligence, Machine Learning and Deep Learning

AI includes symbolic reasoning, search, planning, knowledge representation, robotics and learning systems. It is therefore broader than ML. ML systems improve their performance on a task through experience represented by data. Deep learning uses neural networks containing an input layer, one or more hidden layers and an output layer.

A neural network computes a parameterized function:

ŷ = f(x; θ)

Here, x is an input, ŷ is the prediction, θ is the collection of trainable parameters, and f is the network function. Training seeks parameters that make predictions suitable for the task.

Learning paradigms

Supervised learning uses input–target pairs (xi, yi). Classification predicts a discrete category, such as defective or acceptable. Regression predicts a numerical quantity, such as energy demand. The model is trained by comparing ŷi with yi.

Unsupervised learning uses inputs without target labels. Clustering, dimensionality reduction and representation learning are examples. The objective may be to discover structure or construct useful features.

Self-supervised learning creates supervisory signals from the data itself. For example, a language model may predict a masked or next token. This permits learning from large unlabelled datasets.

Reinforcement learning involves an agent, actions, states and rewards. The agent learns a policy for selecting actions, often under delayed consequences. It differs from ordinary supervised learning because the correct action is not supplied for every state.

A typical ML workflow

A professional workflow includes problem definition, data collection, data validation, preprocessing, train–validation–test splitting, model selection, training, evaluation, deployment and monitoring. Data leakage—allowing information from the test set or future events to influence training—can produce deceptively strong results. A model must be evaluated on data representing the conditions in which it will operate.

2. Neural-Network Computation

A single artificial neuron forms a weighted sum and applies an activation function:

z = wᵀx + b
a = φ(z)

In these equations, x ∈ ℝd is an input vector with d features, w ∈ ℝd is a weight vector, b ∈ ℝ is a bias, z is the pre-activation value, φ is an activation function and a is the output. The transpose is used so that wᵀx is a scalar dot product.

Common activations include:

ReLU(z) = max(0, z)
σ(z) = 1/(1 + e^(−z))

ReLU is widely used in hidden layers because it is simple and avoids saturation for positive inputs. The sigmoid function maps a scalar to the interval (0, 1), making it useful for a binary probability output. For a multiclass output with K classes, softmax is:

pk = e^(zk) / ∑_(j=1)K e^(zj)

The outputs are non-negative and sum to one. In practice, numerical implementations subtract maxj zj from all logits before exponentiation; this does not change the probabilities but improves stability.

A multilayer network can be written recursively:

h^(ℓ) = φ^(ℓ)(W^(ℓ)h^(ℓ−1) + b^(ℓ))

where ℓ indexes the layer, h^(0) = x, W^(ℓ) is a weight matrix, b^(ℓ) is a bias vector and φ^(ℓ) is applied element by element unless otherwise specified.

3. Vectors, Matrices and Tensors

A scalar is a single number. A vector is an ordered one-dimensional collection. A matrix is a rectangular two-dimensional array. A tensor generalizes these structures to any number of dimensions. The number of axes is called the tensor’s rank or order, although terminology can vary by field.

For a batch of 64 colour images of height 32 and width 32, a common tensor shape is (64, 32, 32, 3), where the final axis stores colour channels. Shape conventions differ, so the convention must be documented.

Essential operations

For vectors a, b ∈ ℝd, the dot product is:

aᵀb = ∑_(i=1)d ai bi

The Euclidean norm is:

‖a‖₂ = √(∑_(i=1)d ai²)

The distance between two vectors is ‖a − b‖₂. The dot product can also be expressed as aᵀb = ‖a‖₂‖b‖₂ cos θ, where θ is the angle between nonzero vectors. Thus, it measures both magnitude and directional alignment.

Matrix multiplication is defined when the inner dimensions agree. If A has shape m × n and B has shape n × p, then AB has shape m × p:

(AB)_(ij) = ∑_(k=1)n A_(ik)B_(kj)

Matrix multiplication is generally not commutative: AB ≠ BA. This is a frequent source of implementation errors.

The transpose changes rows into columns. A square matrix is symmetric if A = Aᵀ. The identity matrix I satisfies AI = IA = A for compatible square matrices. An inverse A^(−1) exists only for a square, nonsingular matrix and satisfies AA^(−1) = I. Neural networks do not generally require explicit matrix inversion; solving linear systems is usually more numerically stable.

Worked example: a neuron and shape checking

Let

x = [2, 1]ᵀ, w = [0.5, −1]ᵀ and b = 0.2. Then:

z = 0.5(2) + (−1)(1) + 0.2 = −0.8

With ReLU, a = max(0, −0.8) = 0. The weight and input vectors both have shape (2,1), so their transpose product is valid and produces a scalar. If a batch contains three examples, an input matrix may have shape (3,2). Depending on the convention, the corresponding weight operation may be Xw rather than wᵀX. Shape notation should be checked at every layer.

Scaling and normalization

Features with very different scales can make optimization inefficient. Standardization uses training-set statistics:

x′ = (x − μ) / σ

where μ is the training mean and σ > 0 is the training standard deviation. The same training values must be used to transform validation, test and production data. Min–max scaling is:

x′ = (x − xmin)/(xmax − xmin)

provided xmax > xmin. Scaling does not automatically remove outliers and should not be used to conceal data-quality problems.

4. Probability and Statistics for Learning

A probability model represents uncertainty. A random variable maps outcomes to numerical values. Its probability mass function applies to discrete variables; its probability density function applies to continuous variables, for which probabilities are obtained by integration over intervals.

The expectation of a discrete variable X is:

E[X] = ∑x x P(X = x)

For a continuous variable with density p(x), it is:

E[X] = ∫ x p(x) dx

The variance measures spread around the mean:

Var(X) = E[(X − μ)²] = E[X²] − μ²

where μ = E[X]. The standard deviation is σ = √Var(X), in the same units as X.

For two variables, covariance is:

Cov(X,Y) = E[(X − μX)(Y − μY)]

Correlation standardizes covariance:

ρ_(X,Y) = Cov(X,Y)/(σX σY)

when both standard deviations are positive. Correlation indicates linear association, not causation, and a value near zero does not rule out nonlinear dependence.

Conditional probability and Bayes’ theorem

Conditional probability is:

P(A|B) = P(A ∩ B)/P(B), provided P(B) > 0

Bayes’ theorem follows as:

P(A|B) = P(B|A)P(A)/P(B)

In classification, P(y|x) represents the probability of a class given observed features. The prior P(y) and the likelihood P(x|y) are conceptually distinct. A rare disease illustrates why a highly accurate test can still produce a modest positive predictive value when the base rate is very low.

Likelihood and cross-entropy

For independent observations, a model’s likelihood is the product of probabilities assigned to observed targets:

L(θ) = ∏_(i=1)n p_θ(yi|xi)

Maximizing likelihood is equivalent to minimizing negative log-likelihood. For binary targets y ∈ {0,1} and prediction p ∈ (0,1), binary cross-entropy is:

L = −[y log p + (1 − y) log(1 − p)]

For n observations, the mean loss is the average across examples. Cross-entropy strongly penalizes confident incorrect predictions. It is appropriate when the output is interpreted as a probability under the selected modelling assumptions.

5. Calculus and Backpropagation

A derivative measures the rate at which a function changes with respect to an input. For f(x) = x², df/dx = 2x. A partial derivative changes one variable while treating other variables as fixed. The gradient of a scalar function J(θ) is the vector of partial derivatives:

∇_θ J = [∂J/∂θ1, …, ∂J/∂θm]ᵀ

The gradient points in the direction of greatest local increase. Therefore, a small step in the negative gradient direction tends to reduce the objective.

The chain rule is central to neural networks. If y = f(u) and u = g(x), then:

dy/dx = (dy/du)(du/dx)

For multiple variables, derivatives are represented by Jacobian matrices. Backpropagation applies the chain rule efficiently from the output layer toward the input, accumulating derivatives of the loss with respect to every parameter.

Worked derivative example

Consider a one-neuron linear model ŷ = wx + b with squared loss for one observation:

J = 1/2(ŷ − y)²

The factor 1/2 simplifies derivatives. Since ∂J/∂ŷ = ŷ − y, ∂ŷ/∂w = x and ∂ŷ/∂b = 1, the chain rule gives:

∂J/∂w = (ŷ − y)x
∂J/∂b = ŷ − y

Let x = 2, y = 5, w = 1 and b = 0. Then ŷ = 2, the error is −3, and the gradients are ∂J/∂w = −6 and ∂J/∂b = −3. These values indicate that increasing both parameters slightly would reduce the loss locally.

6. Optimization and Generalization

Training minimizes an objective function over parameters. For empirical risk minimization:

J(θ) = 1/n ∑_(i=1)n ℓ(f(xi;θ), yi)

where n is the number of training examples and ℓ is a loss function. Gradient descent updates parameters as:

θ_(t+1) = θt − η ∇_θ J(θt)

Here, η > 0 is the learning rate. If it is too small, training can be slow; if too large, optimization may oscillate or diverge.

Batch gradient descent uses all training examples per update. Stochastic gradient descent uses one example, while mini-batch gradient descent uses a subset. Mini-batches provide computational efficiency and noisy gradient estimates that can sometimes improve generalization.

Momentum maintains a moving direction, and adaptive methods such as Adam adjust effective step sizes using estimates of first and second moments of gradients. These methods can be useful, but they do not eliminate the need for learning-rate selection, validation and monitoring.

Regularization and generalization

A model generalizes when it performs well on unseen data. Overfitting occurs when a model learns training-specific noise or irrelevant details. Underfitting occurs when the model is too limited or insufficiently trained.

L2 regularization adds a squared-parameter penalty:

Jreg(θ) = J(θ) + λ/2 ‖θ‖₂²

where λ ≥ 0 controls penalty strength. The gradient contribution is λθ under this formulation. L1 regularization instead adds λ‖θ‖₁, which can encourage exact zeros but is not differentiable at zero; subgradient or specialized optimization methods are used.

Dropout randomly removes units during training according to a specified probability and rescales activations according to the implementation. Early stopping monitors validation performance and stops training when further training harms generalization. Data augmentation creates plausible variations, such as image crops or mild rotations, but transformations must preserve the target meaning.

7. An Integrated Illustrative Case: Predictive Maintenance

The following is a fictional but realistic illustrative case. A manufacturing company wants to predict whether a motor will require maintenance within the next seven days.

Background. Each motor produces temperature, vibration, current and rotational-speed measurements. Maintenance records identify failures and interventions.

Problem. Failures are rare, labels may be delayed, sensors may fail, and operating conditions differ across factories. A high accuracy score could be misleading if nearly all examples are non-failures.

Analysis. Engineers first define the prediction time and the information available at that time. They create time-window features or sequences while preventing future measurements from entering the input. Data is split chronologically: earlier periods for training, a later period for validation and the latest period for testing. This reduces temporal leakage.

Approach. A baseline logistic-regression model is compared with a neural network. Inputs are standardized using training-set statistics. The network produces a sigmoid probability. Binary cross-entropy is used for training. Because failures are costly to miss, recall, precision, the confusion matrix and precision–recall curves are examined in addition to accuracy. A decision threshold is selected using maintenance capacity and the relative costs of false positives and false negatives.

Outcome. Suppose the model identifies 90 of 100 failures and incorrectly flags 180 healthy motors. Recall is 90/(90+10) = 0.90. Precision is 90/(90+180) = 1/3 ≈ 0.333. The system catches most failures but generates many inspections. Whether it is useful depends on the cost of inspections, downtime avoided and available staff. Calibration should also be checked: among cases assigned a probability near 0.8, approximately 80% should fail if the probabilities are well calibrated.

Learning points. The model is not the whole solution. Label quality, temporal evaluation, threshold selection, operational capacity, monitoring and human escalation procedures determine practical value. Explanations such as influential sensors can support investigation, but they should not be treated as proof of physical causation.

8. Practical, Ethical and Governance Considerations

Deep-learning systems can amplify bias in data. Bias may arise from under-representation, historical discrimination, measurement differences, proxy variables or unequal label quality. Fairness should be assessed in relation to the application, protected groups, legal requirements and relevant metrics; no single fairness metric is universally appropriate.

Privacy requires data minimization, access control, retention limits and secure processing. Sensitive data may require consent, lawful basis, de-identification or other safeguards depending on jurisdiction. Re-identification risk can remain even after direct identifiers are removed.

Important operational practices include versioning datasets and code, recording preprocessing steps, documenting intended use and limitations, testing robustness, monitoring drift and retaining audit trails. Human oversight is essential in high-impact decisions. A model probability is not automatically a decision, and a benchmark result is not evidence of suitability in every deployment environment.

Contemporary deep learning increasingly uses transfer learning, self-supervised pretraining, attention mechanisms, foundation models and hardware accelerators. These developments improve capability but may increase compute cost, opacity, privacy exposure and dependence on large datasets. Responsible development therefore combines mathematical competence with security, documentation, evaluation and governance.

Best Practices for Neural-Network Foundations

  1. Write down tensor shapes before implementing a layer.
  2. Separate training, validation and test data before fitting preprocessing statistics.
  3. Establish a simple, interpretable baseline.
  4. Match the output activation and loss to the target and probability assumptions.
  5. Monitor both training and validation loss.
  6. Report metrics relevant to operational costs, not accuracy alone.
  7. Check calibration, subgroup performance and robustness.
  8. Use numerically stable library implementations.
  9. Record random seeds, data versions, hyperparameters and software versions.
  10. Treat deployment monitoring and human accountability as part of the model lifecycle.

Chapter Summary

AI is the broad field of intelligent computation; ML learns patterns from data; and DL uses multilayer neural networks for representation learning and nonlinear prediction. Neural neurons compute weighted sums followed by activation functions. Vectors, matrices and tensors provide the language for representing inputs, parameters, batches and intermediate activations, while shape compatibility governs valid computation.

Probability and statistics describe uncertainty, variation, dependence and likelihood. Expectation, variance, covariance, Bayes’ theorem and cross-entropy are especially important for modelling and evaluation. Calculus supplies derivatives, gradients and the chain rule, enabling backpropagation. Optimization uses gradients to update parameters, while regularization and sound validation improve generalization.

A successful deep-learning system requires more than a high training score. Data leakage prevention, appropriate metrics, calibration, fairness, privacy, security, documentation, monitoring and human oversight are essential professional responsibilities.

Key Terms

Artificial intelligence: The broad field of systems performing tasks associated with intelligence.

Machine learning: Learning patterns or functions from data to improve task performance.

Deep learning: Machine learning based on multilayer neural networks.

Feature: An input variable used by a model.

Parameter: A trainable quantity, such as a weight or bias.

Activation function: A function applied to a neuron’s pre-activation.

Tensor: A multidimensional numerical array.

Dot product: The sum of pairwise products of two compatible vectors.

Gradient: A vector of partial derivatives of a scalar function.

Loss function: A measure of prediction error used for training.

Cross-entropy: A probabilistic loss comparing target distributions with predicted distributions.

Likelihood: The probability of observed data viewed as a function of model parameters.

Expectation: The probability-weighted mean of a random variable.

Variance: The expected squared deviation from the mean.

Covariance: A measure of joint linear variation between two variables.

Backpropagation: Efficient application of the chain rule through a network.

Gradient descent: Iterative minimization using steps opposite the gradient.

Overfitting: Poor generalization caused by fitting training-specific patterns.

Data leakage: Unintended use of information unavailable at prediction time.

Calibration: Agreement between predicted probabilities and observed frequencies.

Review Questions

Short Answer Questions

  1. Distinguish artificial intelligence, machine learning and deep learning.
  2. What is the difference between a parameter and a feature?
  3. Why must matrix dimensions be checked before multiplication?
  4. Define expectation and variance.
  5. What role does the learning rate play in gradient descent?

Long Answer Questions

  1. Explain the structure and operation of a multilayer neural network, including weights, biases and activation functions.
  2. Discuss supervised, unsupervised, self-supervised and reinforcement learning, giving one application of each.
  3. Explain Bayes’ theorem and its relevance to classification under imbalanced base rates.
  4. Describe backpropagation using partial derivatives and the chain rule.
  5. Discuss overfitting, regularization, validation and generalization in deep learning.

Analytical / Application Questions

  1. A model is evaluated on a dataset containing 990 non-failures and 10 failures. Explain why accuracy alone is inadequate and recommend additional metrics.
  2. A feature has training mean 50 and standard deviation 10. Standardize an observation of 70 and explain why the same training statistics should be used during testing.
  3. Design an evaluation plan for the predictive-maintenance case that prevents temporal leakage and incorporates operational costs, calibration and human oversight.

Multiple Choice Questions with Answers

Question 1

Which statement best describes deep learning?

A. A rule-based method that does not use data

B. A branch of machine learning using multilayer neural networks

C. A database system for storing tensors

D. A statistical method limited to linear regression

Correct Answer: B. A branch of machine learning using multilayer neural networks

Question 2

If A has shape 3 × 4 and B has shape 4 × 2, what is the shape of AB?

A. 3 × 2

B. 4 × 4

C. 2 × 3

D. 3 × 4

Correct Answer: A. 3 × 2

Question 3

For x = [2, 1] and w = [0.5, −1], what is wᵀx?

A. −2.0

B. −0.5

C. 0.0

D. 2.0

Correct Answer: B. −0.5

Question 4

Which activation function maps a binary-classification logit to a value between 0 and 1?

A. ReLU

B. Sigmoid

C. Absolute value

D. Identity

Correct Answer: B. Sigmoid

Question 5

What does the gradient of a scalar loss with respect to parameters represent?

A. The model’s class labels

B. The direction of greatest local increase in loss

C. The number of training examples

D. The input tensor’s rank

Correct Answer: B. The direction of greatest local increase in loss

Question 6

In gradient descent, which update is correct?

A. θ_(t+1) = θ_t + η∇J

B. θ_(t+1) = θ_t − η∇J

C. θ_(t+1) = η − θ_t∇J

D. θ_(t+1) = θ_t/∇J

Correct Answer: B. θ_(t+1) = θ_t − η∇J

Question 7

If a classifier predicts 90 true failures and 10 missed failures, its recall is:

A. 0.10

B. 0.50

C. 0.90

D. 1.00

Correct Answer: C. 0.90

Question 8

Which practice prevents test-set information from influencing feature scaling?

A. Compute scaling statistics using the complete dataset

B. Use training-set statistics to transform all later splits

C. Scale only the test set

D. Replace all missing values with test-set means

Correct Answer: B. Use training-set statistics to transform all later splits

Question 9

What is the main purpose of L2 regularization?

A. To increase the number of classes

B. To penalize large parameter values

C. To remove the validation set

D. To guarantee zero training error

Correct Answer: B. To penalize large parameter values

Question 10

Why can accuracy be misleading for rare-event classification?

A. Accuracy cannot be computed for neural networks

B. A model can achieve high accuracy by mostly predicting the majority class

C. Accuracy always equals precision

D. Rare events make gradients mathematically undefined

Correct Answer: B. A model can achieve high accuracy by mostly predicting the majority class

Deep Learning & Neural Networks
Chapter 1 of 15