CStatNegativePenalty
- class sherpa.stats.CStatNegativePenalty(name: str = 'cstatnegativepenalty')[source] [edit on github]
Bases:
CStatCStat with penalty for negative model values.
The Cash statistic assumes that the model evaluation is always positive, as it requires evaluating the log of the model values. The
CStatclass replaces any model value that is 0 or negative by a small positive model (thetrunc_valueterm).The
CStatNegativePenaltystatistic instead applies a penalty to any model evaluation that leads to model values 0 or less, and this penalty increases as the values move further away from zero (inCStatthe penalty is a constant term). The aim is to guide the optimizer back to models that are all positive.The penalty term is (where M represents the model):
(sum_j M(j))
where j represents only those model values that are 0 or less.
When the model values are positive the statistic is the same as calculated by
CStat.Added in version 4.18.0.
Methods Summary
calc_stat(data, model)Return the statistic value for the data and model.
calc_staterror(data)Return the statistic error values for the data.
goodness_of_fit(statval, dof)Return the reduced statistic and q value.
Methods Documentation
- calc_stat(data: Data | DataSimulFit, model: Model) tuple[float, ndarray] [edit on github]
Return the statistic value for the data and model.
- Parameters:
data (
sherpa.data.Dataorsherpa.data.DataSimulFit) – The data set, or sets, to use.model (
sherpa.models.model.Modelorsherpa.models.model.SimulFitModel) – The model expression, or expressions. If asherpa.models.model.SimulFitModelis given then it must match the number of data sets in the data parameter.
- Returns:
statval (number) – The value of the statistic.
fvec (array of numbers) – The per-bin “statistic” value.
- static calc_staterror(data: ndarray) ndarray [edit on github]
Return the statistic error values for the data.
- Parameters:
data (scalar or 1D array of numbers) – The data values.
- Returns:
staterror – The errors for the input data values (matches the data argument).
- Return type:
scalar or array of numbers
- goodness_of_fit(statval: float, dof: int) tuple[Literal[None], Literal[None]] | tuple[float, float] [edit on github]
Return the reduced statistic and q value.
The reduced statisitc is conceptually simple, as it is just statistic / degrees-of-freedom, but it is not meaningful for all statistics, and it is only valid if there are any degrees of freedom.
- Parameters:
- Returns:
rstat (float or NaN or None) – The reduced statistic. If the statistic does not support a goodness of fit then the return value is
None. If it does then NaN is returned if either the number of degrees of freedom is 0 (or less), or the statistic value is less than 0.qval (float or NaN or None) – The q value. If the statistic does not support a goodness of fit then the return values are
None. If it does then NaN is returned if either the number of degrees of freedom is 0 (or less), or the statistic value is less than 0.