Skip to content

Commit

Permalink
prediction for all binned likelihoods (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Feb 10, 2023
1 parent 7ff1c79 commit 7d4f544
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/iminuit/cost.py
Expand Up @@ -1002,12 +1002,32 @@ def __init__(self, args, n, xe, verbose, *updater):
def _ndata(self):
return np.prod(self._masked.shape[: self._ndim])

@abc.abstractmethod
def _pred(self, args: _tp.Sequence[float]) -> np.ndarray:
... # pragma: no cover

def _update_cache(self):
super()._update_cache()
if self._bztrafo:
ma = _replace_none(self._mask, ...)
self._bztrafo = BohmZechTransform(self._data[ma, 0], self._data[ma, 1])

def prediction(self, args: _tp.Sequence[float]) -> np.ndarray:
"""
Return the bin expectation for the fitted model.
Parameters
----------
args : array-like
Parameter values.
Returns
-------
np.ndarray
Model prediction for each bin.
"""
return self._pred(args)

def visualize(self, args: _tp.Sequence[float]):
"""
Visualize data and model agreement (requires matplotlib).
Expand All @@ -1031,13 +1051,9 @@ def visualize(self, args: _tp.Sequence[float]):
if self.mask is not None:
cx = cx[self.mask]
plt.errorbar(cx, n, ne, fmt="ok")
mu = self._pred(args)
mu = self.prediction(args)
plt.stairs(mu, xe, fill=True, color="C0")

@abc.abstractmethod
def _pred(self, args: _tp.Sequence[float]) -> np.ndarray:
... # pragma: no cover


class BinnedCostWithModel(BinnedCost):
"""
Expand Down

0 comments on commit 7d4f544

Please sign in to comment.