summaryrefslogtreecommitdiff
path: root/src/neuron.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/neuron.h')
-rw-r--r--src/neuron.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/neuron.h b/src/neuron.h
new file mode 100644
index 0000000..dc30471
--- /dev/null
+++ b/src/neuron.h
@@ -0,0 +1,71 @@
1#ifndef NEURAL_NEURON_H
2#define NEURAL_NEURON_H
3
4#include "neural/node.h"
5#include "neural/slope.h"
6
7namespace Neural
8{
9 template<typename sigtype>
10 class Neuron : public Node<sigtype>
11 {
12 public:
13 Neuron() :
14 iInputs( 0 ),
15 aWeights( 0 ),
16 sBias( 0.0 ),
17 pSlope( 0 )
18 {
19 }
20
21 virtual ~Neuron()
22 {
23 delete[] aWeights;
24 delete pSlope;
25 }
26
27 virtual void finalize( int iNumInputs )
28 {
29 iInputs = iNumInputs;
30 aWeights = new sigtype[iInputs];
31 }
32
33 virtual void process( sigtype *aInput, sigtype *aOutput )
34 {
35 sigtype sOutput = sBias;
36 for( int j = 0; j < iInputs; j++ )
37 {
38 sOutput += aWeights[j] * aInput[j];
39 }
40 *aOutput = (*pSlope)( sOutput );
41 }
42
43 virtual int getNumInputs() const
44 {
45 return iInputs;
46 }
47
48 virtual int getNumOutputs() const
49 {
50 return 1;
51 }
52
53 virtual int getNumWeights() const
54 {
55 return iInputs;
56 }
57
58 virtual int getNumBiases() const
59 {
60 return 1;
61 }
62
63 private:
64 int iInputs;
65 sigtype *aWeights;
66 sigtype sBias;
67 Slope<sigtype> *pSlope;
68 };
69};
70
71#endif