-
Notifications
You must be signed in to change notification settings - Fork 0
/
BPNN.h
55 lines (40 loc) · 1.16 KB
/
BPNN.h
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
50
51
52
53
54
#ifndef BPNN_H
#define BPNN_H
#include <vector>
#include <cmath>
#include <boost/serialization/vector.hpp>
inline double sigmoid(double x)
{
return 1.0/(1.0+exp(-x));
}
class BP_neural_networks
{
public:
BP_neural_networks() {}
BP_neural_networks(std::vector<int>& numNodes);
void train(std::vector<double>& input, std::vector<double>& output);
void getResult(std::vector<double>& input, std::vector<double>& output);
void initialWeights();
std::vector<std::vector<std::vector<double>>> mWeights;
double learningRate = 1.0;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
// for boost::archive::binary_iarchive, it may not work
// I don't know the reasons
// And not suite for xml archive
ar & learningRate;
ar & mNumLayers;
ar & mWeights;
ar & mNumNodes;
ar & mNodeValue;
ar & mErr;
}
int mNumLayers;
std::vector<int> mNumNodes;
std::vector<std::vector<double>> mNodeValue;
std::vector<std::vector<double>> mErr;
};
#endif // BPNN_H