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.


In [18]:
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)


power law index before change:
Parameter index = -2.0 []
(min_value = -10.0, max_value = 10.0, delta = 0.2, free = True)
power law index after change:
Parameter index = 0.0 []
(min_value = -10.0, max_value = 10.0, delta = 0.2, free = True)
power law index after creation:
Parameter index = -1.5 []
(min_value = -10.0, max_value = 10.0, delta = 0.2, free = True)

In [19]:
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)


Using Gaussian statistic (equivalent to chi^2) with the provided errors.
power law index before fit:
Parameter index = -2.0 []
(min_value = -10.0, max_value = 10.0, delta = 0.2, free = True)
Using Gaussian statistic (equivalent to chi^2) with the provided errors.
Best fit values:

result unit
parameter
source.spectrum.main.Powerlaw.K (9.97 -0.27 +0.28) x 10^-1 1 / (cm2 keV s)
source.spectrum.main.Powerlaw.index -1.493 +/- 0.010
Correlation matrix:

1.00-0.87
-0.871.00
Values of -log(likelihood) at the minimum:

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

statistical measures
AIC 54.084279
BIC 57.653006
power law index after fit:
Parameter index = -1.4925573458177759 []
(min_value = -10.0, max_value = 10.0, delta = 0.2, 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.


In [ ]: