summaryrefslogtreecommitdiff
path: root/src/neuron.h
blob: dc304713639716d983c36a69a1bd995756ad0463 (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
#ifndef NEURAL_NEURON_H
#define NEURAL_NEURON_H

#include "neural/node.h"
#include "neural/slope.h"

namespace Neural
{
	template<typename sigtype>
	class Neuron : public Node<sigtype>
	{
	public:
		Neuron() :
			iInputs( 0 ),
			aWeights( 0 ),
			sBias( 0.0 ),
			pSlope( 0 )
		{
		}

		virtual ~Neuron()
		{
			delete[] aWeights;
			delete pSlope;
		}

		virtual void finalize( int iNumInputs )
		{
			iInputs = iNumInputs;
			aWeights = new sigtype[iInputs];
		}

		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