Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fitting in AIDA General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions.

Similar presentations


Presentation on theme: "Fitting in AIDA General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions."— Presentation transcript:

1 Fitting in AIDA General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions

2 General Concepts The main players: –Data Set the actual data, i.e. an Histogram –Model or Function a set of parametric shapes to describe the data –Fitter the engine that finds the best fit between the data and the model by changing a set of paramters –Fit Method the method used by the fitter to evaluate the “best fit”, i.e. Chi2, Least Squares etc. –Fit Result the actual result of a fit –new set of parameters –covariance matrix –contours –scans –Optimizer the engine that calculates the minimum (or maximum) of the problem

3 General Concepts Optimizing Optimizer User Result Model/Function

4 General Concepts Fitting Fitter User Fit Result Optimizer Data SetModel/FunctionFit Method

5 Requirements Easy to use and configure –change fit method –change data set –change model Easy access to pool of optimizers –Minuit is a must, but not the only product. Many optimizers are available. Accept user-provided custom functions Straightforward way to build complicated models –Add, multiply and convolute (analytically when possible)

6 Requirements Same interface for binned and unbinned fits –binned fit to histogram –unbinned fit to a tuple Similar interfaces for fitting and optimization Multiple fit methods supported –least squares –chi2 –…user defined (advanced) Support for simultaneous fits –fits over different data sets

7 JAIDA JAIDA is our Java implementation of AIDA –http://java.freehep.org/jaida/index.htmlhttp://java.freehep.org/jaida/index.html Fitting implementation: –fit methods least squares –“leastsquares”, “ls” chi2 –“chi2”, “chisquared” clever chi2 –“cleverchi2”, cleverchisquared” binned maximum likelihood –“bml”, “binnedmaxlikelihood”, binnedmaximumlikelihood” unbinned maximum likelihood –“uml”, “unbinnedmaxlikelihood”, “unbinnedmaximumlikelihood” –engines Minuit Uncmin (pure java code)

8 JAIDA –built-in functions gaussian “g” –“amplitude”, “mean”, “sigma” exponential “e” –“amplitude”, “exponent” polynomials “p0”,”p1”,… –“p1”,”p2”… Clear distinction between optimization and error analysis –easy to adopt new optimizers The examples below are based on JAIDA –other implementations might have different fit methods or optimizers.

9 Examples Binned fit to an IHistogram //Create the factories … IFitter fitter = af.createFitFactory().createFitter(); //Perform the fit IFitResult result = fitter.fit(hist,”g”); //Plot the result IPlotter p = af.createPlotterFactory().create(); p.region(0).plot(hist); p.region(0).plot(result.fittedFunction()); p.show()

10 Examples Binned fit to a 2D Histogram //Create the factories … IFunctionfactory funcFactory = af.createFunctionFactory( tree ); IFitter fitter = af.createFitFactory().createFitter("chi2","minuit"); //Create a scripted function, a sum of two gaussians IFunction func = funcFactory.createFunctionFromScript("twoDdistr",2,"N*(a*exp( -(x[0]- mu0)*(x[0]-mu0)/(2*s0*s0) )+(1-a)*exp( -(x[0]-mu1)*(x[0]-mu1)/(2*s1*s1) ))*exp( - (x[1]-mu2)*(x[1]-mu2)/(2*s2*s2) )","N,a,mu0,s0,mu1,s1,mu2,s2","",null); //Set the initial parameters double[] initialPars = { 1, 0.8, 5, 1, 5, 2, 0, 1}; func.setParameters( initialPars ); //Control the parameters and set constraints fitter.fitParameterSettings("mu2").setFixed(true); fitter.fitParameterSettings("a").setBounds(0.5,0.9); fitter.fitParameterSettings("a").setStepSize(0.001); fitter.fitParameterSettings("s1").setBounds(2,4); fitter.fitParameterSettings("s1").setStepSize(0.1); fitter.setConstraint("s0 = s2"); fitter.setConstraint("mu0 = mu1"); //Perform the fit IFitResult fitResult = fitter.fit(hist2d,func);

11 Examples Unbinned Fit //Create the factories … IFunctionfactory funcFactory = af.createFunctionFactory( tree ); IFitFactory fitf = af.createFitFactory(); IFitter fitter = fitf.createFitter(“uml",“uncmin"); IFitData data = fitf.createFitData(); ITupleFactory tupf = af.createTupleFactory(tree); //Create a function, control the parameters, set bounds and constraints… //… //Get and ITuple and create an IEvaluator for its columns ITuple tuple = (ITuple) tree.find(“myTuple”); IEvaluator eval = tupf.createEvaluator(“sqrt(px*px + py*py)”); //Connect the data set to the ITuple through the IEvaluator data.createConnection(tuple, eval); //Perform the fit IFitResult fitResult = fitter.fit(data,func);

12 Interfaces Overview The factories From IAnalysisFactory –IFitFactory createFitFactory() –IFunctionFactory createFunctionFactory(ITree) IFitFactory creates –fitters –data sets (for advanced data handling) e.g. select columns from tuple IFunctionFactory creates –functions

13 Interfaces Overview IFitFactory Methods –IFitData createFitData() –IFitter createFitter(fitMethod,engine) Through IFitData connections to all the AIDA data objects are established IFitter is the main fitting engine

14 Interfaces Overview IFunctionFactory IFunction creatFunctionByName(name,model) IFunction createFunctionFromScript(……) IFunction cloneFunction(name, function) IFunctionCatalog catalog() “byName” are built-in functions “fromScript” are scripted functions user-defined functions –e.g. define “Gauss+Gauss+Pol1+…” to be “myFavoriteFunc” …that can be added to a function catalog for future use

15 Interfaces Overview IFitter Do the fit –IFitResult fit(“data”,”model”,”pars”) –IDataPointSet createContour(IFitData, IFitResult…..) –IDataPointSet createScan1D(IFitData, IFunction…) Configure the fitter –void setFitMethod(String) –String fitMethodName() –void setEngine(String) –String engineName() –void setUseFunctionGradient(boolean) –boolean userFunctionGradient() Control the parameters in the fit –IFitParameterSetting fitParameterSettings(String) –String[] listParameterSettings() –void resetParameterSettings()

16 Interfaces Overview IFitter Constraints –void setConstraint(String) –String[] constraints() –void resetConstraints() The fitter does not change the function; the fitted parameters are in the IFitResult

17 Interfaces Overview IFitResult Fit outcome –int fitStatus() –int ndf() –double quality() Fit info –String fitMethodName() –String engineName() –String dataDescription() –String[] constraints() Fitted function –IFunction fittedFunction() –String[] fittedParameterNames() –double fittedParameter(String) –double fittedParameters() –IFitParameterSettings fitParameterSettings(String) Errors –double covMatrixElement(int,int) –double[] errors() –double[] errorsMinus() –double[] errorsPlus()

18 Interfaces Overview IFitData Connect the data –create1DConnection(…) –create2DConnection(…) –create3DConnection(…) –createConnection(…) Ranges –IRangeSet range(int) Utils –String dataDescription() –int dimension() –reset()

19 Interfaces Overview IFunction General –double value(double[]) –double[] gradient(double[] x) –int dimension() –int numberOfParameters() –boolean providesGradient() Variables –String variableName(int) –String[] variableNames() Parameters –String[] parameterNames() –double[] parameters() –double parameter(String) –int indexOfParameter(String) –void setParameter(String,double) –void setParameters(double[])

20 Interfaces Overview IFitParameterSettings Control a parameter –Bounds double lowerBound() void setLowerBound(double) double upperBound() void setUpperBound() boolean isBound() void setBounds(double, double) void removeBounds() –Step void setStepSize(double) double stepSize() –Fix boolean isFixed() void setFixed(boolean) –Other void reset() String name()

21 Conclusions AIDA has a complete set of interfaces for fitting flexible interfaces –room for improvements JAIDA future: –Extend the pool of optimizers –Implement more built-in functions –Allow model-building


Download ppt "Fitting in AIDA General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions."

Similar presentations


Ads by Google