ReSampleData

class sherpa.sim.ReSampleData(data, model)[source] [edit on github]

Bases: NoNewAttributesAfterInit

Re-sample a 1D dataset using asymmetric errors.

For each iteration, each data point is resampled using normal distributions for the lower and upper sides based on the asymmetric errors, and then the data is fit (starting at the model “best-fit” location). The parameter values, statistic value, and re-sampled data for each iteration are returned.

Parameters
  • data (sherpa.data.Data1DAsymmetricErrs instance) – The data.

  • model (sherpa.models.model.ArithmeticModel instance) – The model to fit the data. The model parameters are taken to be the best-fit location.

Returns

sampled – The keys are samples, which contains the resampled data used in the fits as a niter by ndata array, and the free parameters from the fit, each as a NumPy array containing the best-fit parameter value from each iteration (of size niter).

Return type

dict

Notes

When called with no arguments the number of iterations is set to 1000 and the seed is set to None. The call method should be used instead if the values need changing.

Example

>>> from sherpa.astro import ui
>>> from sherpa.models.basic import PowLaw1D
>>> from sherpa.fit import Fit
>>> ui.load_ascii_with_errors(1, 'gro.txt', delta=False)
>>> data = ui.get_data(1)
>>> model = PowLaw1D('p1')
>>> fit = Fit(data, model)
>>> results = fit.fit()
>>> rd = ReSampleData(data, model)
p1.gamma : avg = -0.45420248162153376 , std = 0.1263323500098545
p1.ampl : avg = 178.84238884771565 , std = 78.40441241963649
>>> rd_results = rd(niter=10, seed=47)
>>> print(rd_results['p1.gamma'])
[-0.32872302 -0.12877417 -0.52554761 -0.57215054 -0.56462214 -0.45767851
 -0.50537904 -0.49456541 -0.46087699 -0.50370738]
>>> print(rd_results['p1.ampl'])
[ 76.77797067  23.71375218 219.70853134 289.93482138 282.85054769
 151.11542405 203.62594591 184.68814605 158.73489704 197.27385216]
>>> print(rd_results['statistic'])
[ 3181.39803175 15640.64148543   526.3225861    269.42556572
   255.21395223   631.70392914   271.34923174   349.71959439
  1896.22993898   579.80520809]
>>> print(rd_results['samples'].shape)
(10, 61)

Methods Summary

call(niter[, seed])

Resample the data and fit the model to each iteration.

Methods Documentation

call(niter, seed=None)[source] [edit on github]

Resample the data and fit the model to each iteration.

New in version 4.12.2: The samples and statistic keys were added to the return value, the parameter values are returned as NumPy arrays rather than as lists, and the seed parameter was made optional.

Parameters
  • niter (int) – The number of iterations.

  • seed (int or None, optional) – The seed value.

Returns

sampled – The keys are samples, which contains the resampled data used in the fits as a niter by ndata array, and the free parameters in the fit, containing a NumPy array containing the fit parameter for each iteration (of size niter).

Return type

dict

Notes

The fit for each iteration uses the input values of the model parameters as the starting point. The parameters of the model are not changed by this method.