Adam Optimisation :
Adam (Adaptive Moment Estimation) is an optimization algorithm for training deep learning models. It is a variant of stochastic gradient descent (SGD) that uses moving averages of the parameters to provide a running estimate of the second raw moments of the gradients; the name Adam is derived from adaptive moment estimation.
Adam is an optimization algorithm that is used to update the parameters of a deep learning model. It is a popular choice among deep learning practitioners because it is computationally efficient, has low memory requirements, and is effective at reducing the loss of the model over time. Adam is a variant of stochastic gradient descent (SGD), and it is named after the adaptive moment estimation that it uses to calculate the running averages of the gradient and its second raw moment.
Adam can be thought of as a combination of two other popular optimization algorithms, RMSprop and SGD with momentum. RMSprop is an extension of SGD that uses a moving average of the squared gradient to scale the learning rate, which helps to prevent the gradients from getting too large or too small. SGD with momentum is an extension of SGD that uses a moving average of the gradient to provide a “momentum” term that helps the model to converge faster. Adam combines these two algorithms by using the moving average of the gradient and the second raw moment of the gradient to calculate the adaptive learning rate for each parameter.
Adam is typically used in deep learning applications to optimize the model’s parameters. The algorithm works by calculating the gradient of the loss function with respect to each parameter in the model, and then updating the parameters in the direction that reduces the loss. The learning rate of the model is adjusted based on the gradient and the second raw moment of the gradient, which helps to prevent the model from oscillating or diverging.
Here is an example of Adam optimization in action:
# Initialize the model’s parameters
params = initialize_params(n_inputs, n_hidden, n_outputs)
# Set the learning rate and the number of training iterations
learning_rate = 0.01
n_iterations = 1000
# Initialize the Adam optimizer
optimizer = AdamOptimizer(params, learning_rate)
# Train the model for n_iterations
for i in range(n_iterations):
# Forward propagate the input
outputs = forward_propagate(inputs, params)
# Calculate the loss
loss = calculate_loss(outputs, targets)
# Backpropagate the error
gradients = backpropagate(outputs, targets, params)
# Update the model’s parameters
# Evaluate the trained model on the test data
accuracy = evaluate(test_data, params)
In this example, we initialize the model’s parameters, set the learning rate and the number of training iterations, and initialize the Adam optimizer. Then, we train the model by looping over the training data and performing forward propagation, backpropagation, and parameter update for each input. Finally, we evaluate the trained model on the test data to measure its accuracy.
Adam is an effective optimization algorithm for deep learning because it can adapt the learning rate of each parameter based on the gradient and the second raw moment of the gradient. This means that Adam can automatically adjust the learning rate to prevent the model from converging too slowly or oscillating, which can help to improve the model’s performance.