#ifndef NEURAL_NEURON_H #define NEURAL_NEURON_H #include "neural/node.h" #include "neural/slope.h" #include "neural/slopestd.h" #include namespace Neural { template class Neuron : public Node { public: Neuron() : iInputs( 0 ), aWeights( 0 ), sBias( 0.0 ), pSlope( new Neural::SlopeStd() ) { } 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 *pSlope; }; }; #endif