#ifndef NUMMODELLEASTSQUAREB_HH #define NUMMODELLEASTSQUAREB_HH //////////////////////////////////////////////////////////////////////////// //! author="Robert Crida" //! lib=NumModelBasicModels //! date="2/2/1998" //! userlevel=Develop //! file="amma/PatternRec/FuncTools/Model/BasicModels/NumModelLeastSquareB.hh" //! docentry="Numerical Methods.Multidimensional Models.Implementation" //! rcsid="$Id: NumModelLeastSquareB.hh,v 1.6 2000/02/16 14:10:26 ees1cg Exp $" #include "amma/Num/NumModelB.hh" // -------------------------------------------------------------------------- // ********** NumModelLeastSquareBC *************************************** // ------------------------------------------------------------------------- //: Least squares model fitting implementation class. // // It provides an implementation for performing model to data fitting using // least squares regression. The form of the model is not incorporated in // this class.

// // In order to actually create a new form of model it is necessary to // overload the private member functions, MakeInput() and MakeJacobianInput(). // MakeInput must produce a vector which when multiplied by a matrix of the // model weights will produce a prediction. Similarly, MakeJacobian() should // produce a vector which when multiplied by the model weights produces the // partial derivative vector corresponding to the parameter i. class NumModelLeastSquareBC: public NumModelBC { MatrixC _A; virtual VectorC MakeInput (const VectorC &X) const=0; //: Used for fitting and evaluating any linear model // The output of the model is determined as A*MakeInput(X) which is a matrix // multiplied by a vector. virtual VectorC MakeJacobianInput (const VectorC &X, IndexT i) const=0; //: Used for calculating Jacobian of linear model // Each column i of the Jacobian is determined as A*MakeJacobianInput(X,i) public: NumModelLeastSquareBC (const StringC &name); //: Constructor takes concrete class name, this class is abstract NumModelLeastSquareBC (const StringC &name, istream &in); //: Constructor from a stream NumModelLeastSquareBC (const NumModelLeastSquareBC &m); //: Copy constructor protected: virtual VectorC Evaluate (const VectorC &X) const; //: Evaluates Y=f(X) virtual void Fit (const NumVVDataSetC &train); //: Performs necessary model fitting to supplied training samples virtual MatrixC Jacobian (const VectorC &X) const; //: Evaluates Jacobian matrix df(X)/dX. virtual const StringC GetInfo () const; //: Prints information about the model virtual BooleanT Save (ostream &out) const; //: Saves the model to a stream }; BooleanT IsMarginal (MatrixC m, SArray1dC invalid); //: Tests whether matrix is singular. // IsMarginal is used to determine whether or not the matrix m is singular // and would therefore be impossible to invert. It is used by // LeastSquaresModelC to detemine which parameters or model weights to // incorporate. #endif