What happens to the model/function during a fit?

The spectral/spatial shapes that are input into the models and subsequently used during the fit are objects. There parameters are members of those objects and when they are changed by the user or the fitting engine, the parameter values in those objects are modified.

[1]:
%%capture
from threeML import *

power_law = Powerlaw()

print("power law index before change:")
print(power_law.index)

power_law.index = 0

print("power law index after change:")
print(power_law.index)


# or create a power law with a different default index
power_law = Powerlaw(index=-1.5)

print("power law index after creation:")
print(power_law.index)
[2]:
import numpy as np

x = np.logspace(0, 2, 50)

xyl_generator = XYLike.from_function(
    "sim_data", function=power_law, x=x, yerr=0.1 * power_law(x)
)

y = xyl_generator.y
y_err = xyl_generator.yerr

fit_function = Powerlaw()

print("power law index before fit:")
print(fit_function.index)

xyl = XYLike("data", x, y, y_err)

parameters, like_values = xyl.fit(fit_function)


print("power law index after fit:")
print(fit_function.index)
12:38:24 INFO      Using Gaussian statistic (equivalent to chi^2) with the provided errors.            XYLike.py:62
12:38:25 INFO      Using Gaussian statistic (equivalent to chi^2) with the provided errors.            XYLike.py:62
power law index before fit:
Parameter index = -2.01 []
(min_value = -10.0, max_value = 10.0, delta = 0.20099999999999998, free = True)
         INFO      Using Gaussian statistic (equivalent to chi^2) with the provided errors.            XYLike.py:62
         INFO      set the minimizer to minuit                                             joint_likelihood.py:1042
         INFO      set the minimizer to MINUIT                                             joint_likelihood.py:1059
Best fit values:

result unit
parameter
source.spectrum.main.Powerlaw.K (9.76 -0.27 +0.28) x 10^-1 1 / (cm2 keV s)
source.spectrum.main.Powerlaw.index -1.481 +/- 0.010

Correlation matrix:

1.00-0.87
-0.871.00

Values of -log(likelihood) at the minimum:

-log(likelihood)
data 32.8702
total 32.8702

Values of statistical measures:

statistical measures
AIC 69.995718
BIC 73.564445
power law index after fit:
Parameter index = -1.4806575515238756 []
(min_value = -10.0, max_value = 10.0, delta = 0.20099999999999998, free = True)

After a fit, the fitted result are stored in an AnalysisResults object so that if the fit function’s values are further modified, the best fit parameters can still be recovered.

Why does my plugin not return a get_log_like()?

When a plugin is created, it does not have a likelihood model set initially. This is typically done when a DataList containing the plugin is passed to a JointLikelihood or BayesianAnalysis constructor along with a model. One can manually pass a model object to the plugin using the set_model() member of the plugin.

Why did my plugin lose its model?

If you use the same plugin with different models bvy passing it to successive JointLikelihood or BayesianAnalysis constructors, the plugin will have the last model with which it was used set as its model.

[ ]: