-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeuralNetwork.h
More file actions
49 lines (39 loc) · 1.82 KB
/
Copy pathNeuralNetwork.h
File metadata and controls
49 lines (39 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef NEURALNETWORK_H
#define NEURALNETWORK_H
#include <vector>
#include <functional>
class NeuralNetwork {
public:
NeuralNetwork(int inputSize, const std::vector<int>& hiddenLayers, int outputSize,
std::function<double(double)> activation = [](double x) { return x > 0 ? x : 0; }, // Default ReLU
std::function<double(double)> activationDerivative = [](double x) { return x > 0 ? 1 : 0; }); // Default ReLU derivative
std::vector<double> Forward(const std::vector<double>& inputs);
void Backward(const std::vector<double>& inputs, const std::vector<double>& targets, double learningRate);
void UpdateWeights(const std::string& optimizer); // This method will be used in case of optimization or weight update.
double CalculateLoss(const std::vector<double>& targets, const std::vector<double>& outputs);
double GetLoss() const;
//priiiivaaaaatee
std::vector<int> layerSizes;
std::vector<std::vector<std::vector<double>>> weights;
std::vector<std::vector<double>> biases;
std::vector<std::vector<std::vector<double>>> weightGradients;
std::vector<std::vector<double>> biasGradients;
std::function<double(double)> activation;
std::function<double(double)> activationDerivative;
double learningRate = 0.001; // Default learning rate
double loss;
private:
// Adam optimizer parameters
std::vector<std::vector<std::vector<double>>> m_weights;
std::vector<std::vector<std::vector<double>>> v_weights;
std::vector<std::vector<double>> m_biases;
std::vector<std::vector<double>> v_biases;
double beta1 = 0.9;
double beta2 = 0.999;
double epsilon = 1e-8;
int t = 0;
void InitializeAdam(); // Initialize Adam parameters
void UpdateWeightsSGD();
void UpdateWeightsAdam();
};
#endif // NEURALNETWORK_H