SigmoidalNeuron.h

Go to the documentation of this file.
00001 #ifndef CSIGMOIDALNEURON_H
00002 #define CSIGMOIDALNEURON_H
00003 #include "GeneralLinearCombiner.h"
00004 #include "GeneralActivationFunction.h"
00005 #include "GeneralNeuron.h"
00006 #include <vector>
00007 #include <boost/shared_ptr.hpp>
00008 #include <boost/function.hpp>
00009 
00010 namespace gplib
00011   {
00012     /** \addtogroup neuralnet Neural Network filtering */
00013     /* @{ */
00014 
00015     //! SigmoidalNeuron implements the main functionality of neurons in a neural network
00016     class SigmoidalNeuron: public GeneralNeuron
00017       {
00018     public:
00019       //! At the moment there are two types of neurons: bipolar and identity, they differ in their activation function
00020       enum tneurontype
00021         {
00022         bipolar, identity
00023         };
00024     private:
00025       //! The old weight correction for momentum adaptation
00026       std::vector<double> OldDelta;
00027       //! A pointer to the linear combiner used
00028       boost::shared_ptr<GeneralLinearCombiner> Combiner;
00029       //! Pointer to the activation function
00030       boost::shared_ptr<GeneralActivationFunction> Function;
00031       //! The Output, only updated in CalcOutput
00032       double Output;
00033       //! Correction term in the adaptation stage
00034       double Delta;
00035       //! The result from the linear combiner, only updated in CalcOutput to avoid multiple calculations
00036       double Net;
00037       //! Do we want the linear combiner to cache its output
00038       bool cachedoutput;
00039       //! The core routine that calculates the output of the neuron
00040       virtual double CalcOutput();
00041     public:
00042       //! Get the last weight correction for momentum adaptation
00043       virtual const std::vector<double> &GetOldDelta()
00044         {
00045           return OldDelta;
00046         }
00047       virtual std::vector<double> &SetOldDelta()
00048         {
00049           return OldDelta;
00050         }
00051       //! Return the derivative of the activation function
00052       virtual double CalcDeriv(const double input)
00053         {
00054           return Function->CalcDeriv(input);
00055         }
00056       //! Get the raw output of the linear combiner
00057       virtual double GetNet()
00058         {
00059           return Net;
00060         }
00061       //! Get the delta term of the weight correction formula
00062       virtual double GetDelta()
00063         {
00064           return Delta;
00065         }
00066       //! Set the delta term of the weight correction formula
00067       virtual void SetDelta(const double d)
00068         {
00069           Delta = d;
00070         }
00071       //! Set the bias of the linear combiner, the following functions are mostly for convenience access
00072       virtual void SetBias(const double b)
00073         {
00074           Combiner->SetBias(b);
00075         }
00076       //! Get the bias of the linear combiner
00077       virtual double GetBias()
00078         {
00079           return Combiner->GetBias();
00080         }
00081       //! Get the weights
00082       virtual const std::vector<double> &GetWeights()
00083         {
00084           return Combiner->GetWeights();
00085         }
00086       //! Set the weights
00087       virtual std::vector<double> &SetWeights()
00088         {
00089           return Combiner->SetWeights();
00090         }
00091       //! Get the input neurons
00092       virtual const GeneralLinearCombiner::tinvector &GetInput()
00093         {
00094           return Combiner->GetInput();
00095         }
00096       //! Set the input neurons
00097       virtual void SetInput(const GeneralLinearCombiner::tinvector &input);
00098       //! Set the type of neuron, determines the activation function
00099       virtual void SetType(tneurontype type);
00100       //! Construct neuron with a known type
00101       explicit SigmoidalNeuron(tneurontype type, bool wantcached = false);
00102       virtual ~SigmoidalNeuron();
00103       };
00104   /* @} */
00105   }
00106 #endif // CSIGMOIDALNEURON_H

Generated on Tue May 4 16:52:15 2010 for GPLIB++ by  doxygen 1.5.8