123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //////////////////////////////////////////////////////////////////////
- //
- // CostFunction.h: interface of the CostFunction class.
- //
- // Written By: Matthias Wacker
- //
- //////////////////////////////////////////////////////////////////////
- #ifndef _COST_FUNCTION_H_
- #define _COST_FUNCTION_H_
- #include "optimization/Optimizable.h"
- #include "optimization/Opt_Namespace.h"
- namespace opt=optimization;
- /*!
- class Abstract base class for all cost functions.
- */
- class CostFunction : public Optimizable
- {
- public:
- typedef Optimizable SuperClass;
- typedef opt::matrix_type matrix_type;
-
- /*!
- DefaultConstructor
- */
- CostFunction();
- /*!
- Constructor.
- \param numOfParameters
- */
- CostFunction(unsigned int numOfParamters);
-
- /*
- Copy constructor
- */
- CostFunction(const CostFunction &func);
-
- /*!
- Destructor.
- */
- virtual ~CostFunction();
- /*!
- =operator
- */
- CostFunction &operator=(const CostFunction &costFunc);
- inline bool hasAnalyticGradient(){return m_hasAnalyticGradient;}
- /*!
- get the analytic gradient
- */
- virtual const opt::matrix_type getAnalyticGradient(const opt::matrix_type &x);
-
-
- inline bool hasAnalyticHessian(){return m_hasAnalyticHessian;}
- /*!
- get the analytic hessian
- */
- virtual const opt::matrix_type getAnalyticHessian(const opt::matrix_type & x);
- /*!
- get number of Evaluations
- */
- inline unsigned int getNumberOfEvaluations(){return m_numEval;};
- /*!
- reset the evaluation counter
- */
- inline void resetNumberOfEvaluations(){m_numEval = 0;};
- /*!
- Initialization for the cost function
- */
- virtual void init();
- /*!
- set an x0 for 1dim line search
- */
- bool setX0(const opt::matrix_type &x0);
- /*!
- set an h0 for 1dim line search
- */
- bool setH0(const opt::matrix_type &H0);
- /*!
- evaluate 1dimension sub function fsub(lambda) = f(x0 + lambda * h0)
- */
- double evaluateSub(double lambda);
- /*!
- * This function returns the full parameter vector. If the costfunction performs dimension reduction
- * this method will return the current parameter vector with full dimension. Otherwise the costfunction works with
- * the full parameter vector in any case and it is returned unchanged.
- * @param x current parameter vector (from optimizer)
- * @return full parameter vector
- */
- virtual opt::matrix_type getFullParamsFromSubParams(const opt::matrix_type &x)
- {
- matrix_type fullparamvec(x);
- return x;
- }
- protected:
- /*!
- has analytic gradient ?
- */
- bool m_hasAnalyticGradient;
-
- /*!
- has analytic hessian ?
- */
- bool m_hasAnalyticHessian;
- /*!
- x_0
- */
- opt::matrix_type m_x_0;
- /*!
- direction h_0
- */
- opt::matrix_type m_h_0;
- /*!
- number of evaluations
- */
- unsigned int m_numEval;
- };
- #endif
|