Skip to content

Compute UnbinnedNLL with substraction rather than division #565

Description

@redeboer

The recent UnbinnedNLL.__call__ rewrite changes the computation from roughly:

    -sum(log(data_intensities / normalization_integral))

to:

    N * log(normalization_integral) - sum(log(data_intensities))

Findings:

  • This avoids a full normalized-likelihood temporary and is faster for NumPy in isolated benchmarks.
  • The rewrite is only equivalent when the normalization integral and all data intensities are strictly positive.
  • That is a slight behavioral change: the old formula could remain finite when data_intensities and normalization_integral were both negative, because their ratio was positive. The new formula logs them separately and returns NaN.
  • This exposed that benchmarks/expression.py used unconstrained signed mixture weights, so SciPy could try negative intensities. That benchmark should use a genuinely non-negative model.
  • Backend impact is not uniform. JAX/XLA may optimize the original expression already; TensorFlow and Numba need backend-appropriate benchmarking/synchronization to compare fairly.

Metadata

Metadata

Assignees

Labels

⚙️ EnhancementImprovements and optimizations of existing features

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions