# 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)

19:47:05 INFO      Using Gaussian statistic (equivalent to chi^2) with the provided errors.            XYLike.py:89

19:47:06 INFO      Using Gaussian statistic (equivalent to chi^2) with the provided errors.            XYLike.py:89

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:89

         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 1.043 +/- 0.028 1 / (cm2 keV s)
source.spectrum.main.Powerlaw.index -1.512 +/- 0.010
Correlation matrix:


 1 -0.86 -0.86 1
Values of -log(likelihood) at the minimum:


-log(likelihood)
data 29.455345
total 29.455345
Values of statistical measures:


statistical measures
AIC 63.166009
BIC 66.734735
power law index after fit:
Parameter index = -1.5122569556023475 []
(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.

[ ]: