Robot Simulator of the Robotics Group for Self-Organization of Control: complexmeasure.h Source File

# complexmeasure.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot 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 #ifndef _COMPLEX_MEASURE_H
    00025 #define _COMPLEX_MEASURE_H
    00026
    00027 #include "abstractmeasure.h"
    00028 #include <list>
    00029
    00030 #include "sparsearray.h"
    00031
    00032 /** measure modes of complex measures.
    00033  */
    00034 enum ComplexMeasureMode {
    00035   /// returns the entropy of the value, uses update formula, needs O(1)
    00036   ENT,
    00037   /// returns the entropy of the value, uses normal formula, needs O(n) or O(m*n)
    00038   ENTSLOW,
    00039   /// returns the mutual information of two values, uses update formula, needs O(1)
    00040   MI,
    00041   /// returns the predictive information of two or more values
    00042   PINF
    00043 };
    00044
    00045 class Discretisizer;
    00046
    00047 class ComplexMeasure : public AbstractMeasure {
    00048
    00049   public:
    00050
    00051  /**
    00052   * creates a new complex measure. the calculated things are such like
    00053   * mutual information, entropy, joint entropy and so on.
    00054   * it`s possible to add new ones, see above for the
    00055   * ComplexMeasureModes.
    00056   * Don"t forget! to add observed values! with the method @see addObservable
    00057   * @param measureName the name of the measure, needed for PlotOptions and
    00058   * HUDSM
    00059   * @param mode the measure you like to have
    00060   * @param numberBins in earlier versions named as intervalCount. For complex
    00061   * measures the observedValue has to be discretisized, this does the
    00062   * ComplexMeasure with the class Discretisizer for you.
    00063   */
    00064 ComplexMeasure( const char* measureName, ComplexMeasureMode mode, int numberBins );
    00065
    00066
    00067
    00068     /**
    00069      * adds a observed variable to the measure.
    00070      * @param observedValue address of the observed value
    00071      * @param minValue minimum value the observed value can become
    00072      * @param maxValue maximum value the observed value can become
    00073      */
    00074     virtual void addObservable( double& observedValue, double minValue, double maxValue );
    00075
    00076     virtual ~ComplexMeasure();
    00077
    00078     /**
    00079      * defined by AbstractMeasure. This method is called from StatisticTools
    00080      * for updating the measure in every simStep (ODE).
    00081      */
    00082     virtual void step();
    00083
    00084
    00085   protected:
    00086   std::list<double*> observedValueList; // stores the adresses of the observedValues
    00087   std::list<Discretisizer*> discretisizerList; // stores the Discretisizer
    00088   ComplexMeasureMode mode;
    00089   int numberBins;
    00090   long fSize; // size of F
    00091   int historySize; // size of binNumberHistory
    00092 //  int *F; // stores the frequencies as a linear vector
    00093   int *binNumberHistory; // holds the binNumbers as an history, for predictive information 2 values are enough
    00094   int historyIndex; // index of last stored value
    00095   int *historyIndexList; // indexes of relevant stored values
    00096   int historyIndexNumber; // number of indexes stored in historyIndexList
    00097   int historyInterval; // interval between two different histoy indexes
    00098
    00099   // new: use SparseArray backed by HashMap instead of normal array
    00100   matrix::SparseArray<long, int> F;
    00101     // calculation methods
    00102
    00103       /**
    00104      * calculates the Predictive Information
    00105      */
    00106     void calculatePInf();
    00107
    00108
    00109     /**
    00110      * updates the entropy. uses update rule with O(1) costs
    00111      * @param binNumber the bin number
    00112      */
    00113     void updateEntropy( int binNumber);
    00114
    00115     /**
    00116      * computes the entropy. uses the normal rule with O(m*n*o) costs
    00117      */
    00118     void computeEntropy();
    00119
    00120
    00121     /**
    00122      * inits F, neccessary after each call of addObservable()
    00123      *
    00124      */
    00125     void initF();
    00126
    00127
    00128   };
    00129
    00130 #endif