// file: $isip/class/numeric/NonlinearOptimization/NonlinearOptimization.h // version: $Id: NonlinearOptimization.h 8338 2002-07-11 03:35:34Z picone $ // // make sure definitions are only made once // #ifndef ISIP_NONLINEAR_OPTIMIZATION #define ISIP_NONLINEAR_OPTIMIZATION #ifndef ISIP_LINEAR_ALGEBRA #include #endif #ifndef ISIP_MATRIX_DOUBLE #include #endif #ifndef ISIP_MATRIX_FLOAT #include #endif #ifndef ISIP_MEMORY_MANAGER #include #endif // NonlinearOptimization: a class to perform standard nonlinear optimization // techniques including parametric curve fitting and nonparametric // quadratic optimization // class NonlinearOptimization { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // Levenberg-Marquardt computation constants // static const float32 LEVMARQ_INIT_LAMBDA = 0.001; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; //---------------------------------------- // // default values and arguments // //---------------------------------------- static const float32 DEF_LEVMARQ_CONVERGE = 0.1; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 35200; static const int32 ERR_LEV_MARQ = 35201; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // typedef for the functional form to use for Levenberg-Marquardt // optimization in // typedef bool8 (*LEV_MARQ_FUNC_FLOAT)(float32&, VectorFloat&, const float32, const VectorFloat&); typedef bool8 (*LEV_MARQ_FUNC_DOUBLE)(float64&, VectorDouble&, const float64, const VectorDouble&); // a static debug level // static Integral::DEBUG debug_level_d; // a 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); // method: setDebug // static bool8 setDebug(Integral::DEBUG level) { debug_level_d = level; return true; } // method: debug // bool8 debug(const unichar* msg) const { return true; } // method: destructor // ~NonlinearOptimization() {} // method: default constructor // NonlinearOptimization() {} // method: copy constructor // NonlinearOptimization(const NonlinearOptimization& arg) { assign(arg); } // method: assign // bool8 assign(const NonlinearOptimization& copy_node) { return true; } // method: operator= // NonlinearOptimization& operator= (const NonlinearOptimization& arg) { assign(arg); return *this; } // method: sofSize // int32 sofSize() const { return 0; } // method: read // bool8 read(Sof& sof, int32 tag, const String& name = CLASS_NAME) { return true; } // method: write // bool8 write(Sof& sof, int32 tag, const String& name = CLASS_NAME) const { return true; } // method: readData // bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false) { return true; } // method: writeData // bool8 writeData(Sof& sof, const String& name = DEF_PARAM) const { return true; } // method: eq // bool8 eq(const NonlinearOptimization& arg) const { return true; } // 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); } // method: clear // bool8 clear(Integral::CMODE cmode = Integral::DEF_CMODE) { return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // parametric curve-fitting methods // //--------------------------------------------------------------------------- // method: levenbergMarquardt // least-squares Levenberg-Marquardt optimization // static bool8 levenbergMarquardt(VectorFloat& params, float32& chi_square, const VectorFloat& x, const VectorFloat& y, const VectorFloat& stddev, LEV_MARQ_FUNC_FLOAT func, float32 convergence=DEF_LEVMARQ_CONVERGE) { return levMarqTemplate(params, chi_square, x, y, stddev, func, convergence); } // method: levenbergMarquardt // least-squares Levenberg-Marquardt optimization // static bool8 levenbergMarquardt(VectorDouble& params, float64& chi_square, const VectorDouble& x, const VectorDouble& y, const VectorDouble& stddev, LEV_MARQ_FUNC_DOUBLE func, float64 convergence=DEF_LEVMARQ_CONVERGE) { return levMarqTemplate(params, chi_square, x, y, stddev, func, convergence); } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // templatized Levenberg-Marquardt optimization // template static bool8 levMarqTemplate(TVector& params, TIntegral& chi_square, const TVector& x, const TVector& y, const TVector& stddev, bool8 (*)(TIntegral&, TVector&, const TIntegral, const TVector&), TIntegral convergence); // auxiliary methods: // Levenberg-Marquardt routines // template static bool8 levMarqChiSquare(TIntegral& chi_square, TMatrix& alpha, TVector& beta, const TVector& x, const TVector& y, const TVector& inv_variance, const TVector& params, bool8 (*)(TIntegral&, TVector&, const TIntegral, const TVector&)); // auxiliary methods: // general purpose // template static bool8 scaleDiagonal(TMatrix& mat, const TIntegral& scale); // auxiliary methods: // diagnose // static bool8 diagnoseSigmoidFl(float32& y, VectorFloat& derivatives, const float32 x, const VectorFloat& params); static bool8 diagnoseSigmoidDoub(float64& y, VectorDouble& derivatives, const float64 x, const VectorDouble& params); }; // end of include file // #endif