Home | News | Documentation | Download

Set parameters or fix parameters in fitting function

Dear Colleagues,
Attached is a functional program that performs a fit as I would like. I nonetheless have a question about using ‘SetParameter’ and ‘FixParameter’. If I use ‘SetParameters’ to initialize my parameters in my ‘main()’ function and they are propagated into various other auxiliary functions, should they be fixed in these auxilary functions using ‘FixParameters’ or should they be further propagated using ‘SetParameters’.
Instinctively, I feel that the parameters are only free in the ‘main()’ function and in the auxiliary function they should be considered fixed, as I have done in my program, but I am not completely sure.
test6MV_alpha_strydom_frm.c (6.9 KB)


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Hi @Ricardo_Lambo,
Thank you for your input. FixParameters internally calls SetParameter so I guess it’s just a matter of the order you want to give to the operations.

However in your code

dalpha_dz_shab.SetParameters(E0, R, B, A0, mu, d50, a, A); // Set A0, mu, R, E
dalpha_dz_shab.FixParameter(0, E0);
dalpha_dz_shab.FixParameter(1, R);
dalpha_dz_shab.FixParameter(2, B);
dalpha_dz_shab.FixParameter(3, A0);
dalpha_dz_shab.FixParameter(4, mu);

is a bit redundant since you are setting E0,R,B,A0,mu and then fixing them at the next line. If you know those parameters should be fixed you could leave out the call to SetParameters

Thanks @Vpadulan. But to try to home in a little more on my question, should I also fix the parameters ‘d50’, ‘a’, ‘A’ using FixParameters? In my main() function they are left as free parameters, but what should happen in the auxiliary functions. Should they be left free there as well?

That really depends on your analysis. Do you know a priori that those parameters should have a fixed value? Or are they uncertain? You should then use FixParameter or SetParameter respectively


the section called “Setting initial conditions” available here explains the difference. The TF1::SetParameters(...) merely initializes the parameters to some values, but it does not fix them in any way - they can still vary freely in both directions starting from the initial value.

The TF1::FixParameter(...), however, fixes the parameter, and it can no longer vary freely.

True, but it also fixes the parameter later on by setting both lower and upper limits on its possible range to the same value (see lines 1567 and 1568).

I agree. It’s not necessary to set the initial values of those parameters you are willing to fix.

Are you talking about fixing them for this fit:
graph->Fit("alpha", "R");
? If so, probably not: if you fix all seven of your fit parameters, why do you need the fit in the first place?

Thanks @yus and @vpadulan for your replies. I work in a group in which I am the only Root user so this forum is a lifeline to me. I see that I did not completely manage to make my question clear and the answers have so far dealt with a side issue which is a redundancy in my code.

I understand that in ‘main()’ function the parameters that I wish to be determined by the fit should be initialized using ‘SetParameter’ while the remaining parameters should be fixed using ‘FixParameter’. I also understand that ‘FixParameter’ calls ‘SetParameter’ so that while it is harmless to first use the latter before the former on a fixed parameter there is no real need to. I have removed this ambiguity from the ‘alpha_shab()’ function to try to get to the heart of my question.

I am asking about should happen in auxiliary functions. I have attached two sample codes to try to illustrate my point. In the ‘main()’ function my free parameters are ‘d50’, ‘A’ and ‘a’ which are then propagated into the function ‘alpha_shab()’ and then propagated into several other functions. As far as I can tell, it makes no difference whether in ‘alpha_shab()’ and these additional functions, I apply ‘FixParameter’ or ‘SetParameter’. It only matters how I apply ‘FixParameter’ and SetParameter’ in my ‘main()’ function. Is this correct?

Thanks in advance.

test6MV_alpha_strydom_frm1.c (6.9 KB) test6MV_alpha_strydom_frm2.c (7.0 KB) .

yes, it is correct.
FixParameter and SetParameter are equivalent in ‘alpha_shab()’ and additional functions.

Thanks for the confirmation @smgrig.