complexmeasure.h

Go to the documentation of this file.
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.2  2009/08/10 07:39:31  guettler
00028 *   -example use of new SparseArray.
00029 *   -some test implementations for entropy (to be tested, corrected)
00030 *
00031 *   Revision 1.1  2009/03/27 06:16:58  guettler
00032 *   support for gcc 4.3 compatibility (has to be checked), StatisticTools moves from utils to statistictools
00033 *
00034 *   Revision 1.3  2008/02/14 14:43:09  der
00035 *   made some enhancements
00036 *
00037 *   Revision 1.2  2008/01/17 09:59:27  der
00038 *   complexmeasure: preparations made for predictive information,
00039 *   fixed a minor bug
00040 *   statisticmeasure, statistictools: added support for adding
00041 *   std::list<AbstractMeasure*> to StatisticTools, some minor
00042 *   improvements
00043 *
00044 *   Revision 1.1  2007/12/06 10:18:10  der
00045 *   AbstractMeasure is now a abstract type for Measures,
00046 *   StatisticTools now supports AbstractMeasures,
00047 *   StatisticalMeasure, ComplexMeasure  now derived from
00048 *   AbstractMeasure,
00049 *   ComplexMeasure provides support for calculation e.g. entropy,
00050 *   uses Discretisizer,
00051 *   Discretisizer is a stand-alone class for support of discretisizing values
00052 *   TrackableMeasure derived from ComplexMeasure and provides support for calculating complex measures for Trackable objects
00053 *
00054 *   Revision 1.3  2007/09/28 08:48:21  robot3
00055 *   corrected some minor bugs, files are still in develop status
00056 *
00057 *   Revision 1.2  2007/09/27 10:49:39  robot3
00058 *   removed some minor bugs,
00059 *   added CONVergence test
00060 *   changed little things for support of the new WSM
00061 *
00062 *   Revision 1.1  2007/05/07 21:01:31  robot3
00063 *   statistictools is a class for easy visualization of measurements of observed values
00064 *   it is possible to add the observed value itself with mode ID
00065 *
00066 *                                                                         *
00067 ***************************************************************************/
00068 #ifndef _COMPLEX_MEASURE_H
00069 #define _COMPLEX_MEASURE_H
00070 
00071 #include "abstractmeasure.h"
00072 #include <list>
00073 
00074 #include "sparsearray.h"
00075 
00076 /** measure modes of complex measures.
00077  */
00078 enum ComplexMeasureMode {
00079   /// returns the entropy of the value, uses update formula, needs O(1)
00080   ENT,
00081   /// returns the entropy of the value, uses normal formula, needs O(n) or O(m*n)
00082   ENTSLOW,
00083   /// returns the mutual information of two values, uses update formula, needs O(1)
00084   MI,
00085   /// returns the predictive information of two or more values
00086   PINF
00087 };
00088 
00089 class Discretisizer;
00090 
00091 class ComplexMeasure : public AbstractMeasure {
00092 
00093   public:
00094 
00095  /**
00096   * creates a new complex measure. the calculated things are such like
00097   * mutual information, entropy, joint entropy and so on.
00098   * it`s possible to add new ones, see above for the
00099   * ComplexMeasureModes.
00100   * Don"t forget! to add observed values! with the method @see addObservable
00101   * @param measureName the name of the measure, needed for PlotOptions and
00102   * HUDSM
00103   * @param mode the measure you like to have
00104   * @param numberBins in earlier versions named as intervalCount. For complex
00105   * measures the observedValue has to be discretisized, this does the
00106   * ComplexMeasure with the class Discretisizer for you.
00107   */
00108 ComplexMeasure( const char* measureName, ComplexMeasureMode mode, int numberBins );
00109 
00110 
00111 
00112     /**
00113      * adds a observed variable to the measure.
00114      * @param observedValue address of the observed value
00115      * @param minValue minimum value the observed value can become
00116      * @param maxValue maximum value the observed value can become
00117      */
00118     virtual void addObservable( double& observedValue, double minValue, double maxValue );
00119 
00120     virtual ~ComplexMeasure();
00121 
00122     /**
00123      * defined by AbstractMeasure. This method is called from StatisticTools
00124      * for updating the measure in every simStep (ODE).
00125      */
00126     virtual void step();
00127 
00128 
00129   protected:
00130   std::list<double*> observedValueList; // stores the adresses of the observedValues
00131   std::list<Discretisizer*> discretisizerList; // stores the Discretisizer
00132   ComplexMeasureMode mode;
00133   int numberBins;
00134   long fSize; // size of F
00135   int historySize; // size of binNumberHistory
00136 //  int *F; // stores the frequencies as a linear vector
00137   int *binNumberHistory; // holds the binNumbers as an history, for predictive information 2 values are enough
00138   int historyIndex; // index of last stored value
00139   int *historyIndexList; // indexes of relevant stored values
00140   int historyIndexNumber; // number of indexes stored in historyIndexList
00141   int historyInterval; // interval between two different histoy indexes
00142 
00143   // new: use SparseArray backed by HashMap instead of normal array
00144   matrix::SparseArray<long, int> F;
00145     // calculation methods
00146 
00147       /**
00148      * calculates the Predictive Information
00149      */
00150     void calculatePInf();
00151 
00152 
00153     /**
00154      * updates the entropy. uses update rule with O(1) costs
00155      * @param binNumber the bin number
00156      */
00157     void updateEntropy( int binNumber);
00158 
00159     /**
00160      * computes the entropy. uses the normal rule with O(m*n*o) costs
00161      */
00162     void computeEntropy();
00163 
00164 
00165     /**
00166      * inits F, neccessary after each call of addObservable()
00167      *
00168      */
00169     void initF();
00170 
00171 
00172   };
00173 
00174 #endif

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7