diff options
| author | mike <mike@d8baa203-390c-0410-a584-dba4c0749223> | 2011-07-16 18:53:45 +0000 |
|---|---|---|
| committer | mike <mike@d8baa203-390c-0410-a584-dba4c0749223> | 2011-07-16 18:53:45 +0000 |
| commit | 3005ed13f0fde6d61ab8a229c1490f9389cd75b5 (patch) | |
| tree | 737c067dc4ceb0e4cee26e3e5f60ef91f8e71cdb /src/neuron.h | |
| parent | 6bf9a32cf42b3f1a6dad7018d1b1925cc909b585 (diff) | |
| download | libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.tar.gz libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.tar.bz2 libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.tar.xz libneural-3005ed13f0fde6d61ab8a229c1490f9389cd75b5.zip | |
Everything is in place except for columns, networks, and a cute language for
describing the networks. ...and tests, don't forget about tests.
git-svn-id: http://svn.xagasoft.com/misc/libneural/trunk@470 d8baa203-390c-0410-a584-dba4c0749223
Diffstat (limited to '')
| -rw-r--r-- | src/neuron.h | 71 |
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 | |||
| 7 | namespace 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 | ||
