LCFIVertex  0.7.2
Neuron.h
1 #ifndef NEURON_H
2 #define NEURON_H
3 
4 #include "NeuralNetConfig.h"
5 
6 #include <vector>
7 #include <iostream>
8 #include <string>
9 
10 #ifdef __CINT__
11 #include "NeuralNet.h"
12 #else
13 //namespace nnet added 15/08/06 by Mark Grimes (mark.grimes@bristol.ac.uk) for the LCFI vertex package
14 namespace nnet
15 {
16 class NeuralNet;
17 }
18 #endif
19 
20 // A simple Neuron class that defines an
21 // interface to concrete neurons.
22 // Note that neurons can only be created on
23 // the heap, i.e. you have to new them.
24 
25 //namespace nnet added 15/08/06 by Mark Grimes (mark.grimes@bristol.ac.uk) for the LCFI vertex package
26 namespace nnet
27 {
28 
29 class
30 #ifndef __CINT__
31 NEURALNETDLL
32 #endif
33 Neuron
34 {
35 public:
36  double output(const std::vector<double> &inputValues) const;
37  double derivativeOutput(const std::vector<double> &inputValues) const;
38  std::vector<double> weights() const {return _weights;}
39  double bias() const {return _bias;}
40  int numberOfWeights() {return (int)_weights.size();}
41  void setWeights(const std::vector<double> &newWeights);
42  void serialise(std::ostream &os) const;
43  virtual void destroy() const = 0;
44  virtual Neuron *clone(const NeuralNet *parentNetwork) const = 0;
45  virtual void outputRange(double &outputmin,double &outputmax) const = 0;
46 
47 protected:
48  Neuron(const int numberOfInputs,const double bias,const NeuralNet *parentNetwork=0);
49  virtual ~Neuron(void);
50  virtual double thresholdFunction(const double activation) const = 0;
51  virtual double derivative(const double x) const = 0;
52  virtual void serialiseExtra(std::ostream &os) const {};
53  virtual std::string neuronType() const = 0;
54 
55 private:
56  double activation(const std::vector<double> &inputs) const;
57 
58 protected:
59  const int _numberOfInputs;
60  const double _bias;
61  std::vector<double> _weights;
62  const NeuralNet *_parentNetwork;
63 };
64 
65 }//namespace nnet
66 
67 #endif