11 const int bar_width = 50;
15 for (
int epoch = 0; epoch < epochs; ++epoch) {
29 float progress =
static_cast<float>(epoch + 1) / epochs;
30 int pos =
static_cast<int>(bar_width * progress);
34 for (
int i = 0; i < bar_width; ++i) {
35 if (i < pos) bar +=
"=";
36 else if (i == pos) bar +=
">";
42 std::cout <<
"\r" << std::setw(3) <<
static_cast<int>(progress * 100.0) <<
"% "
43 << bar << std::setw(3) << epoch + 1 <<
"/" << std::setw(3) << epochs
44 <<
" - Accuracy: " << std::fixed << std::setprecision(4) << accuracy << std::flush;
47 std::cout << std::endl;
Represents a matrix with GPU-accelerated operations.
void backward(const Matrix &X, const Matrix &Y)
Perform backward propagation through the network.
void update_params(double learning_rate)
Updates the network parameters based on computed gradients.
double get_accuracy(const Matrix &Y) const
Calculate the accuracy of predictions compared to true labels.
void forward(const Matrix &X)
Perform forward propagation through the network.
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.