Пример #1
0
    8.018943e-01, 1.839664e+00, 1.941974e+00, 1.276013e+00, 2.839654e+00,
    3.488302e+00, 3.775855e+00, 4.555187e+00, 4.477186e+00, 5.376026e+00
]
xerr = 3.000000e-01
y = [
    2.650644e-01, 1.472682e-01, 8.077234e-02, 1.850181e-01, 5.326301e-02,
    1.984233e-02, 1.866309e-02, 1.230001e-02, 9.694612e-03, 2.412357e-03
]
yerr = [
    1.060258e-01, 5.890727e-02, 3.230893e-02, 7.400725e-02, 2.130520e-02,
    7.936930e-03, 7.465238e-03, 4.920005e-03, 3.877845e-03, 9.649427e-04
]

# create a fit object from the data arrays
fit = Fit(data=[x, y], model_function=exponential)
fit.add_error(axis='x', err_val=xerr)  # add the x-error to the fit
fit.add_error(axis='y', err_val=yerr)  # add the y-errors to the fit

fit.do_fit()  # perform the fit
fit.report(asymmetric_parameter_errors=True
           )  # print a report with asymmetric uncertainties

# Optional: create a plot
plot = Plot(fit)
plot.plot(asymmetric_parameter_errors=True,
          ratio=True)  # add the ratio data/function and asymmetric errors

# Optional: create the contours profiler
cpf = ContoursProfiler(fit)
cpf.plot_profiles_contours_matrix(
)  # plot the contour profile matrix for all parameters
Пример #2
0
derivative of the model function it will vary depending on our choice of model parameters. This distorts our likelihood
function - the minimum of a chi2 cost function will no longer be shaped like a parabola (with a model parameter on the x
axis and chi2 on the y axis).

The effects of this deformation are explained in the non_linear_fit.py example.
"""

import matplotlib.pyplot as plt
from kafe2 import XYContainer, Fit, Plot
from kafe2.fit.tools import ContoursProfiler

# Construct a fit with data loaded from a yaml file. The model function is the default of f(x) = a * x + b
nonlinear_fit = Fit(data=XYContainer.from_file('x_errors.yml'))

# The x errors are much bigger than the y errors. This will cause a distortion of the likelihood function.
nonlinear_fit.add_error('x', 1.0)
nonlinear_fit.add_error('y', 0.1)

# Perform the fit.
nonlinear_fit.do_fit()

# Optional: Print out a report on the fit results on the console.
# Note the asymmetric_parameter_errors flag
nonlinear_fit.report(asymmetric_parameter_errors=True)

# Optional: Create a plot of the fit results using Plot.
# Note the asymmetric_parameter_errors flag
plot = Plot(nonlinear_fit)
plot.plot(fit_info=True, asymmetric_parameter_errors=True)

# Optional: Calculate a detailed representation of the profile likelihood