00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * frankguettler@gmx.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 *************************************************************************** 00023 * * 00024 * DESCRIPTION * 00025 * * 00026 * $Log: complexmeasure.h,v $ 00027 * Revision 1.3 2008/02/14 14:43:09 der 00028 * made some enhancements 00029 * 00030 * Revision 1.2 2008/01/17 09:59:27 der 00031 * complexmeasure: preparations made for predictive information, 00032 * fixed a minor bug 00033 * statisticmeasure, statistictools: added support for adding 00034 * std::list<AbstractMeasure*> to StatisticTools, some minor 00035 * improvements 00036 * 00037 * Revision 1.1 2007/12/06 10:18:10 der 00038 * AbstractMeasure is now a abstract type for Measures, 00039 * StatisticTools now supports AbstractMeasures, 00040 * StatisticalMeasure, ComplexMeasure now derived from 00041 * AbstractMeasure, 00042 * ComplexMeasure provides support for calculation e.g. entropy, 00043 * uses Discretisizer, 00044 * Discretisizer is a stand-alone class for support of discretisizing values 00045 * TrackableMeasure derived from ComplexMeasure and provides support for calculating complex measures for Trackable objects 00046 * 00047 * Revision 1.3 2007/09/28 08:48:21 robot3 00048 * corrected some minor bugs, files are still in develop status 00049 * 00050 * Revision 1.2 2007/09/27 10:49:39 robot3 00051 * removed some minor bugs, 00052 * added CONVergence test 00053 * changed little things for support of the new WSM 00054 * 00055 * Revision 1.1 2007/05/07 21:01:31 robot3 00056 * statistictools is a class for easy visualization of measurements of observed values 00057 * it is possible to add the observed value itself with mode ID 00058 * 00059 * * 00060 ***************************************************************************/ 00061 #ifndef _COMPLEX_MEASURE_H 00062 #define _COMPLEX_MEASURE_H 00063 00064 #include "abstractmeasure.h" 00065 #include <list> 00066 00067 /** measure modes of complex measures. 00068 */ 00069 enum ComplexMeasureMode { 00070 /// returns the entropy of the value, uses update formula, needs O(1) 00071 ENT, 00072 /// returns the entropy of the value, uses normal formula, needs O(n) or O(m*n) 00073 ENTSLOW, 00074 /// returns the mutual information of two values, uses update formula, needs O(1) 00075 MI, 00076 /// returns the predictive information of two or more values 00077 PINF 00078 }; 00079 00080 class Discretisizer; 00081 00082 class ComplexMeasure : public AbstractMeasure { 00083 00084 public: 00085 00086 /** 00087 * creates a new complex measure. the calculated things are such like 00088 * mutual information, entropy, joint entropy and so on. 00089 * it`s possible to add new ones, see above for the 00090 * ComplexMeasureModes. 00091 * Don"t forget! to add observed values! with the method @see addObservable 00092 * @param measureName the name of the measure, needed for PlotOptions and 00093 * HUDSM 00094 * @param mode the measure you like to have 00095 * @param numberBins in earlier versions named as intervalCount. For complex 00096 * measures the observedValue has to be discretisized, this does the 00097 * ComplexMeasure with the class Discretisizer for you. 00098 */ 00099 ComplexMeasure( const char* measureName, ComplexMeasureMode mode, int numberBins ); 00100 00101 00102 00103 /** 00104 * adds a observed variable to the measure. 00105 * @param observedValue address of the observed value 00106 * @param minValue minimum value the observed value can become 00107 * @param maxValue maximum value the observed value can become 00108 */ 00109 virtual void addObservable( double& observedValue, double minValue, double maxValue ); 00110 00111 virtual ~ComplexMeasure(); 00112 00113 /** 00114 * defined by AbstractMeasure. This method is called from StatisticTools 00115 * for updating the measure in every simStep (ODE). 00116 */ 00117 virtual void step(); 00118 00119 00120 protected: 00121 std::list<double*> observedValueList; // stores the adresses of the observedValues 00122 std::list<Discretisizer*> discretisizerList; // stores the Discretisizer 00123 ComplexMeasureMode mode; 00124 int numberBins; 00125 int fSize; // size of F 00126 int historySize; // size of binNumberHistory 00127 int *F; // stores the frequencies as a linear vector 00128 int *binNumberHistory; // holds the binNumbers as an history, for predictive information 2 values are enough 00129 int historyIndex; // index of last stored value 00130 int *historyIndexList; // indexes of relevant stored values 00131 int historyIndexNumber; // number of indexes stored in historyIndexList 00132 int historyInterval; // interval between two different histoy indexes 00133 00134 00135 00136 // calculation methods 00137 00138 /** 00139 * calculates the Predictive Information 00140 */ 00141 void calculatePInf(); 00142 00143 00144 /** 00145 * updates the entropy. uses update rule with O(1) costs 00146 * @param binNumber the bin number 00147 */ 00148 void updateEntropy( int binNumber); 00149 00150 /** 00151 * computes the entropy. uses the normal rule with O(m*n*o) costs 00152 */ 00153 void computeEntropy(); 00154 00155 00156 /** 00157 * inits F, neccessary after each call of addObservable() 00158 * 00159 */ 00160 void initF(); 00161 00162 00163 }; 00164 00165 #endif