Deep Feedforward Networks Overview
Deep Feedforward Networks Overview
[Link]/Key Components:
1. Input Layer: Receives the input data.
2. Hidden Layers: One or more layers between the input and output layers.
These layers extract and transform features from the input data.
3. Output Layer: Produces the final output, which can be a classification or
regression prediction.
4. Neurons: Each neuron in a layer receives inputs from the previous layer,
performs a weighted sum of these inputs, applies an activation function, and
passes the result to the next layer.
5. Activation Functions: Non-linear functions that introduce non-linearity into
the network, allowing it to learn complex patterns. Common activation
functions include ReLU (Rectified Linear Unit), sigmoid, and tanh
a.
b.
[Link] it Works:
Input: The input data (e.g., features of an image) is fed into the input layer.
Propagation: The input data is propagated through the network, layer by
layer.
Each neuron in a layer calculates its output using the following formula:
where:
[Link] Optimization:
Gradient Descent: The most common optimization algorithm used in
deep feedforward networks.
[Link]:
"Deep" refers to having multiple hidden layers.
Training Process:
Initialize weights randomly.
Forward pass to compute the predictions.
Compute the loss using a suitable loss function (e.g.,
cross-entropy for classification).
Backpropagate the error to compute gradients.
Update weights using an optimization algorithm (e.g.,
gradient descent).
Repeat the process for multiple iterations (epochs) until the
model converges (i.e., the loss function reaches a minimum).
Gradient-Based Learning:
Neural Network Training:
Training a neural network is similar to training any other machine learning
model using gradient descent.
Non-linearity in Neural Networks:
The biggest difference between neural networks and linear models is the
non-linearity of neural networks.
Non-linearity makes loss functions non-convex, meaning they have multiple
minima and can make optimization more difficult.
Optimization and Convergence:
Neural networks are usually trained using iterative, gradient-based
optimizers to minimize the cost function, which is not as straightforward as
solving linear equations in models like linear regression.
Convex optimization methods (like those used in logistic regression or
SVMs) guarantee global convergence, but this is not the case with non-
convex problems.
Stochastic Gradient Descent (SGD):
SGD is applied to non-convex loss functions, and unlike convex problems, it
does not guarantee convergence to a global minimum.
The convergence of SGD can be sensitive to various factors, such as the
initialization of parameters.
Gradient-based Learning for neural networks:
Initialization:
Weights: For feedforward neural networks, it is common to initialize all
weights to small random values.
Biases: Biases can be initialized to zero or small positive values.
Training Phase:
During the training phase, gradient descent is used to minimize the cost
function by updating the weights based on the gradient of the loss.
Comparison with Other Models:
Linear regression and SVM models can use gradient descent for larger
training sets. However, the gradient calculation in neural networks is more
complex due to the non-linear structure but can still be computed efficiently.
Gradient Computation:
The gradient is computed using the back-propagation algorithm, which
calculates the gradient of the loss function with respect to each weight in the
network.
The total cost function is what is minimized during the training of a neural
network. It measures the difference between the predicted output and the
actual output (labels).
Most neural networks use maximum likelihood for training, and the cost
function in this case is the negative log-likelihood, often referred to as
cross-entropy. It measures the divergence between the training data
distribution and the model's output distribution.
For effective learning, the gradient of the cost function should be large
enough to drive meaningful updates to the weights during training. If the
gradient becomes too small, learning becomes slow or may stop altogether.
Saturation of Functions:
If activation functions (e.g., sigmoid, tanh) saturate, they can become very
flat, leading to vanishing gradients (very small gradient values). This can
significantly hinder learning as the model stops adjusting the weights
meaningfully.
Negative Log-Likelihood:
To find the parameter values (θ) that maximize the likelihood of observing the given data.
P(D|θ): This represents the likelihood of the data given the model
parameters.
∑: The summation symbol indicates that we're summing over all data points.
m: The total number of data points.
y_i: The actual target value for the i-th data point (either 0 or 1).
ŷ_i: The predicted probability of the i-th data point belonging to class 1.
log(): The natural logarithm function.
Interpretation:
The equation calculates the log-likelihood by summing the contributions from each
data point.
The number and type of output units depend on the specific task or problem the
neural network is designed to solve.
Example:
c. For a binary classification task (e.g., "Is this spam?"), the network
might have one output unit that produces a probability.
d. For a multiclass task (e.g., digit classification 0-9), the network could
have 10 output units (one for each digit).
2. For Regression Problems:
a. Single Output Unit: In regression tasks (e.g., predicting house
prices), the output unit typically does not use an activation function
like softmax or sigmoid and directly outputs a continuous value (real
number).
b. Multiple Output Units: In cases where multiple continuous values
need to be predicted simultaneously, the output layer can have
multiple units, each predicting a different value.
Example:
c. In predicting house prices, the network might have one output unit
representing the predicted price.
d. For multi-output regression (e.g., predicting several attributes like
weight and height), there could be multiple output units, one for each
attribute.
Use Case: Rarely used in output layers (mostly used in hidden layers), but
can handle specific unbounded positive outputs in regression.
Use Case: Modeling outputs that are strictly positive, e.g., in Poisson
regression for count data.
8. Softplus Output Units
Choosing optimizer
An optimizer in machine learning refers to the algorithm or method used to update
the model's parameters (like weights) during training in order to minimize the loss
function. The goal of an optimizer is to find the optimal values of these parameters
that minimize the error between the model's predictions and the actual target
values.
Key Types of Optimizers:
Gradient Descent:
Hidden Units
Each hidden unit applies a weighted sum of its inputs, followed by an
activation function (e.g., ReLU, sigmoid, or tanh) to introduce non-
linearity, allowing the network to learn more complex patterns.
1 Rectified Linear Units and Their Generalizations
Definition
This means that if the input x is positive, the output is x; otherwise, the output is 0.
Key Properties:
Non-linearity: ReLU introduces non-linearity into neural networks, which is
essential for learning complex patterns.
Sparsity: Many neurons in a ReLU network may have zero activations, which
can improve computational efficiency.
Dying ReLU Problem: One potential issue with ReLU is the "dying ReLU"
problem, where neurons can become stuck in a state where they always
output 0. This can reduce the network's learning capacity. Techniques like
Leaky ReLU and Parametric ReLU can help mitigate this problem.
Advantages of ReLU:
Faster convergence: ReLU can often lead to faster training compared to
other activation functions like sigmoid or tanh.
Reduced vanishing gradient problem: ReLU helps to alleviate the
vanishing gradient problem, which can occur in deep neural networks.
Definition
Disadvantages:
Can suffer from the vanishing gradient problem when used in deep neural
networks.
The vanishing gradient problem is a phenomenon that occurs in deep
neural networks where the gradients of the error with respect to the
weights in the earlier layers become very small during training. This
can make it difficult for the network to learn effectively, especially for
deep networks with many layers.
Computationally expensive.
2. Hyperbolic Tangent (tanh) Function
Definition
Advantages:
Disadvantages:
Softmax Units:
Typically used in output layers to represent probability distributions.
Hard Tanh:
Architecture design:
Fig: The test set accuracy consistently increases with increasing depth.
BackPropagation:
Forward Propagation: The process of input data flowing through the
network to produce an output.
Backward Propagation: The process of calculating the gradient of the cost
function with respect to the network's parameters.
Gradient Calculation: Backpropagation efficiently computes the gradient
using a simple procedure.
1 .Computational Graphs:
Definition:
A computational graph is a formal way to represent
operations in neural networks where each node represents
a variable (e.g., scalar, vector, matrix, tensor).
Operations:
An operation is a function applied to one or more
variables. Complex functions can be described by
combining multiple simple operations.
Consider a neural network with two hidden layers and an output layer. Let's
denote the output of the first hidden layer as h1, the output of the second
hidden layer as h2, and the final output as y. The error function is denoted as
J(y).
To calculate the gradient of the error with respect to the weights in the first
hidden layer, we can use the chain rule:
This equation breaks down the gradient calculation into three parts:
1. dJ/dh2: The gradient of the error with respect to the output of the
second hidden layer.
2. dh2/dh1: The gradient of the output of the second hidden layer with
respect to the output of the first hidden layer.
3. dh1/dw1: The gradient of the output of the first hidden layer with
respect to its weights.
Back propagation Algorithm:
Backpropagation is a supervised learning algorithm used to
train artificial neural networks. It's a method for calculating the
gradient of the error function with respect to the network's
weights and biases, allowing the network to learn from its
mistakes and improve its performance.
1. Forward Propagation:
a. Input data is fed into the network's input layer.
b. The data passes through the hidden layers, with each
layer applying an activation function to its weighted
sum of inputs.
c. The final output layer produces a predicted output.
2. Calculate Error:
a. The error between the predicted output and the actual
target is calculated using a loss function (e.g., mean
squared error, cross-entropy).
3. Backward Propagation:
a. The error is propagated backward through the network,
layer by layer.
b. At each layer, the gradient of the error with respect to
the weights and biases is calculated using the chain
rule.
c. These gradients are used to update the weights and
biases using an optimization algorithm like gradient
descent.
4. Repeat: Steps 1-3 are repeated until the network reaches a
desired level of accuracy or a stopping criterion is met.
Example: [Link]
Underfitting occurs when a model is too simple to capture the underlying patterns
in the data. As a result, it performs poorly on both the training and validation data.
Bias refers to the systematic error that occurs when a model is too simple to
capture the underlying patterns in the data. A high-bias model underfits the data,
leading to poor performance both on the training and test sets.
High Bias (Underfitting): The left graph shows a simple linear model
that underfits the data. It fails to capture the underlying trend and has a
high bias.
High Variance (Overfitting): The right graph shows a complex
polynomial model that overfits the data. It captures the noise in the
training data and performs poorly on unseen data.
Regularization:
Without Regularization:
With L1 Regularization:
If 3 of the 10 features are not important, their weights will shrink to exactly
zero.
The model will only keep the 7 relevant features, making it simpler and more
robust.
Here, λ (the regularization coefficient) controls the influence of the penalty term.
Higher values of λ increase the impact of the regularization.
Example:
Without Regularization:
With L2 Regularization:
The model will still use all 10 features, but their weights will be smaller.
Irrelevant features will have very small weights but not zero.
During training, the regularized loss function combines the original loss function
(such as cross-entropy or mean squared error) with a penalty term. This penalty
term, defined by a norm constraint (often L1 or L2), acts as a regularizer, limiting
the size of the model parameters. The purpose is to control the model's complexity
and prevent overfitting.
The diagram shows how L2 regularization (weight decay) changes the process
of finding the best weights (w1 and w2 ) in a machine learning model.
The solid ellipses represent the loss function without any regularization.
They show how "good" or "bad" a certain combination of w1 and w2 is for
Key Idea
A norm penalty (like L1 or L2 regularization) added to the loss function can be
expressed equivalently as an optimization problem with a constraint.
1. Unconstrained Optimization with Norm Penalty:
The regularized loss function is:
Examples:
Advantages
Flexibility: Reformulating as constraints gives better control over the model.
Interpretability: Helps understand the impact of regularization on
optimization.
Limitations
Computational Complexity: Solving constrained optimization problems can
be more challenging.
Parameter Tuning: Choosing τ requires careful cross-validation
Lagrange Multiplier:
The Lagrangian:
The Lagrangian function combines the original objective function with the constraints multiplied
by their respective Lagrange multipliers. Here, the constraint is that Ω(θ) should be less than
or equal to k. The Lagrangian is then defined as:
The Goal:
The goal is to find the optimal value of θ that minimizes the Lagrangian function. This
involves finding the right balance between minimizing the loss function and satisfying
the constraint on the norm of the parameters.
Norm Violation: This means that the current parameter values θ lead to a norm that
exceeds the specified limit k.
Increasing α: To penalize this violation, the Lagrange multiplier α should be increased.
Effect of Increased α: A larger α will increase the contribution of the constraint term in
the Lagrangian, making it more costly for the optimization algorithm to choose parameter
values that violate the constraint.
Norm Within Limits: The current parameter values satisfy the constraint.
Decreasing α: In this case, a smaller α is sufficient to maintain the constraint.
Effect of Decreased α: A smaller α reduces the impact of the constraint term, allowing
the optimization algorithm to focus more on minimizing the objective function.
In essence:
α acts as a tuning parameter that balances the trade-off between minimizing the objective
function and satisfying the constraint.
By adjusting α, we can control the degree to which the constraint is enforced.