-
Notifications
You must be signed in to change notification settings - Fork 1
/
CNeuralNet.h
101 lines (66 loc) · 2.11 KB
/
CNeuralNet.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef CNEURALNET_H
#define CNEURALNET_H
//------------------------------------------------------------------------
//
// Name: CNeuralNet.h
//
// Author: Mat Buckland 2002
//
// Desc: Class for creating a feedforward neural net.
//-------------------------------------------------------------------------
#include <vector>
#include <fstream>
#include <math.h>
#include "utils.h"
using namespace std;
//-------------------------------------------------------------------
// define neuron struct
//-------------------------------------------------------------------
struct SNeuron
{
//the number of inputs into the neuron
int m_NumInputs;
//the weights for each input
vector<double> m_vecWeight;
//ctor
SNeuron(int NumInputs);
};
//---------------------------------------------------------------------
// struct to hold a layer of neurons.
//---------------------------------------------------------------------
struct SNeuronLayer
{
//the number of neurons in this layer
int m_NumNeurons;
//the layer of neurons
vector<SNeuron> m_vecNeurons;
SNeuronLayer(int NumNeurons,
int NumInputsPerNeuron);
};
//----------------------------------------------------------------------
// neural net class
//----------------------------------------------------------------------
class CNeuralNet
{
private:
int m_NumInputs;
int m_NumOutputs;
int m_NumHiddenLayers;
int m_NeuronsPerHiddenLyr;
//storage for each layer of neurons including the output layer
vector<SNeuronLayer> m_vecLayers;
public:
CNeuralNet();
void CreateNet();
//gets the weights from the NN
vector<double> GetWeights()const;
//returns total number of weights in net
int GetNumberOfWeights()const;
//replaces the weights with new ones
void PutWeights(vector<double> &weights);
//calculates the outputs from a set of inputs
vector<double> Update(vector<double> &inputs);
//sigmoid response curve
inline double Sigmoid(double activation, double response);
};
#endif