Skip to content

Stabilize ParticleDiagnostics normalization for extreme finite weights #4415

Description

@FlorianPfaff

Bug

ParticleDiagnostics.from_weights() normalizes nonnegative finite weights by summing them at their original scale. For valid inputs near the float64 limit, the sum can overflow to infinity even though all entries and their relative probabilities are well defined.

For example:

maximum = np.finfo(float).max
diagnostics = ParticleDiagnostics.from_weights([maximum, maximum / 2.0])

The current normalization computes an infinite total and therefore produces [0.0, 0.0]. The reported effective sample size and entropy are both zero instead of the correct values:

  • normalized weights: [2/3, 1/3]
  • ESS: 1.8
  • entropy: approximately 0.6365141683

Suggested fix

After validating finiteness, clip negative diagnostic weights as today, divide by the largest positive entry, and normalize the bounded scaled vector. Add a focused regression through ParticleDiagnostics.from_weights().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions