#pragma once #include #include #include #include "common.h" #include "args.h" class data ; /*! \brief A representation of an analytical function. * \ingroup core * * function are functors with a domain of definition specified by a vector * interval \f$[\vec{min} .. \vec{max}]\f$ where \f$\vec{min}\f$ and * \f$\vec{max}\f$ have the size of the input domain. * * Any function used by the fitting algorithm should overload publicly this * interface. * * \todo how-to write a plugin here ? */ class function { public: // methods // Overload the function operator virtual vec operator()(const vec& x) const = 0 ; virtual vec value(const vec& x) const = 0 ; //! Load function specific files virtual void load(const std::string& filename) = 0 ; //! \brief Save the current function to a specific file type, args can //! be used to differenciate the type of export. //! //! \see rational_function.cpp for an example virtual void save(const std::string& filename, const arguments& args) const = 0 ; //! Provide the dimension of the input space of the function virtual int dimX() const { return _nX ; } //! Provide the dimension of the output space of the function virtual int dimY() const { return _nY ; } virtual void setDimX(int nX) { _nX = nX ; } virtual void setDimY(int nY) { _nY = nY ; } // Acces to the domain of definition of the function virtual void setMin(const vec& min) { assert(min.size() == _nX) ; _min = min ; } virtual void setMax(const vec& max) { assert(max.size() == _nX) ; _max = max ; } virtual vec getMin() const { return _min ; } virtual vec getMax() const { return _max ; } protected: //data // Dimension of the function & domain of definition. int _nX, _nY ; vec _min, _max ; }; /*! \brief Non-linear function interface * * Provide a way to obtain the dérivative of the function with respect to its * parameters. If the function \f$f(\vec{x})\f$ is defined for a vector of * parameters \f$\vec{a}\f$, the resulting vector is \f$df_i = {df \over * da_i}\f$. * * \note It is not necessary to have an analytical formulation * of the derivative and a numerical evaluation of it can be provided. * * \todo Add a Levenberg-Marquardt fitter for this generic kind of function */ class nonlinear_function: public function { public: // methods //! Number of parameters to this non-linear function virtual int nbParameters() const = 0; //! Get the vector of parameters for the function virtual vec parameters() const = 0; //! Update the vector of parameters for the function virtual void setParameters(const vec& p) = 0; //! \brief Obtain the derivatives of the function with respect to the //! parameters. // // The x input of this function is the position in the input space and // has size dimX(), the resulting vector has the size of the parameters // times the size of the output domain. // // The result vector should be orderer as res[i + dimY()*j], output // dimension first, then parameters. virtual vec parametersJacobian(const vec& x) const = 0; }; Q_DECLARE_INTERFACE(function, "Fitter.Function")