-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Currently, if you don't know the CDF analytically in an extended likelihood, you have the option to integrate within the bins via doing height * bin width or using numerical quadrature integration.
But what if you want something better than the rectangle appoximation. but something faster then quad?
You can hack your way around it and overwrite the ._pred_impl I think (from looking at the code) and so something like this
cost = ExtendedBinnedNLL(self._bin_values, self._bin_edges, model_pdf, use_pdf="approximate")
def _pred_simpson(args):
from scipy.integrate import simpson
d = np.empty(len(self._bin_edges) - 1)
for i in range(len(self._bin_edges) - 1):
a = self._bin_edges[i]
b = self._bin_edges[i + 1]
x_points = np.linspace(a, b, 11)
y_points = model_pdf(x_points, *args)
d[i] = simpson(y_points, x=x_points)
return d
cost._pred_impl = _pred_simpsonto register a simpson integration for example. But it definitely is hacky.
It would be nice if there is an official mechanism to support registering such "integrators" and maybe even add something in the middle of numeric quadrature and rectangle approximation in the official code in terms of accuracy vs speed. Maybe trapezoid or simpson?