CUDA Networks
neural_network_update_params.cu
Go to the documentation of this file.
1 /**
2  * @file neural_network_update_params.cu
3  * @brief Implementation of the NeuralNetwork::update_params method.
4  */
5 #include "neural_network.h"
6 #include <iostream>
7 
8 void NeuralNetwork::update_params(double learning_rate) {
9  // Update weights for the first layer (W1)
10  DW1.multiply_scalar(learning_rate);
11  W1 = W1.subtract(DW1);
12  // std::cout << "Updated W1:" << std::endl;
13  // W1.print(4);
14 
15  // Update bias for the first layer (b1)
16  b1.subtract_scalar(learning_rate * db1);
17  // std::cout << "Updated b1:" << std::endl;
18  // b1.print(4);
19 
20  // Update weights for the second layer (W2)
21  DW2.multiply_scalar(learning_rate);
22  W2 = W2.subtract(DW2);
23  // std::cout << "Updated W2:" << std::endl;
24  // W2.print(4);
25 
26  // Update bias for the second layer (b2)
27  b2.subtract_scalar(learning_rate * db2);
28  // std::cout << "Updated b2:" << std::endl;
29  // b2.print(4);
30 }
Matrix subtract(const Matrix &other) const
Subtracts another matrix from this matrix.
void multiply_scalar(double scalar)
Multiplies all elements in the matrix by a scalar.
void update_params(double learning_rate)
Updates the network parameters based on computed gradients.
void subtract_scalar(double scalar)
Subtracts a scalar value from all elements in the vector.
Defines the NeuralNetwork class for a simple feedforward neural network.