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.

from threeML import *

power_law = Powerlaw()

print("power law index before change:")

power_law.index = 0

print("power law index after change:")

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

print("power law index after creation:")
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:")

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

parameters, like_values = xyl.fit(fit_function)

print("power law index after fit:")
power law index before fit:
Parameter index = -2.01 []
(min_value = -10.0, max_value = 10.0, delta = 0.20099999999999998, free = True)
Best fit values:

result unit
source.spectrum.main.Powerlaw.K 1.019 -0.028 +0.029 1 / (cm2 keV s)
source.spectrum.main.Powerlaw.index -1.504 +/- 0.010

Correlation matrix:


Values of -log(likelihood) at the minimum:

data 28.510357
total 28.510357

Values of statistical measures:

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

[ ]: