EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FunctionGradHessian.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FunctionGradHessian.h
1 #ifndef __FUNCTIONGRADHESSIAN__
2 #define __FUNCTIONGRADHESSIAN__
3 
4 #include <vector>
5 #include <Eigen/Core>
6 
7 namespace FitNewton
8 {
10  {
11  public:
12  FunctionGradHessian(unsigned int nparams=1, unsigned int nfixedparams=1) : npars(nparams), nfixedpars(nfixedparams)
13  {
14  fixedpars.assign(nfixedpars, 0.);
15  }
16 
18 
19  //false if parameters x are not in allowed region
20  virtual bool calcValGradHessian(const Eigen::VectorXd& x, double& val, Eigen::VectorXd& grad, Eigen::MatrixXd& hessian) = 0;
21  virtual bool calcValGrad(const Eigen::VectorXd& x, double& val, Eigen::VectorXd& grad)
22  {
23  Eigen::MatrixXd hess = Eigen::MatrixXd::Zero(grad.size(), grad.size());
24  return calcValGradHessian(x, val, grad, hess);
25  }
26 
27  unsigned int nPars(){return npars;}
28  unsigned int nFixedPars(){return nfixedpars;}
29  std::vector<double> getFixedPars(){return fixedpars;}
30 
31  void setFixedPar(unsigned int coor, double val){fixedpars[coor]=val;}
32 
33  //create a new instance of this class from the current instance
34  virtual FunctionGradHessian* Clone() const = 0;
35 
36  virtual void computeCovariance(const double& /*val*/, const Eigen::MatrixXd& /*hessian*/){}
37 
38  virtual void rescaleMove(const Eigen::VectorXd& /*pars*/, Eigen::VectorXd& /*move*/){}
39 
40 
41 
42  protected:
43  unsigned int npars;
44  unsigned int nfixedpars;
45 
46  std::vector<double> fixedpars;
47  };
48 }
49 
50 
51 
52 
53 #endif
54