Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prediction for all binned likelihoods #831

Merged
merged 1 commit into from Feb 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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