+ All Categories
Home > Documents > Fitting in AIDA General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions.

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

Date post: 05-Jan-2016
Category:
Upload: josephine-allen
View: 215 times
Download: 0 times
Share this document with a friend
21
Fitting in AIDA General Concepts • Requirements • JAIDA • Examples Interfaces Overview • Conclusions
Transcript
Page 1: Fitting in AIDA General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions.

Fitting in AIDA

• General Concepts• Requirements• JAIDA• Examples• Interfaces Overview• Conclusions

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

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

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

General Concepts Optimizing

Optimizer

User Result

Model/Function

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

General Concepts Fitting

Fitter

User Fit Result

Optimizer

Data Set Model/FunctionFit Method

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

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)

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

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

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

JAIDA

• JAIDA is our Java implementation of AIDA– http://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)

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

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.

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

Examples Binned fit to an IHistogram

//Create the factories…IFitter fitter = af.createFitFactory().createFitter();

//Perform the fitIFitResult result = fitter.fit(hist,”g”);

//Plot the resultIPlotter p = af.createPlotterFactory().create();p.region(0).plot(hist);p.region(0).plot(result.fittedFunction());p.show()

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

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 parametersdouble[] initialPars = { 1, 0.8, 5, 1, 5, 2, 0, 1};func.setParameters( initialPars );

//Control the parameters and set constraintsfitter.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 fitIFitResult fitResult = fitter.fit(hist2d,func);

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

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 columnsITuple tuple = (ITuple) tree.find(“myTuple”);IEvaluator eval = tupf.createEvaluator(“sqrt(px*px + py*py)”);

//Connect the data set to the ITuple through the IEvaluatordata.createConnection(tuple, eval);

//Perform the fitIFitResult fitResult = fitter.fit(data,func);

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

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

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

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

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

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

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

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()

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

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

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

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()

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

Interfaces Overview IFitData

• Connect the data– create1DConnection(…)– create2DConnection(…)– create3DConnection(…)– createConnection(…)

• Ranges– IRangeSet range(int)

• Utils– String dataDescription()– int dimension()– reset()

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

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[])

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

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()

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

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


Recommended