Root interpolator embedded in a TF1

Hello Colleagues,
Is it possible to use Root interpolator embedded in TF1 in direct analogy as has been done here with TSpline3:

My attempt with the data set attached gave me the error ‘ERROR: x values must be strictly increasing.’
kpias_C6_10.c (7.3 KB)
C6.txt (574 Bytes)

Regards,


Please read tips
for efficient and successful posting
and posting code

Regards,
RL
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


I think @moneta can help you.

Hi,

Your attempt seems fine to me. The error is clear, have you tried sorting the data before passing to the Interpolator ? You can use std::sort or TMath::Sort

Lorenzo

Hi @moneta

Thanks for the quick reply, but I believe that a quick glance at the original data shows it to be already sorted in increasing ‘x’.

Hi,

The problem is that in same case the interpolate points are NaN. This happens because you are using this spline for fitting. This will not work with a gradient method like Minuit because you cannot differentiate on the interpolate points (your fitting parameters).
Why are you fitting the graph with the interpolated function ? What are you trying to achieve ?

Lorenzo

I understand the problem now @moneta and appreciate your explanation.

I am using a spline because it will require fewer parameters than a polynomial expansion to fit the curves that I am working with. The number of parameters has to be practical number since I intend to make them available to others.

Is there a simple work-around? The advantage of the Root interpolator is that I can choose various different splines (akima, cubic etc) where as with TSpline3, I am limited to one type.

Hi,

What you can do in this case is to use a Minimizer algorithm for fitting that does not use the derivatives. For example using Simplex or simulated annealing from GSL
You need to add just this line before fitting:

ROOT::Math::MinimizerOptions::SetDefaultMinimizer("Minuit","Simplex");

You might also need to set bounds on the function parameter (i.e. the input data points) that they stay in the correct order, for example that x1 is guaranteed to be always less than x2.

Lorenzo

Lorenzo

Thanks @moneta Your suggestions seems to have allowed to code to compile without errors, but I can’t full yunderstand why I still get the messages: “Warning in ROOT::Math::GSLInterpolator::Eval: input domain error” and some other similar fits “ERROR: x values must be strictly increasing”.

If you look at the original data, “x” is already in increasing order such that “x1” is less than “x2”.

Hi,
Th problem is that when fitting x1 and x2 are parameters of your function and will vary. Then it is possible that x1 becomes larger than x2. I would limit them to vary between some defined range for example x1 should never become bigger than (x1_0+x2_0)/2 and x2 never smaller that this value, where x1_01 and x2_0 are the initial values of x1 and x2.

Thanks. This worked.