Describe the bug
FPE when calling Simplex with no free parameters.
Expected behavior
No FPE/crash
To Reproduce
simplex.cxx
#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/MnSimplex.h"
#include "Minuit2/FCNBase.h"
#include <fenv.h>
using namespace ROOT::Minuit2;
class TestChi2 : public ROOT::Minuit2::FCNBase
{
public:
TestChi2() {}
~TestChi2() {}
virtual double Up() const {return 1.0;}
virtual double operator () (const std::vector<double> &a) const
{
return std::pow(a.at(0)-0.11,2)+std::pow(a.at(1)-0.5,2)/100.0;
}
};
int main(int argc, char ** argv)
{
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
MnUserParameters fit_parameters;
fit_parameters.Add("A",0.118,0.01,0,1);
fit_parameters.Add("B",0.5,0.1,0.1,100.0);
fit_parameters.Fix("A");
fit_parameters.Fix("B");
TestChi2* FULL= new TestChi2();
MnUserParameters temp_fit_parameters=fit_parameters;
MnMigrad migrad0(*FULL, temp_fit_parameters);
FunctionMinimum min_migrad0 = migrad0(); // OK
MnSimplex simplex0(*FULL, temp_fit_parameters);
FunctionMinimum min_simplex0 = simplex0(); // FPE
exit(0);
}
g++ simplex.cc -o simplex.exe $(root-config --glibs --cflags) -lMinuit2
./simplex.exe
results in
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 ROOT::Minuit2::SimplexBuilder::Minimum (this=0x7ffcf9555c58, mfcn=..., seed=..., maxfcn=200, minedm=0.10000000000000001) at /usr/src/debug/root-6.22.02/math/minuit2/src/SimplexBuilder.cxx:48
#6 0x00007f045c93e1cd in ROOT::Minuit2::ModularFunctionMinimizer::Minimize (this=<optimized out>, mfcn=..., gc=..., seed=..., strategy=..., maxfcn=200, toler=<optimized out>) at /usr/src/debug/root-6.22.02/math/minuit2/src/ModularFunctionMinimizer.cxx:166
#7 0x00007f045c93c737 in ROOT::Minuit2::ModularFunctionMinimizer::Minimize (this=0x7ffcf9555c48, fcn=..., st=..., strategy=..., maxfcn=200, toler=0.10000000000000001) at /usr/src/debug/root-6.22.02/math/minuit2/src/ModularFunctionMinimizer.cxx:120
#8 0x00007f045c905c51 in ROOT::Minuit2::MnApplication::operator() (this=0x7ffcf9555b00, maxfcn=200, toler=0.10000000000000001) at /usr/src/debug/root-6.22.02/math/minuit2/src/MnApplication.cxx:57
#9 0x000000000041068c in main ()
===========================================================
Setup
CentOS7/gcc-4.8.5 root 6.22 from EPEL
Additional context
Not a personal priority of me, so it is unlikely that I will provode a patch in the next days.
However, I can briefly describe how the FPE occurs.
It occurs on line 48 in SimplexBuilder when all parameters are fixed and 1./double(n) is always 1/0. So it is just plain crash, not an FPE.
To avoid it the Simplex builder should not be called for the case when there are no free parameters but instead, ModularFunctionMinimizer::Minimize() should call FCn just once and return "current state".
And yes, just preempting a question about a fit with zero free parameters. Yes, it is very useful.
Imagine a set of different models fitted to the data using the same codebase. Some models have 2 free parameters, others 3, but some have 0. And for the last category because if this bug one cannot use simplex from ROOT. (I use migrad).
Describe the bug
FPE when calling Simplex with no free parameters.
Expected behavior
No FPE/crash
To Reproduce
simplex.cxx
results in
Setup
CentOS7/gcc-4.8.5 root 6.22 from EPEL
Additional context
Not a personal priority of me, so it is unlikely that I will provode a patch in the next days.
However, I can briefly describe how the FPE occurs.
It occurs on line 48 in SimplexBuilder when all parameters are fixed and 1./double(n) is always 1/0. So it is just plain crash, not an FPE.
To avoid it the Simplex builder should not be called for the case when there are no free parameters but instead, ModularFunctionMinimizer::Minimize() should call FCn just once and return "current state".
And yes, just preempting a question about a fit with zero free parameters. Yes, it is very useful.
Imagine a set of different models fitted to the data using the same codebase. Some models have 2 free parameters, others 3, but some have 0. And for the last category because if this bug one cannot use simplex from ROOT. (I use migrad).