Skip to content

Conversation

@MyznikovFD
Copy link
Collaborator

@MyznikovFD MyznikovFD commented Dec 14, 2025

  • Implemented an exponential parametric family

  • File with implementations of concrete parametric families is separated into 3 files: normal.py, uniform.py, exponential.py

  • New files are located in their own directory builtins/contitnuous

Copy link
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.

Divide the changes into refactoring and features, you shouldn't lump everything together.

Comment on lines 132 to 133
with np.errstate(divide="ignore", invalid="ignore"):
return np.where(p < 1.0, -np.log(1.0 - p) / lambda_, np.inf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

-log(1-p)/lambda == -log1p(-p)/lambda, but log1p is more accurate near p=1

Comment on lines 158 to 163
result = np.where(
np.abs(t_arr) < 1e-12,
1.0 + 0j,
lambda_ / denominator,
)
return cast(ComplexArray, result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

1e-12 is a magic number. Make a variable inside the configure_exponential_family() function as you did it in tests

Comment on lines 200 to 202
def _exponential_support(_: Parametrization) -> ContinuousSupport:
"""Support of exponential distribution"""
return ContinuousSupport(left=0.0, right=math.inf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

right=math.inf is redundant here. We already have right=inf by default in ContinuousSupport .

Comment on lines 165 to 179
def test_analytical_computations_caching(self):
"""Test that analytical computations are properly cached."""
comp = self.exponential_family(lambda_=1.0).analytical_computations

expected_chars = {
CharacteristicName.PDF,
CharacteristicName.CDF,
CharacteristicName.PPF,
CharacteristicName.CF,
CharacteristicName.MEAN,
CharacteristicName.VAR,
CharacteristicName.SKEW,
CharacteristicName.KURT,
}
assert set(comp.keys()) == expected_chars
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and in similar tests in other families, there is a relic of the past in the form of a naming. Caching is no longer checked here, we need to rename it to something that reflects the point.

Comment on lines 181 to 192
def test_array_input_support(self):
"""Test that PDF supports array inputs."""
dist = self.exponential_family(lambda_=1.0)
x_array = np.array([-1.0, 0.0, 0.5, 1.0, 2.0, 3.0])

pdf = dist.query_method(CharacteristicName.PDF)
pdf_array = pdf(x_array)

assert pdf_array.shape == x_array.shape
scipy_pdf = expon.pdf(x_array, scale=1.0) # scale = 1/lambda = 1.0

self.assert_arrays_almost_equal(pdf_array, scipy_pdf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and in similar tests in other families, why are we checking only PDF?

@MyznikovFD MyznikovFD force-pushed the families/exponential-family-configuration branch from 4d203cb to 7de7ffe Compare December 18, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants