FlexNN 1
Fully connected neural network built from scratch with flexible n-layer design and multiple activations.
Loading...
Searching...
No Matches
FlexNN.h
Go to the documentation of this file.
1
11#ifndef FlexNN_H
12#define FlexNN_H
13
14#include <vector>
15#include <Eigen/Dense>
16
17#include "Layer.h"
18
27namespace FlexNN
28{
38 {
39 public:
45 NeuralNetwork(const std::vector<Layer> &layers) : layers(layers) {}
46
58 void train(const Eigen::MatrixXd &input, const Eigen::MatrixXd &target, double learningRate, int epochs);
59
69 double accuracy(const Eigen::MatrixXd &X, const Eigen::MatrixXd &Y);
70
80 Eigen::MatrixXd predict(const Eigen::MatrixXd &input)
81 {
82 auto outputs = forward(input);
83 return outputs.back(); // Return the final output (activation of the last layer)
84 }
85
86 private:
93 std::vector<Layer> layers;
94
104 std::vector<Eigen::MatrixXd> forward(const Eigen::MatrixXd &input);
105
116 std::vector<Eigen::MatrixXd> backward(const std::vector<Eigen::MatrixXd> &outputs, const Eigen::MatrixXd &target);
117
127 void updateWeights(const std::vector<Eigen::MatrixXd> &gradients, double learningRate);
128 };
129}
130
131#endif // FlexNN_H
Header file for the Layer class in the FlexNN neural network library.
Class representing a neural network.
Definition FlexNN.h:38
void train(const Eigen::MatrixXd &input, const Eigen::MatrixXd &target, double learningRate, int epochs)
Train the neural network.
Definition FlexNN.cpp:29
NeuralNetwork(const std::vector< Layer > &layers)
Constructor for the NeuralNetwork class.
Definition FlexNN.h:45
double accuracy(const Eigen::MatrixXd &X, const Eigen::MatrixXd &Y)
Calculate the accuracy of the neural network.
Definition FlexNN.cpp:53
Eigen::MatrixXd predict(const Eigen::MatrixXd &input)
Predict the output for given input data.
Definition FlexNN.h:80
Namespace for the FlexNN neural network library.