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
complexmeasure.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 _COMPLEX_MEASURE_H
25 #define _COMPLEX_MEASURE_H
26 
27 #include "abstractmeasure.h"
28 #include <list>
29 
30 #include "sparsearray.h"
31 
32 /** measure modes of complex measures.
33  */
35  /// returns the entropy of the value, uses update formula, needs O(1)
36  ENT,
37  /// returns the entropy of the value, uses normal formula, needs O(n) or O(m*n)
39  /// returns the mutual information of two values, uses update formula, needs O(1)
40  MI,
41  /// returns the predictive information of two or more values
43 };
44 
45 class Discretisizer;
46 
48 
49  public:
50 
51  /**
52  * creates a new complex measure. the calculated things are such like
53  * mutual information, entropy, joint entropy and so on.
54  * it`s possible to add new ones, see above for the
55  * ComplexMeasureModes.
56  * Don"t forget! to add observed values! with the method @see addObservable
57  * @param measureName the name of the measure, needed for PlotOptions and
58  * HUDSM
59  * @param mode the measure you like to have
60  * @param numberBins in earlier versions named as intervalCount. For complex
61  * measures the observedValue has to be discretisized, this does the
62  * ComplexMeasure with the class Discretisizer for you.
63  */
64 ComplexMeasure( const char* measureName, ComplexMeasureMode mode, int numberBins );
65 
66 
67 
68  /**
69  * adds a observed variable to the measure.
70  * @param observedValue address of the observed value
71  * @param minValue minimum value the observed value can become
72  * @param maxValue maximum value the observed value can become
73  */
74  virtual void addObservable( double& observedValue, double minValue, double maxValue );
75 
76  virtual ~ComplexMeasure();
77 
78  /**
79  * defined by AbstractMeasure. This method is called from StatisticTools
80  * for updating the measure in every simStep (ODE).
81  */
82  virtual void step();
83 
84 
85  protected:
86  std::list<double*> observedValueList; // stores the adresses of the observedValues
87  std::list<Discretisizer*> discretisizerList; // stores the Discretisizer
90  long fSize; // size of F
91  int historySize; // size of binNumberHistory
92 // int *F; // stores the frequencies as a linear vector
93  int *binNumberHistory; // holds the binNumbers as an history, for predictive information 2 values are enough
94  int historyIndex; // index of last stored value
95  int *historyIndexList; // indexes of relevant stored values
96  int historyIndexNumber; // number of indexes stored in historyIndexList
97  int historyInterval; // interval between two different histoy indexes
98 
99  // new: use SparseArray backed by HashMap instead of normal array
101  // calculation methods
102 
103  /**
104  * calculates the Predictive Information
105  */
106  void calculatePInf();
107 
108 
109  /**
110  * updates the entropy. uses update rule with O(1) costs
111  * @param binNumber the bin number
112  */
113  void updateEntropy( int binNumber);
114 
115  /**
116  * computes the entropy. uses the normal rule with O(m*n*o) costs
117  */
118  void computeEntropy();
119 
120 
121  /**
122  * inits F, neccessary after each call of addObservable()
123  *
124  */
125  void initF();
126 
127 
128  };
129 
130 #endif
Definition: complexmeasure.h:47
int * historyIndexList
Definition: complexmeasure.h:95
returns the entropy of the value, uses normal formula, needs O(n) or O(m*n)
Definition: complexmeasure.h:38
int historyInterval
Definition: complexmeasure.h:97
matrix::SparseArray< long, int > F
Definition: complexmeasure.h:100
ComplexMeasureMode mode
Definition: complexmeasure.h:88
virtual ~ComplexMeasure()
Definition: complexmeasure.cpp:43
int * binNumberHistory
Definition: complexmeasure.h:93
int historyIndex
Definition: complexmeasure.h:94
void initF()
inits F, neccessary after each call of addObservable()
Definition: complexmeasure.cpp:186
returns the mutual information of two values, uses update formula, needs O(1)
Definition: complexmeasure.h:40
returns the entropy of the value, uses update formula, needs O(1)
Definition: complexmeasure.h:36
ComplexMeasure(const char *measureName, ComplexMeasureMode mode, int numberBins)
creates a new complex measure.
Definition: complexmeasure.cpp:35
void computeEntropy()
computes the entropy.
Definition: complexmeasure.cpp:171
int historyIndexNumber
Definition: complexmeasure.h:96
int historySize
Definition: complexmeasure.h:91
long fSize
Definition: complexmeasure.h:90
ComplexMeasureMode
measure modes of complex measures.
Definition: complexmeasure.h:34
int numberBins
Definition: complexmeasure.h:89
std::list< double * > observedValueList
Definition: complexmeasure.h:86
returns the predictive information of two or more values
Definition: complexmeasure.h:42
Use this class to get discrete values.
Definition: discretisizer.h:43
void updateEntropy(int binNumber)
updates the entropy.
Definition: complexmeasure.cpp:153
void calculatePInf()
calculates the Predictive Information
Definition: complexmeasure.cpp:130
virtual void addObservable(double &observedValue, double minValue, double maxValue)
adds a observed variable to the measure.
Definition: complexmeasure.cpp:144
std::list< Discretisizer * > discretisizerList
Definition: complexmeasure.h:87
virtual void step()
defined by AbstractMeasure.
Definition: complexmeasure.cpp:57
Class used by StatisticTools.
Definition: abstractmeasure.h:38