Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
neuralgas.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __NEURALGAS_H
25 #define __NEURALGAS_H
26 
27 #include "abstractmodel.h"
28 #include "controller_misc.h"
29 
30 #include <vector>
31 
32 /** neural gas class. Implementation follows roughly Martinetz scheme.
33  The output of the network is \f$exp(- |x-w_i|^2/cellsize)\f$ for each neuron,
34  where cellsize is distance to the second closest neigbour.
35 */
36 class NeuralGas : public AbstractModel {
37 public:
38  NeuralGas(const std::string& name = "NeuralGas", const std::string& revision = "$Id$");
39  /** create a som
40  @param lambda initial competetive constant for neighborhood learning
41  @param eps initial learning rate
42  @param maxTime maximal time we expect the network to learn, if 0 no annealing is performed
43  */
44  NeuralGas(double lambda, double eps, int maxTime,
45  const std::string& name="NeuralGas",
46  const std::string& revision = "$Id$");
47  virtual ~NeuralGas(){};
48 
49  /** initialised som
50  @param inputDim dimension of input vector
51  @param outputDim number of outputneurons
52  @param unit_map interval for randomly choosen weights.
53  if zero then (-1,1) is used otherwise (-unit_map, unit_map) (in all dimensions)
54  */
55  virtual void init(unsigned int inputDim, unsigned int outputDim,
56  double unit_map = 0.0, RandGen* randGen = 0);
57 
58  virtual const matrix::Matrix process (const matrix::Matrix& input);
59 
60  /* performs training. Nominal output is ignored.
61  A zero matrix is returned.
62  learnRateFactor can be given to modify eps for this learning step
63  (process should be called before)
64  */
65  virtual const matrix::Matrix learn (const matrix::Matrix& input,
66  const matrix::Matrix& nom_output,
67  double learnRateFactor = 1);
68 
69  virtual void damp(double damping) { return;}
70 
71  virtual unsigned int getInputDim() const { return weights[0].getM();}
72  virtual unsigned int getOutputDim() const { return weights.size();}
73 
74 
75  virtual bool store(FILE* f) const;
76  virtual bool restore(FILE* f);
77 
78  virtual void printWeights(FILE* f) const;
79  virtual void printCellsizes(FILE* f) const;
80 
81 protected:
82  /// updates the cell sizes
83  void updateCellSizes();
84 
85  /// activation function (rbf)
86  static double activationfunction(double rdfsize, double d);
87 
88 public:
89  double eps; ///< initial learning rate for weight update
90 private:
91 
92  std::vector<matrix::Matrix> weights;
93  std::vector<matrix::Matrix> diffvectors; ///< temporary difference vectors
94  matrix::Matrix distances; ///< vector of distances
95  matrix::Matrix cellsizes; ///< vector of cell sizes
96  double lambda; ///< initial neighbourhood size
97  int maxTime; ///< maximal time for annealing
98  int t; ///< time used for annealing
99 
100  bool initialised;
101 };
102 
103 
104 #endif
Matrix type.
Definition: matrix.h:65
virtual const matrix::Matrix learn(const matrix::Matrix &input, const matrix::Matrix &nom_output, double learnRateFactor=1)
Definition: neuralgas.cpp:104
virtual void init(unsigned int inputDim, unsigned int outputDim, double unit_map=0.0, RandGen *randGen=0)
initialised som
Definition: neuralgas.cpp:50
virtual const matrix::Matrix process(const matrix::Matrix &input)
passive processing of the input (this function is not constant since a recurrent network for example ...
Definition: neuralgas.cpp:94
virtual void printWeights(FILE *f) const
Definition: neuralgas.cpp:80
double eps
initial learning rate for weight update
Definition: neuralgas.h:89
iparamkey name
Definition: inspectable.h:251
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
virtual unsigned int getOutputDim() const
returns the number of output neurons
Definition: neuralgas.h:72
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: neuralgas.cpp:150
virtual void damp(double damping)
damps the weights and the biases by multiplying (1-damping)
Definition: neuralgas.h:69
void updateCellSizes()
updates the cell sizes
Definition: neuralgas.cpp:132
neural gas class.
Definition: neuralgas.h:36
virtual unsigned int getInputDim() const
returns the number of input neurons
Definition: neuralgas.h:71
virtual void printCellsizes(FILE *f) const
Definition: neuralgas.cpp:90
static double activationfunction(double rdfsize, double d)
activation function (rbf)
Definition: neuralgas.cpp:70
NeuralGas(const std::string &name="NeuralGas", const std::string &revision="$Id$")
Definition: neuralgas.cpp:33
abstract class (interface) for a model that can be used by a controller
Definition: abstractmodel.h:34
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: neuralgas.cpp:165
virtual ~NeuralGas()
Definition: neuralgas.h:47