Last modified: December 2022

URL: https://cxc.cfa.harvard.edu/sherpa/ahelp/load_user_stat.html
Jump to: Description · Example · PARAMETERS · Notes · Bugs · See Also


AHELP for CIAO 4.15 Sherpa

load_user_stat

Context: statistics

Synopsis

Create a user-defined statistic.

Syntax

load_user_stat(statname, calc_stat_func, calc_err_func=None, priors={})

statname - str
calc_stat_func - func
calc_err_func - func, optional
priors - dict

Description

The choice of statistics - that is, the numeric value that is minimised during the fit - can be extended by providing a function to calculate a numeric value given the data. The statistic is given a name and then can be used just like any of the pre-defined statistics.


Example

Define a chi-square statistic with the label "qstat":

>>> def qstat(d, m, staterr=None, syserr=None, w=None):
...     if staterr is None:
...         staterr = 1
...     c = ((d-m) / staterr)
...     return ((c*c).sum(), c)
...
>>> load_user_stat("qstat", qstat)
>>> set_stat("qstat")

PARAMETERS

The parameters for this function are:

Parameter Definition
statname The name to use for the new statistic when calling `set_stat` .
calc_stat_func The function that calculates the statistic.
calc_err_func How to calculate the statistical error on a data point.
priors A dictionary of hyper-parameters for the priors.

Notes

The calc_stat_func should have the following signature:

def func(data, model, staterror=None, syserrr=None, weight=None)

where data is the array of dependent values, model the array of the predicted values, staterror and syserror are arrays of statistical and systematic errors respectively (if valid), and weight an array of weights. The return value is the pair (stat_value, stat_per_bin), where stat_value is a scalar and stat_per_bin is an array the same length as data.

The calc_err_func should have the following signature:

def func(data)

and returns an array the same length as data.


Bugs

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

See Also

data
dataspace1d, dataspace2d, datastack, fake, load_arf, load_arrays, load_ascii, load_bkg, load_bkg_arf, load_bkg_rmf, load_data, load_grouping, load_image, load_multi_arfs, load_multi_rmfs, load_pha, load_quality, load_rmf, load_staterror, load_syserror, load_table, pack_image, pack_pha, pack_table, unpack_arf, unpack_arrays, unpack_ascii, unpack_bkg, unpack_data, unpack_image, unpack_pha, unpack_rmf, unpack_table
filtering
load_filter
info
get_default_id, list_bkg_ids, list_data_ids
modeling
add_model, add_user_pars, load_table_model, load_template_interpolator, load_template_model, load_user_model, save_model, save_source
saving
save_arrays, save_data, save_delchi, save_error, save_filter, save_grouping, save_image, save_pha, save_quality, save_resid, save_staterror, save_syserror, save_table
statistics
set_stat