7 int num_examples = 60000;
10 int hidden_size = 200;
11 double learning_rate = 0.001;
15 Matrix X_train(num_examples, input_size);
16 Matrix Y_train(num_examples, output_size);
18 std::cout <<
"Reading training data..." << std::endl;
19 X_train.
read_csv(
"data/X_train.csv");
20 Y_train.
read_csv(
"data/Y_train.csv");
23 std::cout <<
"Transposing matrices..." << std::endl;
28 std::cout <<
"Creating neural network..." << std::endl;
32 std::cout <<
"Training neural network..." << std::endl;
33 nn.
gradient_descent(X_train_transposed, Y_train_transposed, learning_rate, epochs);
36 double final_accuracy = nn.
get_accuracy(Y_train_transposed);
37 std::cout <<
"Final training accuracy: " << final_accuracy << std::endl;
39 std::cout <<
"Training completed successfully." << std::endl;
40 }
catch (
const std::exception& e) {
41 std::cerr <<
"Exception caught: " << e.what() << std::endl;
Represents a matrix with GPU-accelerated operations.
void read_csv(const char *filename)
Read data from a CSV file into the matrix.
Matrix transpose() const
Transposes the matrix and returns a new Matrix object.
Represents a simple feedforward neural network with one hidden layer.
double get_accuracy(const Matrix &Y) const
Calculate the accuracy of predictions compared to true labels.
void gradient_descent(const Matrix &X, const Matrix &Y, double learning_rate, int epochs)
Perform gradient descent to train the neural network.
Defines the NeuralNetwork class for a simple feedforward neural network.