Skip to content

Score should raise ValueError for points outside support, not 0 #108

@MyznikovFD

Description

@MyznikovFD

Issue: _base_score should raise ValueError for points outside support, not return 0.0

Location: exponential.py, uniform.py, normal.py function _base_score

Problem:
Currently, for points outside the support of the exponential distribution, the function returns 0.0 instead of raising an exception. This is incorrect because:

  • The gradient is undefined (does not exist) for such points.
  • Returning 0.0 silently hides the error and can mislead downstream calculations

Expected behaviour:
When any element of x is outside the distribution’s support, the function must raise a ValueError (or RuntimeError) indicating that the score is undefined for those points.

Proposed fix:
Replace the np.where with an explicit check:

if np.any(x < 0):
    raise ValueError(f"Score is undefined for x < 0 (outside support). Got x = {x}")
grad = 1.0 / lam - x
return grad[..., np.newaxis]

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions