Skip to content

fix(families): raise ValueError for x outside support in exponential and uniform#118

Open
MyznikovFD wants to merge 1 commit into
mainfrom
score-function
Open

fix(families): raise ValueError for x outside support in exponential and uniform#118
MyznikovFD wants to merge 1 commit into
mainfrom
score-function

Conversation

@MyznikovFD
Copy link
Copy Markdown
Collaborator

No description provided.

@MyznikovFD MyznikovFD self-assigned this May 25, 2026
@MyznikovFD MyznikovFD requested review from Desiment and LeonidElkin and removed request for LeonidElkin May 25, 2026 16:00
@MyznikovFD MyznikovFD added Bug Something isn't working API: Consistency Internal Consistency of API/Behavior core.families core.families.builtins labels May 25, 2026
@MyznikovFD MyznikovFD moved this to In review in PySATL Core Developing May 25, 2026
@MyznikovFD MyznikovFD linked an issue May 25, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@LeonidElkin LeonidElkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue explicitly lists normal.py, but this commit does not add any support validation for the normal score. Even though all finite real values are in support, ContinuousSupport() excludes ±inf and NaN, and the current implementation returns inf/nan gradients for those inputs. Either add a finite-value check here or clarify why normal is intentionally out of scope.

Comment on lines +297 to +298
grad_a = np.full_like(x, 1.0 / width)
grad_b = np.full_like(x, -1.0 / width)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.full_like preserves the dtype of x. For integer inputs, 1.0 / width and -1.0 / width are cast to integers, so the score becomes [[0, 0], ...] instead of the expected floating-point gradient. Force a floating dtype here, e.g. np.full_like(x, ..., dtype=np.float64), and add a regression test with integer x.

Comment on lines +253 to +254
if np.any(x < 0):
raise ValueError(f"Score is undefined for x < 0 (outside support). Got x = {x}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check only rejects x < 0, but the family support excludes non-finite values as well. For example, ContinuousSupport(left=0.0).contains(np.inf) is false, while score([np.inf]) currently returns -inf instead of raising. Reject non-finite x values, ideally with a test for np.inf and np.nan.

Comment on lines +293 to +294
if np.any((x < a) | (x > b)):
raise ValueError(f"Score is undefined for x outside support [{a}, {b}]. Got x = {x}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This support check does not reject NaN: both (x < a) and (x > b) are false for NaN, so score([np.nan]) returns a regular-looking gradient. Since NaN is not contained in the distribution support, reject non-finite values before computing the gradient.

Comment on lines +442 to +443
ValueError
If any value in `x` lies outside the distribution's support.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented under a NumPy-style Raises section. Right now ValueError is placed directly after Returns, so the docstring structure is invalid and may render incorrectly in generated docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API: Consistency Internal Consistency of API/Behavior Bug Something isn't working core.families.builtins core.families

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Score should raise ValueError for points outside support, not 0

2 participants