CUDA Networks
|
Represents a simple feedforward neural network with one hidden layer. More...
#include <neural_network.h>
Public Member Functions | |
NeuralNetwork (int input_size, int hidden_size, int output_size) | |
Construct a new NeuralNetwork object. More... | |
~NeuralNetwork () | |
Destroy the NeuralNetwork object. More... | |
void | initialize () |
Initialize the neural network parameters. More... | |
void | forward (const Matrix &X) |
Perform forward propagation through the network. More... | |
void | backward (const Matrix &X, const Matrix &Y) |
Perform backward propagation through the network. More... | |
void | update_params (double learning_rate) |
Updates the network parameters based on computed gradients. More... | |
Vector | get_predictions () const |
Get predictions from the output layer (A2) More... | |
double | get_accuracy (const Matrix &Y) const |
Calculate the accuracy of predictions compared to true labels. More... | |
void | gradient_descent (const Matrix &X, const Matrix &Y, double learning_rate, int epochs) |
Perform gradient descent to train the neural network. More... | |
double * | get_W1_data () const |
Get the pointer to the W1 matrix data. More... | |
double * | get_W2_data () const |
Get the pointer to the W2 matrix data. More... | |
double * | get_b1_data () const |
Get the pointer to the b1 vector data. More... | |
double * | get_b2_data () const |
Get the pointer to the b2 vector data. More... | |
std::pair< int, int > | get_W1_dimensions () const |
Get the dimensions of the W1 matrix. More... | |
std::pair< int, int > | get_W2_dimensions () const |
Get the dimensions of the W2 matrix. More... | |
int | get_b1_size () const |
Get the size of the b1 vector. More... | |
int | get_b2_size () const |
Get the size of the b2 vector. More... | |
Matrix | get_DW1 () const |
Get the DW1 matrix. More... | |
double | get_db1 () const |
Get the db1 scalar. More... | |
Matrix | get_DW2 () const |
Get the DW2 matrix. More... | |
double | get_db2 () const |
Get the db2 scalar. More... | |
double * | get_A_data () const |
Get the pointer to the A matrix data (input matrix) More... | |
std::pair< int, int > | get_A_dimensions () const |
Get the dimensions of the A matrix. More... | |
double * | get_Z1_data () const |
Get the pointer to the Z1 matrix data (pre-activation of hidden layer) More... | |
std::pair< int, int > | get_Z1_dimensions () const |
Get the dimensions of the Z1 matrix. More... | |
double * | get_A1_data () const |
Get the pointer to the A1 matrix data (activation of hidden layer) More... | |
std::pair< int, int > | get_A1_dimensions () const |
Get the dimensions of the A1 matrix. More... | |
double * | get_Z2_data () const |
Get the pointer to the Z2 matrix data (pre-activation of output layer) More... | |
std::pair< int, int > | get_Z2_dimensions () const |
Get the dimensions of the Z2 matrix. More... | |
double * | get_A2_data () const |
Get the pointer to the A2 matrix data (activation of output layer) More... | |
std::pair< int, int > | get_A2_dimensions () const |
Get the dimensions of the A2 matrix. More... | |
Represents a simple feedforward neural network with one hidden layer.
Definition at line 16 of file neural_network.h.
NeuralNetwork::NeuralNetwork | ( | int | input_size, |
int | hidden_size, | ||
int | output_size | ||
) |
Construct a new NeuralNetwork object.
input_size | Number of input features |
hidden_size | Number of neurons in the hidden layer |
output_size | Number of output classes |
Definition at line 8 of file neural_network_constructor.cu.
NeuralNetwork::~NeuralNetwork | ( | ) |
Destroy the NeuralNetwork object.
Definition at line 8 of file neural_network_destructor.cu.
Perform backward propagation through the network.
X | Input data matrix |
Y | True labels matrix |
Definition at line 8 of file neural_network_backward.cu.
void NeuralNetwork::forward | ( | const Matrix & | X | ) |
Perform forward propagation through the network.
X | Input data matrix |
Definition at line 8 of file neural_network_forward.cu.
|
inline |
Get the pointer to the A1 matrix data (activation of hidden layer)
Definition at line 177 of file neural_network.h.
|
inline |
Get the dimensions of the A1 matrix.
Definition at line 183 of file neural_network.h.
|
inline |
Get the pointer to the A2 matrix data (activation of output layer)
Definition at line 201 of file neural_network.h.
|
inline |
Get the dimensions of the A2 matrix.
Definition at line 207 of file neural_network.h.
|
inline |
Get the pointer to the A matrix data (input matrix)
Definition at line 153 of file neural_network.h.
|
inline |
Get the dimensions of the A matrix.
Definition at line 159 of file neural_network.h.
double NeuralNetwork::get_accuracy | ( | const Matrix & | Y | ) | const |
Calculate the accuracy of predictions compared to true labels.
Y | True labels matrix |
Definition at line 22 of file neural_network_get_accuracy.cu.
|
inline |
Get the pointer to the b1 vector data.
Definition at line 93 of file neural_network.h.
|
inline |
Get the size of the b1 vector.
Definition at line 117 of file neural_network.h.
|
inline |
Get the pointer to the b2 vector data.
Definition at line 99 of file neural_network.h.
|
inline |
Get the size of the b2 vector.
Definition at line 123 of file neural_network.h.
|
inline |
|
inline |
|
inline |
|
inline |
Vector NeuralNetwork::get_predictions | ( | ) | const |
Get predictions from the output layer (A2)
Definition at line 7 of file neural_network_get_predictions.cu.
|
inline |
Get the pointer to the W1 matrix data.
Definition at line 81 of file neural_network.h.
|
inline |
Get the dimensions of the W1 matrix.
Definition at line 105 of file neural_network.h.
|
inline |
Get the pointer to the W2 matrix data.
Definition at line 87 of file neural_network.h.
|
inline |
Get the dimensions of the W2 matrix.
Definition at line 111 of file neural_network.h.
|
inline |
Get the pointer to the Z1 matrix data (pre-activation of hidden layer)
Definition at line 165 of file neural_network.h.
|
inline |
Get the dimensions of the Z1 matrix.
Definition at line 171 of file neural_network.h.
|
inline |
Get the pointer to the Z2 matrix data (pre-activation of output layer)
Definition at line 189 of file neural_network.h.
|
inline |
Get the dimensions of the Z2 matrix.
Definition at line 195 of file neural_network.h.
void NeuralNetwork::gradient_descent | ( | const Matrix & | X, |
const Matrix & | Y, | ||
double | learning_rate, | ||
int | epochs | ||
) |
Perform gradient descent to train the neural network.
X | Input data matrix |
Y | True labels matrix |
learning_rate | Learning rate for parameter updates |
epochs | Number of training epochs |
Definition at line 10 of file neural_network_gradient_descent.cu.
void NeuralNetwork::initialize | ( | ) |
Initialize the neural network parameters.
Definition at line 9 of file neural_network_initialize.cu.
void NeuralNetwork::update_params | ( | double | learning_rate | ) |
Updates the network parameters based on computed gradients.
learning_rate | The learning rate for the parameter update. |
Definition at line 8 of file neural_network_update_params.cu.