// file: $isip_ifc/class/algo/Lyapunov/Lyapunov.h // version: $Id: Lyapunov.h 10636 2007-01-26 22:18:09Z tm334 $ // // make sure definitions are only made once // #ifndef ISIP_LYAPUNOV #define ISIP_LYAPUNOV #ifndef ISIP_ALGORITHM_BASE #include #endif // Lyapunov: a class that computes the Lyapunov spectra from an input // reconsctructed (RPS) matrix. from the RPS it computes the trajectory map, // T, at every point and uses treppen-iteration to extract the average // eigenvalues of the T matrices // // Refer to : // Michael Banbrook, "Nonlinear analysis of speech from a synthesis // perspective", PhD thesis, The University of Edinburgh, 1996. // class Lyapunov : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define algorithm choices // enum ALGORITHM { LINEAR_TANGENT_MAP = 0, DEF_ALGORITHM = LINEAR_TANGENT_MAP }; // define implementation choices // enum IMPLEMENTATION { TREPPEN_ITERATION = 0, DEF_IMPLEMENTATION = TREPPEN_ITERATION }; // define static NameMap objects // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_NUM_NEIGHBORS; static const String PARAM_EVOLVE_STEP; static const String PARAM_LOCAL_DIM; static const String PARAM_NUM_STEPS; static const String PARAM_INNER_RADIUS; static const String PARAM_OUTER_RADIUS; static const String PARAM_NUM_NEIGHBOR_SUBGROUPS; static const String PARAM_REINIT_STEP; static const String PARAM_START_POS; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define the default value(s) of the class data // static const int32 DEF_NUM_NEIGHBORS = -1; static const int32 DEF_EVOLVE_STEP = -1; static const int32 DEF_LOCAL_DIM = -1; static const int32 DEF_NUM_STEPS = 1000; static const float32 DEF_INNER_RADIUS = 0.0; static const float32 DEF_OUTER_RADIUS = -1.0; static const int32 DEF_NUM_NEIGHBOR_SUBGROUPS = -1; static const int32 DEF_REINIT_STEP = -1; static const int32 DEF_START_POS = 1; // define default argument(s) // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::RPS; //---------------------------------------- // // error codes // //---------------------------------------- // MY: Needs to be addressed last // static const int32 ERR = 73500; static const int32 ERR_SUBGRPS = 73501; static const int32 ERR_NGH = 73502; static const int32 ERR_DIM = 73503; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation type // IMPLEMENTATION implementation_d; // number of neighbors // Long num_neighbors_d; // evolve step for trajectory matrix computation // Long evolve_step_d; // local embedding dimension // Long local_dim_d; // number of points to evolve // Long num_steps_d; // inner and outer radius of neighborhood // Float inner_radius_d, outer_radius_d; // number of subgroups of neighbors (with averaging // in each subgroups done) // Long num_neighbor_subgroups_d; // number of points to jump before recalculating LE // Long reinit_step_d; // position to start computing // Long start_pos_d; // 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 // ~Lyapunov() {} // default constructor // Lyapunov(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, int32 num_neighbors = DEF_NUM_NEIGHBORS, int32 evolve_step = DEF_EVOLVE_STEP, int32 local_dim = DEF_LOCAL_DIM, int32 num_steps = DEF_NUM_STEPS, float32 inner_radius = DEF_INNER_RADIUS, float32 outer_radius = DEF_OUTER_RADIUS, int32 num_neighbor_subgroups = DEF_NUM_NEIGHBOR_SUBGROUPS, int32 reinit_step = DEF_REINIT_STEP, int32 start_pos = DEF_START_POS) { algorithm_d = algorithm; implementation_d = implementation; num_neighbors_d = num_neighbors; evolve_step_d = evolve_step; local_dim_d = local_dim; num_steps_d = num_steps; inner_radius_d = inner_radius; outer_radius_d = outer_radius; num_neighbor_subgroups_d = num_neighbor_subgroups; reinit_step_d = reinit_step; start_pos_d = start_pos; is_valid_d = false; } // method: copy constructor // Lyapunov(const Lyapunov& arg) { assign(arg); } // assign methods // bool8 assign(const Lyapunov& arg) { algorithm_d = arg.algorithm_d; implementation_d = arg.implementation_d; num_neighbors_d = arg.num_neighbors_d; evolve_step_d = arg.evolve_step_d; local_dim_d = arg.local_dim_d; num_steps_d = arg.num_steps_d; inner_radius_d = arg.inner_radius_d; outer_radius_d = arg.outer_radius_d; num_neighbor_subgroups_d = arg.num_neighbor_subgroups_d; reinit_step_d = arg.reinit_step_d; start_pos_d = arg.start_pos_d; return AlgorithmBase::assign(arg); } // method: operator= // Lyapunov& operator= (const Lyapunov& 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 Lyapunov& arg) const { return ((algorithm_d == arg.algorithm_d) && (implementation_d == arg.implementation_d) && (num_neighbors_d == arg.num_neighbors_d) && (evolve_step_d == arg.evolve_step_d) && (local_dim_d == arg.local_dim_d) && (num_steps_d == arg.num_steps_d) && (inner_radius_d == arg.inner_radius_d) && (outer_radius_d == arg.outer_radius_d) && (num_neighbor_subgroups_d == arg.num_neighbor_subgroups_d) && (reinit_step_d == arg.reinit_step_d) && (start_pos_d == arg.start_pos_d)); } // 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; } bool8 setNumNeighbors(int32 num_neighbors) { num_neighbors_d = num_neighbors; is_valid_d = false; return true; } bool8 setEvolveStep(int32 evolve_step) { evolve_step_d = evolve_step; is_valid_d = false; return true; } bool8 setLocalDim(int32 local_dim) { local_dim_d = local_dim; is_valid_d = false; return true; } bool8 setNumSteps(int32 num_steps) { num_steps_d = num_steps; is_valid_d = false; return true; } bool8 setInnerRadius(float32 inner_radius) { inner_radius_d = inner_radius; is_valid_d = false; return true; } bool8 setOuterRadius(float32 outer_radius) { outer_radius_d = outer_radius; is_valid_d = false; return true; } bool8 setNumNeighborSubgroups(int32 num_neighbor_subgroups) { num_neighbor_subgroups_d = num_neighbor_subgroups; is_valid_d = false; return true; } bool8 setReinitStep(int32 reinit_step) { reinit_step_d = reinit_step; is_valid_d = false; return true; } bool8 setStartPos(int32 start_pos) { start_pos_d = start_pos; is_valid_d = false; return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, int32 num_neighbors = DEF_NUM_NEIGHBORS, int32 evolve_step = DEF_EVOLVE_STEP, int32 local_dim = DEF_LOCAL_DIM, int32 num_steps = DEF_NUM_STEPS, float32 inner_radius = DEF_INNER_RADIUS, float32 outer_radius = DEF_OUTER_RADIUS, int32 num_neighbor_subgroups = DEF_NUM_NEIGHBOR_SUBGROUPS, int32 reinit_step = DEF_REINIT_STEP, int32 start_pos = DEF_START_POS) { algorithm_d = algorithm; implementation_d = implementation; num_neighbors_d = num_neighbors; evolve_step_d = evolve_step; local_dim_d = local_dim; num_steps_d = num_steps; inner_radius_d = inner_radius; outer_radius_d = outer_radius; num_neighbor_subgroups_d = num_neighbor_subgroups; reinit_step_d = reinit_step; start_pos_d = start_pos; 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; } int32 getNumNeighbors() const { return num_neighbors_d; } int32 getEvolveStep() const { return evolve_step_d; } int32 getLocalDim() const { return local_dim_d; } int32 getNumSteps() const { return num_steps_d; } float32 getInnerRadius() const { return inner_radius_d; } float32 getOuterRadius() const { return outer_radius_d; } int32 getNumNeighborSubgroups() const { return num_neighbor_subgroups_d; } int32 getReinitStep() const { return reinit_step_d; } int32 getStartPos() const { return start_pos_d; } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, int32& num_neighbors, int32& evolve_step, int32& local_dim, int32& num_steps, float32& inner_radius, float32& outer_radius, int32& num_neighbor_subgroups, int32& reinit_step, int32& start_pos) const { algorithm = algorithm_d; implementation = implementation_d; num_neighbors = num_neighbors_d; evolve_step = evolve_step_d; local_dim = local_dim_d; num_steps = num_steps_d; inner_radius = inner_radius_d; outer_radius = outer_radius_d; num_neighbor_subgroups = num_neighbor_subgroups_d; reinit_step = reinit_step_d; start_pos = start_pos_d; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // computation methods // //--------------------------------------------------------------------------- // compute method when input is given as matrix itself // 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; // compute Lyapunov exponents // bool8 computeLyapunovLinearTangentMapMethod(VectorFloat& lyapunov, const MatrixFloat& rps); }; // end of include file // #endif