1 / 19

Gemini and HEPFitting

Gemini and HEPFitting. Function minimization and fitting in LHC++. Zbigniew Szkutnik UMM Cracow szkutnik@mat.agh.edu.pl. Minimization and fitting. Minimization: finding a minimum value of a multi-argument function in a given region (optimization)

kalyca
Download Presentation

Gemini and HEPFitting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gemini and HEPFitting Function minimization and fitting in LHC++ Zbigniew Szkutnik UMM Cracow szkutnik@mat.agh.edu.pl Cern School of Computing

  2. Minimization and fitting • Minimization: finding a minimum value of a multi-argument function in a given region (optimization) • qualitative ‘uncertainty’ assessment through analyzing the shape of the function around the minimum • Fitting: minimization of a fit criterion function (chi-squared, ML, least squares e.t.c.) in order to find best-fit parameter values • ‘well-behaving’ objective functions • quantitative assessment of uncertainties in probabilistic terms • Generality versus efficiency • general tools for most common ‘regular’ problems, like fitting • specific problems may require specialized solutions Cern School of Computing

  3. Gemini: a GEneral MINImizer • minimization and error analysis package in C++ • fulfills the requirements from Minuit++ URD • complete Minuit’s functionality (Minos errors included) plus important extensions, e.g. • linear and general non-linear constraints • contour objects • unified OO API to Minuit, NAG C minimizers, ... • easy switch between Minuit and NAG C minimizers • light-weight package (~3200 lines, ~25% comments) • independent of (most of) the LHC++ environment Cern School of Computing

  4. Gemini: functions and objects • objective function (to be minimized) • general constraints functions (restrict the domain) • objective function object (encapsulates the objective function into an OBJfun object) • minimization object (NAGmin or CMinuit) • separate types for Minuit and NAG C working engines • public methods for all minimization-related actions • contour objects (GEminiContour) • overloaded ‘=‘ copies contour object • overloaded ‘+’ overlays contours Cern School of Computing

  5. Gemini: objective function Example problem:Minimizef(x,y,z) = x+y+z , given x^2 + y^2 + z^2 = 3 with obvious solution f(-1,-1,-1) = -3 void myfun(int nop, double g[], double*f, const double parms[], int code) { // define aliases for convenience const double &x=parms[0], &y=parms[1], &z=parms[2]; // compute function value *f = x+y+z; // compute gradient (optional, but helpful) if(code == 2) g[0] = g[1] = g[2] = 1; } Cern School of Computing

  6. Gemini: constraint function Example problem:Minimizef(x,y,z) = x+y+z , given x^2 + y^2 + z^2 = 3 void confun(int nop, double g[], double*conval, const double parms[], int code) { // define aliases for convenience const double &x=parms[0], &y=parms[1], &z=parms[2]; // compute constraint function value *conval = x*x+y*y+z*z; // compute gradient (optional, but helpful) if(code == 2) { g[0]=2*x; g[1]=2*y; g[2]=2*z; } } Cern School of Computing

  7. Gemini: solution #include ”gemini.h” void myfun(int nop,double g[],double*f,const double x[],int cd); void confun(int nop,double g[],double*f,const double x[],int cd); int main() { OBJfun f(myfun); // capture the objective function // create a minimization object NAGmin nlp(”Non-linear programming example”,3,&f); // non-linear constraint (id=11) if( nlp.setNlinConstraint(11, confun, 3.0, 3.0) ) exit(1); nlp.minimize(); nlp.printResults(); return(0); } Cern School of Computing

  8. Gemini: default output Results for "Non-linear programming example" =========================================== ==> Minimization by nag_opt_nlp. ==> Objective function called 4 times. No Name Value Error 1 parm1 -1.000e+000 6.325e+000 2 parm2 -1.000e+000 6.325e+000 3 parm3 -1.000e+000 1.095e+001 ==> Objective function value is -3.000e+000 Cern School of Computing

  9. Gemini: error analysis • Geometrical, qualitative ’uncertainty’ sets (Minos), computationally very costly • Probabilistic, quantitative meaning in statistical applications (confidence regions) • Taylor series approximation (Hessian-based errors) • Uncertainty sets for sub-vectors via projections Cern School of Computing

  10. HEPFitting: features • OO API for batch fitting (no graphics) • inherited Gemini’s functionality • easy switch between minimizers at compilation time • fits models to histograms (HTL) and to general sets of data points • arbitrary models and models composed of pre-defined components (Gaussian, polynomial, exponential) • chi-squared and Poisson maximum likelihood fits • fitting in arbitrarily selected sub-regions • easy creation of confidence regions • small (~1200 lines, ~20% comments) Cern School of Computing

  11. HEPFitting: steps to go (I) • Create a fitting objectHEPHistoFit myFitObj; • Load dataHisto1D *histo = … ; myFitObj.setHistogram(*histo);orint p; // space dimensionality int n; // number of data points double x[], fval[], ferr[]; myFitObj.setDataPoints(p,n,x,fval,ferr); Cern School of Computing

  12. HEPFitting: steps to go (II) • Define a model • create a model object of the type MODELfun// e.g. capture a user model function myFun(...)MODELfun myModel(myFun, spaceDim, noOfParms); • assign the model object to the fitting objectmyFitObj.setModel(&myModel); • Manipulate fit range, if necessary (full flexibility) • Perform the fit, obtain results, e.g.myFitObj.perform(Chi2fit); myFitObj.perform(PoissonMLfit); Cern School of Computing

  13. HEPFitting: built-in models • Gaussian Gparm1 * exp [ -0.5 * ( (x-parm2) / parm3 ) 2 ] • Polynomial Pnparm1 + parm2 * x + parm 3 * x 2 +…+ parm n+1 * x n • Exponential Eexp [ parm1 + parm2 * x ] Cern School of Computing

  14. Single-component models Use specialized model object constructor. Suitable model function, which also computes gradient, and an objective function suitable for the given model and fit criterion are created automatically. MODELfun model1(”G”); // Gaussian model MODELfun model2(”P2”); // second-degree polynomial model HEPHistoFit myFitObj; // create a fitting object // load some data ... myFitObj.setModel(&model1); myFitObj.perform(Chi2fit); ... myFitObj.setModel(&model2); myFitObj.perform(Chi2fit); Cern School of Computing

  15. Multi-component models • Derive your private class from MODELfun • Define the expression by overriding the virtual member function modelfun() • reference the components in the expression as f(0,x,p), f(1,x,p),… • modelfun() should return the value of the expression • if only the four basic operators (+-*/) are used to build the expression, there is a simple way to provide the gradient:“Look at the components f(i,x,p) as if they were all functions of the same single variable, use df(i,x,p) to denote derivatives, apply well-known differentiation rules and assign to g the resulting expression.” • Define the components through a specialized MODELfun constructor or via MODELfun.setComponents(char *string) Cern School of Computing

  16. Example: derived model class classmyModelObject :publicMODELfun{ public: // allow for setting components in the class definition myModelObject(char *components) : MODELfun(components){} // override modelfun, to define the expression // here, it’s simply the product of two components double modelfun(const double x[], const double p[], array_n<double>& g, int code){ // compute gradient, if requested if(code==2) g = df(0,x,p)*f(1,x,p) + f(0,x,p)*df(1,x,p); // return model function value return f(0,x,p)*f(1,x,p); } } Cern School of Computing

  17. Example: continued // use the derived class to define a model which is the product // of a Gaussian and a second-degree polynomial HEPHistoFit myFitObj; // fitting object myModelObject modObj(”P2,G”); // model object with components myFitObj.setModel(&modObj); // model assignement // load data, set initial parameters’ values e.t.c. ... // fix the first parameter of the Gaussian at 1 to ensure // identifiability (it’s the 4th parameter preceded // by 3 parameters of P2) myFitObj.parmDef(4,”Gmass”,1,1,1,1); // perform a fit ... Cern School of Computing

  18. Errors and confidence regions • default one-sigma errors • automatic selection of the error parameter (UP) according to the fitting method • Hessian-based and Minos confidence regions according to confidence level, e.g. // define contour objects GEminiContour c1('*'), c2('+’); // create Hessian- and Minos-based 90% regions for parms 1 and 3 myFitObj.ellipticalConfidenceRegion(1, 3, c1, 0.90); myFitObj.minosConfidenceRegion (1, 3, c2, 0.90); // overlay and plot (c1+c2).plot(); Cern School of Computing

  19. Overlaid contours Cern School of Computing

More Related