GPLIB++
SigmoidalNeuron.h
Go to the documentation of this file.
1 #ifndef CSIGMOIDALNEURON_H
2 #define CSIGMOIDALNEURON_H
5 #include "GeneralNeuron.h"
6 #include <vector>
7 #include <boost/shared_ptr.hpp>
8 #include <boost/function.hpp>
9 
10 namespace gplib
11  {
12  /** \addtogroup neuralnet Neural Network filtering */
13  /* @{ */
14 
15  //! SigmoidalNeuron implements the main functionality of neurons in a neural network
17  {
18  public:
19  //! At the moment there are two types of neurons: bipolar and identity, they differ in their activation function
21  {
23  };
24  private:
25  //! The old weight correction for momentum adaptation
26  std::vector<double> OldDelta;
27  //! A pointer to the linear combiner used
28  boost::shared_ptr<GeneralLinearCombiner> Combiner;
29  //! Pointer to the activation function
30  boost::shared_ptr<GeneralActivationFunction> Function;
31  //! The Output, only updated in CalcOutput
32  double Output;
33  //! Correction term in the adaptation stage
34  double Delta;
35  //! The result from the linear combiner, only updated in CalcOutput to avoid multiple calculations
36  double Net;
37  //! Do we want the linear combiner to cache its output
38  bool cachedoutput;
39  //! The core routine that calculates the output of the neuron
40  virtual double CalcOutput();
41  public:
42  //! Get the last weight correction for momentum adaptation
43  virtual const std::vector<double> &GetOldDelta()
44  {
45  return OldDelta;
46  }
47  virtual std::vector<double> &SetOldDelta()
48  {
49  return OldDelta;
50  }
51  //! Return the derivative of the activation function
52  virtual double CalcDeriv(const double input)
53  {
54  return Function->CalcDeriv(input);
55  }
56  //! Get the raw output of the linear combiner
57  virtual double GetNet()
58  {
59  return Net;
60  }
61  //! Get the delta term of the weight correction formula
62  virtual double GetDelta()
63  {
64  return Delta;
65  }
66  //! Set the delta term of the weight correction formula
67  virtual void SetDelta(const double d)
68  {
69  Delta = d;
70  }
71  //! Set the bias of the linear combiner, the following functions are mostly for convenience access
72  virtual void SetBias(const double b)
73  {
74  Combiner->SetBias(b);
75  }
76  //! Get the bias of the linear combiner
77  virtual double GetBias()
78  {
79  return Combiner->GetBias();
80  }
81  //! Get the weights
82  virtual const std::vector<double> &GetWeights()
83  {
84  return Combiner->GetWeights();
85  }
86  //! Set the weights
87  virtual std::vector<double> &SetWeights()
88  {
89  return Combiner->SetWeights();
90  }
91  //! Get the input neurons
93  {
94  return Combiner->GetInput();
95  }
96  //! Set the input neurons
97  virtual void SetInput(const GeneralLinearCombiner::tinvector &input);
98  //! Set the type of neuron, determines the activation function
99  virtual void SetType(tneurontype type);
100  //! Construct neuron with a known type
101  explicit SigmoidalNeuron(tneurontype type, bool wantcached = false);
102  virtual ~SigmoidalNeuron();
103  };
104  /* @} */
105  }
106 #endif // CSIGMOIDALNEURON_H
virtual std::vector< double > & SetOldDelta()
virtual double GetDelta()
Get the delta term of the weight correction formula.
virtual std::vector< double > & SetWeights()
Set the weights.
virtual void SetDelta(const double d)
Set the delta term of the weight correction formula.
virtual const std::vector< double > & GetOldDelta()
Get the last weight correction for momentum adaptation.
virtual void SetInput(const GeneralLinearCombiner::tinvector &input)
Set the input neurons.
virtual double GetBias()
Get the bias of the linear combiner.
virtual double CalcDeriv(const double input)
Return the derivative of the activation function.
The base class for all neurons in a neural network.
Definition: GeneralNeuron.h:14
virtual void SetType(tneurontype type)
Set the type of neuron, determines the activation function.
virtual const std::vector< double > & GetWeights()
Get the weights.
SigmoidalNeuron(tneurontype type, bool wantcached=false)
Construct neuron with a known type.
virtual void SetBias(const double b)
Set the bias of the linear combiner, the following functions are mostly for convenience access...
SigmoidalNeuron implements the main functionality of neurons in a neural network. ...
virtual const GeneralLinearCombiner::tinvector & GetInput()
Get the input neurons.
virtual double GetNet()
Get the raw output of the linear combiner.
std::vector< boost::shared_ptr< GeneralNeuron > > tinvector
tneurontype
At the moment there are two types of neurons: bipolar and identity, they differ in their activation f...