pythonoptimizationscipysymfit

What is causing this warning in symfit?


Consider this simple optimization code:

from symfit import *


x1 = 1
x2 = 4
p1, p2 = parameters('p1, p2')
model = p1*p2
constraints = [
    Eq(x1*p1+(x2-x1)*p2, 1),
    Ge(p1, p2),
    Ge(p2, 0)
    ]

fit = Fit(- model, constraints=constraints)
fit_result = fit.execute()
print(fit_result)

This gives me the following warning:

/home/user/.local/lib/python3.5/site-packages/symfit/core/fit.py:1783: RuntimeWarning: invalid value encountered in double_scalars
  return 1 - SS_res/SS_tot

What is causing this?


Solution

  • This happens because symfit currently always tries to calculate the coefficient of determination (R^2) for the fit. In this case, since there is no data, both SS_res and SS_tot are zero, resulting in a 0/0 and hence the warning and the resulting nan in fit_results.

    We are now adding extra intelligence to FitResults such that it won't be calculated in the first place, but it is safe to ignore this warning.