Skip to content

Commit

Permalink
partial ndim support
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Dec 8, 2023
1 parent e45bbc9 commit 95123a1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/iminuit/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,13 +1519,18 @@ def __init__(self, n, xe, model, verbose, grad, use_pdf):
self._model_xe = np.row_stack(
[x.flatten() for x in np.meshgrid(*self.xe, indexing="ij")]
)
if use_pdf:
if use_pdf == "approximate":
dx = [np.diff(xe) for xe in self.xe]
xm = [xei[:-1] + 0.5 * dxi for (xei, dxi) in zip(self.xe, dx)]
xm = np.meshgrid(*xm, indexing="xy")
dx = np.meshgrid(*dx, indexing="ij")
self._model_xm = np.array(xm)
self._model_dx = np.prod(dx, axis=0)
elif use_pdf == "numerical":
raise NotImplementedError(
'use_pdf="numerical" is not supported for '
"multidimensional histograms"
)

self._model_len = np.prod(self._xe_shape)

Expand All @@ -1549,10 +1554,10 @@ def _pred_approximate(self, args: Sequence[float]) -> NDArray:
return y * self._model_dx

def _pred_numerical(self, args: Sequence[float]) -> NDArray:
assert self._ndim == 1

from scipy.integrate import quad

assert self._ndim == 1

d = np.empty(self._model_len - 1)
for i in range(self._model_len - 1):
a = self._model_xe[i]
Expand Down

0 comments on commit 95123a1

Please sign in to comment.