// file: $isip_ifc/class/algo/CorrelationDimension/CorrelationDimension.h // version: $Id: CorrelationDimension.h 10555 2006-04-19 08:39:03Z pannuri $ // // make sure definitions are only made once // #ifndef ISIP_CORRELATION_DIMENSION #define ISIP_CORRELATION_DIMENSION #ifndef ISIP_ALGORITHM_BASE #include #endif // CorrelationDimension: a class that computes an invariant of a // chaotic system, the correlation dimension. // the dimension of a strange attractor // is a measure of its geometric scaling properties or its complexity. in this // class we calculate one of the types of dimensions, the correlation // dimension. // // J. Theiler, // Estimating fractal dimension, Lincoln Laboratory, // MIT, Lexington, Massachusetts, USA, pp. 1066-1069, 1990. // // the correlation integral and Rps classes are used for // estimating the correlation dimension. // the user first needs to reconstruct the phase space and // pass it as one of the input arguments. // // there are three different implementations for // estimating the correlation dimension. the first method uses the backward // differentiation and the second method uses a central differentiation and // the third implementation uses smooth version of it. // // P.S. Addison, // Fractals and Chaos, an illustrated course., // Institute of Physics Publishing, Bristol, UK, pp. 163-171, 1997. // // the correlation dimension is given by: // // d(N, r) = lim lim log C(N, r) // r -> 0 N -> inf ----------- // log r // // extracting dimension directly from the equation above is // inaccurate. // // H. Kantz and T. Schreiber, // Nonlinear Time Series Analysis, 2nd Edition., // Cambridge University Press, Cambridge, UK, pp. 77-85, 1999. // // therefore we use a slightly different formula where we // calculate the local slopes and is given as follows: // // d(N, r) = log C(N, 2r) - log C(N, r/2) // ----------------------------- // log 2r - log r/2 // // class CorrelationDimension : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define algorithm choices // enum ALGORITHM { NORMAL = 0, DEF_ALGORITHM = NORMAL }; // define implementation choices // enum IMPLEMENTATION { BACKWARD = 0, CENTRAL, SMOOTH, DEF_IMPLEMENTATION = BACKWARD }; // define scaling choices // enum SCALING { LINSCALE = 0, LOGSCALE, DEF_SCALING = LINSCALE }; // define static NameMap objects // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; static const NameMap SCAL_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_SCALING; static const String PARAM_EPSILON_MIN; static const String PARAM_EPSILON_MAX; static const String PARAM_EPSILON_RES; static const String PARAM_DELTA; static const String PARAM_THEILER_CORRECTION; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define the default value(s) of the class data // static const float32 DEF_EPSILON_MIN = 1.0 ; static const float32 DEF_EPSILON_MAX = 10.0; static const int32 DEF_EPSILON_RES = 5; static const float32 DEF_DELTA = 0.1; static const int32 DEF_THEILER_CORRECTION = 150; // define default argument(s) // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::SIGNAL; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 73900; static const int32 ERR_EPSMIN = 73901; static const int32 ERR_EPSMAX = 73902; static const int32 ERR_EPSRES = 73903; static const int32 ERR_EPS = 73904; static const int32 ERR_DELTA_EPSMIN = 73905; static const int32 ERR_DELTA_EPSMAX = 73906; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation type // IMPLEMENTATION implementation_d; // scaling type // SCALING scaling_d; // parameters related to the algorithm specification // Float epsilon_min_d; // Radius of the neighborhood for correlation sum Float epsilon_max_d; // Radius of the neighborhood for correlation sum Long epsilon_res_d; // Resolution for the region min-to-max Float delta_d; // the delta value for the epsilon Long theiler_correction_d; // Theiler's correction for correlation sum // static memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static bool8 diagnose(Integral::DEBUG debug_level); // debug methods: // setDebug is inherited from the AlgorithmBase class // bool8 debug(const unichar* msg) const; // method: destructor // ~CorrelationDimension() {} // default constructor // CorrelationDimension(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, SCALING scaling = DEF_SCALING, float32 epsilon_min = DEF_EPSILON_MIN, float32 epsilon_max = DEF_EPSILON_MAX, int32 epsilon_res = DEF_EPSILON_RES, float32 delta = DEF_DELTA, int32 theiler_correction = DEF_THEILER_CORRECTION) { // initialize protected data // algorithm_d = DEF_ALGORITHM; implementation_d = DEF_IMPLEMENTATION; scaling_d = DEF_SCALING; epsilon_min_d = epsilon_min; epsilon_max_d = epsilon_max; epsilon_res_d = epsilon_res; delta_d = delta; theiler_correction_d = theiler_correction; is_valid_d = false; } // method: copy constructor // CorrelationDimension(const CorrelationDimension& arg) { assign(arg); } // assign methods // bool8 assign(const CorrelationDimension& arg); // method: operator= // CorrelationDimension& operator= (const CorrelationDimension& arg) { assign(arg); return *this; } // i/o methods // int32 sofSize() const; bool8 read(Sof& sof, int32 tag, const String& name = CLASS_NAME); bool8 write(Sof& sof, int32 tag, const String& name = CLASS_NAME) const; bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; // equality methods // bool8 eq(const CorrelationDimension& arg) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } // other memory management methods // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods // set methods // //--------------------------------------------------------------------------- // method: setAlgorithm // bool8 setAlgorithm(ALGORITHM algorithm) { algorithm_d = algorithm; is_valid_d = false; return true; } // method: setImplementation // bool8 setImplementation(IMPLEMENTATION implementation) { implementation_d = implementation; is_valid_d = false; return true; } // method: setScaling // bool8 setScaling(SCALING scaling) { scaling_d = scaling; is_valid_d = false; return true; } // method: setEpsilonMin // bool8 setEpsilonMin(float32 epsilon_min) { epsilon_min_d = epsilon_min; is_valid_d = false; return true; } // method: setEpsilonMax // bool8 setEpsilonMax(float32 epsilon_max) { epsilon_max_d = epsilon_max; is_valid_d = false; return true; } // method: setEpsilonRes // bool8 setEpsilonRes(int32 epsilon_res) { epsilon_res_d = epsilon_res; is_valid_d = false; return true; } // method: setDelta // bool8 setDelta(float32 delta) { delta_d = delta; is_valid_d = false; return true; } // method: setTheilerCorrection // bool8 setTheilerCorrection(int32 theiler_correction) { theiler_correction_d = theiler_correction; is_valid_d = false; return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, SCALING scaling = DEF_SCALING, float32 epsilon_min = DEF_EPSILON_MIN, float32 epsilon_max = DEF_EPSILON_MAX, int32 epsilon_res = DEF_EPSILON_RES, float32 delta = DEF_DELTA, int32 theiler_correction = DEF_THEILER_CORRECTION) { algorithm_d = algorithm; implementation_d = implementation; scaling_d = scaling; epsilon_min_d = epsilon_min; epsilon_max_d = epsilon_max; epsilon_res_d = epsilon_res; delta_d = delta; theiler_correction_d = theiler_correction; is_valid_d = false; return true; } //--------------------------------------------------------------------------- // // class-specific public methods // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // ALGORITHM getAlgorithm() const { return algorithm_d; } // method: getImplementation // IMPLEMENTATION getImplementation() const { return implementation_d; } // method: getScaling // SCALING getScaling() const { return scaling_d; } // method: getEpsilonMin // float32 getEpsilonMin() const { return epsilon_min_d; } // method: getEpsilonMax // float32 getEpsilonMax() const { return epsilon_max_d; } // method: getEpsilonRes // int32 getEpsilonRes() const { return epsilon_res_d; } // method: getTheilerCorrection // float32 getDelta() const { return delta_d; } // method: getTheilerCorrection // int32 getTheilerCorrection() const { return theiler_correction_d; } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, SCALING& scaling, float32& epsilon_min, float32& epsilon_max, int32& epsilon_res, float32& delta, int32& theiler_correction) { algorithm = algorithm_d; implementation = implementation_d; scaling = scaling_d; epsilon_min = epsilon_min_d; epsilon_max = epsilon_max_d; delta = delta_d; theiler_correction = theiler_correction_d; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // computation methods // //--------------------------------------------------------------------------- bool8 compute(VectorFloat& output, const MatrixFloat& input, AlgorithmData::COEF_TYPE input_coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); //--------------------------------------------------------------------------- // // class-specific public methods: // public methods required by the AlgorithmBase interface contract // //--------------------------------------------------------------------------- // assign method // bool8 assign(const AlgorithmBase& arg); // equality method // bool8 eq(const AlgorithmBase& arg) const; // method: className // const String& className() const { return CLASS_NAME; } // no initialization method is needed since none of the // algorithms currently supported require a history // apply method // bool8 apply(Vector& output, const Vector< CircularBuffer >& input); // method to set the parser // bool8 setParser(SofParser* parser); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // common i/o methods // bool8 readDataCommon(Sof& sof, const String& pname, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeDataCommon(Sof& sof, const String& pname) const; bool8 computeCorrDimBackward(VectorFloat& correlationdimension, const MatrixFloat& input); bool8 computeCorrDimCentral(VectorFloat& correlationdimension, const MatrixFloat& input); bool8 computeCorrDimSmooth(VectorFloat& correlationdimension, const MatrixFloat& input); bool8 compute(VectorFloat& output_a, const CircularBuffer& input_a, AlgorithmData::COEF_TYPE coef_type_a, int32 channel_index_a); }; // end of include file // #endif