// file: $isip_ifc/class/algo/Rps/Rps.h // version: $Id: Rps.h 10484 2006-03-14 23:50:33Z srinivas $ // // make sure definitions are only made once // #ifndef ISIP_RPS #define ISIP_RPS // isip include files // #ifndef ISIP_ALGORITHM_BASE #include #endif // Rps: this class computes the reconstructed phase space (RPS) // matrix from the input signal (time-series). two algorithms // are supported: time delay embedding and SVD embedding. both // the algorithms (for scalar time-series) are described in // // D. S. Broomhead and Gregory P. King, // Extracting qualitative dynamics from experimental data, // Physica D 20, pp. 217, 1986. // // time-delay embedding constructs points in RPS using // delayed-coordinate system. SVD embedding is achieved by first // forming an RPS in a higher dimension with a delay of one // sample and then reducing it, using SVD (singular value // decomposition), to the desired dimension. // // a compute method to embed a vector time-series is also inclded // in this class. presently, it cannot be used from isip_transform. // but can only be called from a C++ program // // a zero column is appended at the end as a flag to indicate that // each point in the RPS is continuous. this is useful, when // concatenating several RPS matrices, to indicate points of // discontinuities // class Rps : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define the algorithm choices // enum ALGORITHM { TIME_DELAY_EMBEDDING = 0, SVD_EMBEDDING, DEF_ALGORITHM = TIME_DELAY_EMBEDDING }; // define the implementation choices // enum IMPLEMENTATION { EMBEDDING = 0, DEF_IMPLEMENTATION = EMBEDDING }; // define the 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_CMODE; static const String PARAM_EMBED_DIMENSION; static const String PARAM_DELAY; static const String PARAM_SVD_WINDOW_SIZE; static const String PARAM_SVD_THRESHOLD; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define the default value(s) of the class data // static const int32 DEF_EMBED_DIMENSION = -1; static const float32 DEF_DELAY = -1.0; static const int32 DEF_SVD_WINDOW_SIZE = -1; static const float32 DEF_SVD_THRESHOLD = -1.0; // define default argument(s) // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::SIGNAL; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 73400; static const int32 ERR_INP = 73401; static const int32 ERR_EMBEDDIM = 73402; static const int32 ERR_SVDDIM = 73403; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation name // IMPLEMENTATION implementation_d; // (global) embedding dimension // Long embed_dimension_d; // SVD window size (initial embedding dimension for SVD_EMBEDDING) // Long svd_window_size_d; // delay (tau) for embedding in sec // Float delay_d; // threshold value for embedding dimension calculation // using singular values // Float svd_threshold_d; // define a buffer for keeping track of all frames of data in ACCUMULATE // mode (using AlgorithmBase::frame_index_d to keep track of the frame // index) // Vector accum_buf_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 // ~Rps() {} // method: default constructor // Rps(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, int32 embed_dimension = DEF_EMBED_DIMENSION, int32 svd_window_size = DEF_SVD_WINDOW_SIZE, float32 delay = DEF_DELAY, float32 svd_threshold = DEF_SVD_THRESHOLD) { algorithm_d = algorithm; implementation_d = implementation; embed_dimension_d = embed_dimension; svd_window_size_d = svd_window_size; delay_d = delay; svd_threshold_d = svd_threshold; is_valid_d = false; } // method: copy constructor // Rps(const Rps& arg) { assign(arg); } // method: assign // bool8 assign(const Rps& arg) { algorithm_d = arg.algorithm_d; implementation_d = arg.implementation_d; embed_dimension_d = arg.embed_dimension_d; svd_window_size_d = arg.svd_window_size_d; delay_d = arg.delay_d; svd_threshold_d = arg.svd_threshold_d; return AlgorithmBase::assign(arg); } // method: operator= // Rps& operator= (const Rps& 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; // method: eq // bool8 eq(const Rps& arg) const { return ((algorithm_d == arg.algorithm_d) && (implementation_d == arg.implementation_d) && embed_dimension_d == arg.embed_dimension_d && svd_window_size_d == arg.svd_window_size_d && delay_d == arg.delay_d && svd_threshold_d == arg.svd_threshold_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; } // method: setEmbedDimension // bool8 setEmbedDimension(int32 embed_dimension) { embed_dimension_d = embed_dimension; is_valid_d = false; return true; } // method: setSVDWindowSize // bool8 setSVDWindowSize(int32 svd_window_size) { svd_window_size_d = svd_window_size; is_valid_d = false; return true; } // method: setDelay // bool8 setDelay(float32 delay ) { delay_d = delay; is_valid_d = false; return true; } // method: setSVDThreshold // bool8 setSVDThreshold(float32 svd_threshold) { svd_threshold_d = svd_threshold; is_valid_d = false; return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, int32 embed_dimension = DEF_EMBED_DIMENSION, int32 svd_window_size = DEF_SVD_WINDOW_SIZE, float32 delay = DEF_DELAY, float32 svd_threshold = DEF_SVD_THRESHOLD) { algorithm_d = algorithm; implementation_d = implementation; embed_dimension_d = embed_dimension; svd_window_size_d = svd_window_size; delay_d = delay; svd_threshold_d = svd_threshold; is_valid_d = false; return true; } // other set methods // //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // ALGORITHM getAlgorithm() const { return algorithm_d; } // method: getImplementation // IMPLEMENTATION getImplementation() const { return implementation_d; } int32 getEmbedDimension() const { return embed_dimension_d; } int32 getSVDWindowSize() const { return svd_window_size_d; } float32 getDelay() const { return delay_d; } float32 getSVDThreshold() const { return svd_threshold_d; } bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, int32& embed_dimension, int32& svd_window_size, float32& delay, float32& svd_threshold) const { algorithm = algorithm_d; implementation = implementation_d; embed_dimension = embed_dimension_d; svd_window_size = svd_window_size_d; delay = delay_d; svd_threshold = svd_threshold_d; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // public methods required by the AlgorithmBase interface contract // computational methods // //--------------------------------------------------------------------------- // for scalar embedding // bool8 compute(MatrixFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE input_coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); // for vector embedding // bool8 compute(MatrixFloat& 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 required since none of the algorithms currently // supported require a history // // bool8 init() {} // // 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; // computation-mode-specific computation methods // // frame-based scalar embedding // bool8 computeFrameInt(MatrixFloat& output, const VectorFloat& input); // frame-based vector embedding // bool8 computeFrameInt(MatrixFloat& rps, const MatrixFloat& input); // Rps computation for the whole file by accumulating // frames or samples // bool8 computeAccumulate(MatrixFloat& output, const VectorFloat& input, int32 chan_a); // algorithm-specific compute methods: TIME_DELAY_EMBEDDING // for scalar embedding // bool8 computeTimeDelayEmbedding(MatrixFloat& output, const VectorFloat& input); // algorithm-specific compute methods: SVD_EMBEDDING // for scalar embedding // bool8 computeSVDEmbedding(MatrixFloat& output, const VectorFloat& input); // algorithm-specific compute methods: TIME_DELAY_EMBEDDING // for vector embedding // bool8 computeTimeDelayEmbedding(MatrixFloat& output, const MatrixFloat& input); // algorithm-specific compute methods: SVD_EMBEDDING // for vector embedding // bool8 computeSVDEmbedding(MatrixFloat& output, const MatrixFloat& input); }; // end of include file // #endif