blob: 2ad5cfb49c1be2b042354aa5648966d03696385e (
plain)
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
|
#ifndef NEURAL_NEURON_H
#define NEURAL_NEURON_H
#include "neural/node.h"
#include "neural/slope.h"
#include "neural/slopestd.h"
#include <bu/sio.h>
namespace Neural
{
template<typename sigtype>
class Neuron : public Node<sigtype>
{
public:
Neuron() :
iInputs( 0 ),
aWeights( 0 ),
sBias( 0.0 ),
pSlope( new Neural::SlopeStd<sigtype>() )
{
}
virtual ~Neuron()
{
delete[] aWeights;
delete pSlope;
}
virtual void finalize( int iNumInputs )
{
iInputs = iNumInputs;
aWeights = new sigtype[iInputs];
}
virtual int setWeights( const sigtype *pWeights )
{
for( int j = 0; j < iInputs; j++ )
aWeights[j] = pWeights[j];
return iInputs;
}
virtual int setBiases( const sigtype *pBiases )
{
sBias = *pBiases;
return 1;
}
virtual void process( sigtype *aInput, sigtype *aOutput )
{
sigtype sOutput = sBias;
for( int j = 0; j < iInputs; j++ )
{
sOutput += aWeights[j] * aInput[j];
}
*aOutput = (*pSlope)( sOutput );
}
virtual int getNumInputs() const
{
return iInputs;
}
virtual int getNumOutputs() const
{
return 1;
}
virtual int getNumWeights() const
{
return iInputs;
}
virtual int getNumBiases() const
{
return 1;
}
private:
int iInputs;
sigtype *aWeights;
sigtype sBias;
Slope<sigtype> *pSlope;
};
};
#endif
|