190 likes | 305 Views
MathMore. Lorenzo Moneta, Andràs Zsenei ROOT Meeting 19/8/2005. MathMore components. Special functions (extension of MathCore) Statistical functions (extension of MathCore) Derivation Integration Interpolation Root finding 1 dimensional minimization. The Current Implementation.
E N D
MathMore Lorenzo Moneta, Andràs Zsenei ROOT Meeting 19/8/2005
MathMore components • Special functions (extension of MathCore) • Statistical functions (extension of MathCore) • Derivation • Integration • Interpolation • Root finding • 1 dimensional minimization ROOT meeting, Andràs Zsenei
The Current Implementation • The relevant GSL code extracted into mathmore/src/gsl-xxx and compiled automatically (mathmore/Module.mk) • Easily maintainable and updateable compared to direct copy of the algorithms into ROOT classes ROOT meeting, Andràs Zsenei
Special Functions • Those functions from the N1687 Technical Report on Standard Library Extensions that use GSL implementa-tion (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1687.pdf) • For example: • Bessel Functions • Elliptic Integrals • Legendre Polynomials, etc ROOT meeting, Andràs Zsenei
Special Functions cont’d • Free functions following the C++ standard’s naming convention (N1687) • Trivial use: • root [0] gSystem->Load("libMathMore.so"); root [1] ROOT::Math::cyl_bessel_i(1.2, 2.4) (double)2.05567401212170076e+00 ROOT meeting, Andràs Zsenei
Statistical Functions • Cumulative Distribution Functions (CDF) of those distributions from MathCore which were missing: • Chi-square, T-distribution, etc • The inverses of the CDF-s • Free functions callable in a trivial way • Naming convention in N1668, but might change (following up…) • http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1069.pdf ROOT meeting, Andràs Zsenei
Function Interface • Minimal interface for functions used by all the nu-merical algorithms: IGenFunction, ParamFunction, Polynomial (see previous presentations) • It would be nice but not necessary if TF1 would implement this interface • class WrappedFunction<T> which wraps any C++ callable object (C free functions, functors, etc...) • Reviewed by CMS — several of the recommendations implemented • Still a few questions: • Gradients: interface or feature testing • NVI (Non-Virtual Interface) ROOT meeting, Andràs Zsenei
Derivation — an example of the overall design • Class Derivator which defines the user interface (constructors, member functions) and has an instance of GSLDerivator • Class GSLDerivator which calls the appropri-ate GSL functions • Both GSLDerivator.h and GSLDerivator.cxx are in mathmore/src so that implementa-tion details do not pollute ROOT header files ROOT meeting, Andràs Zsenei
Derivation — an example of the overall design, cont’d • Usage with function inheriting from IGenFunction: ROOT::Math::Polynomial *f1 = new ROOT::Math::Polynomial(2); … ROOT::Math::Derivator *der = new ROOT::Math::Derivator(*f1); double step = 1E-8; double x0 = 2; double result = der->EvalCentral(x0, step); double error = der->Error(); ROOT meeting, Andràs Zsenei
Derivation — an example of the overall design, cont’d • Usage with a function pointer: double myfunc ( double x, void * ) { return std::pow( x, 1.5); } ROOT::Math::Derivator *der = new ROOT::Math::Derivator(myfunc); double step = 1E-8; double x0 = 2; double result = der->EvalCentral(x0, step); ROOT meeting, Andràs Zsenei
Derivation — an example of the overall design, cont’d • Usage with modified TF1 (or any other callable implementing operator() ): TF1 *fun1 = new TF1("fun1","x*x+3*x",0,10); ROOT::Math::Derivator *der = new ROOT::Math::Derivator(ROOT::Math::WrappedFunction<TF1>(*fun1)); double step = 1E-8; double x0 = 2; double result = der->EvalCentral( x0, step); ROOT meeting, Andràs Zsenei
Derivation — an example of the overall design, cont’d • Straightforward to add the functionality into TF1’s Derivative() so that it is trans-parent to the old user (disadvantage: cre-ates a Derivator object for each call) • If performance is a major issue there is always the possibility to create the object oriented way as shown previously + use function pointers ROOT meeting, Andràs Zsenei
Integration • Non-adaptive, adaptive and adaptive singular (i.e. taking into account singularities) integration • Different Gauss-Konrod rules can be selected • Possibility to use infinite and semi-infinite ranges ROOT meeting, Andràs Zsenei
Interpolation • Linear, polynomial, Akima and Akima periodic interpola-tions ROOT meeting, Andràs Zsenei
Root Finding • Root finding of one dimensional functions • Bracketing algorithms: bisection, false position, Brent-Dekker • Polishing algorithms (derivatives): Newton, secant, Steffenson ROOT meeting, Andràs Zsenei
Minimization in 1 D • 1 dimensional minimization for cases where Minuit or Fumili would be too much overhead • Golden section algorithm • Brent algorithm ROOT meeting, Andràs Zsenei
In progress — Implementation type • How can we select the various implementations (GSL, original ROOT, Cernlib, etc..)? • An additional constructor for class Derivator which takes implementation type so that Derivator constructs an instance of worker class according to implementation chosen (i.e. GSL) • Have also a default implementation (for example used by TF1) which would allow to move Derivator.h into MathCore • Introduce a class MathSelector which manages centrally all the default implementations for the numerical algorithms; PluginManager would be convenient but not standalone ROOT meeting, Andràs Zsenei