Skip to content

Commit e5ace48

Browse files
committed
fix(docs): fix sphinx generation error
1 parent 90a0687 commit e5ace48

File tree

8 files changed

+54
-37
lines changed

8 files changed

+54
-37
lines changed

rework_pysatl_mpest/core/mixture.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class MixtureModel(Generic[DType]):
7272
:toctree: generated/
7373
7474
add_component
75+
astype
7576
remove_component
7677
pdf
7778
lpdf
@@ -89,7 +90,7 @@ def __init__(
8990
):
9091
n_components = len(components)
9192
if n_components == 0:
92-
raise ValueError("List of components cannot be an empty")
93+
raise ValueError("List of components cannot be empty")
9394

9495
self._dtype = dtype
9596

@@ -130,7 +131,7 @@ def _validate_weights(self, n_components: int, weights: NDArray[DType]):
130131

131132
atol = np.sqrt(np.finfo(self.dtype).eps)
132133
if not np.isclose(np.sum(weights), self.dtype(1.0), atol=atol):
133-
raise ValueError(f"Sum of the weights must be equal 1, but it equal {np.sum(weights)}.")
134+
raise ValueError(f"Sum of the weights must be equal 1, but it equals {np.sum(weights)}.")
134135

135136
@property
136137
def dtype(self) -> type[DType]:

rework_pysatl_mpest/core/parameter.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ class Parameter:
5050
The name of the attribute used to store the value within an instance
5151
of the owner class.
5252
53+
Notes
54+
-----
55+
**Initialization Order**
56+
57+
This descriptor casts the assigned value to the owner instance's ``dtype``.
58+
Therefore, the instance must have its ``dtype`` attribute initialized
59+
**before** any value is assigned to this parameter.
60+
61+
In subclasses, ensure ``super().__init__(dtype=...)`` is called before
62+
assigning parameter values to avoid defaulting to ``np.float64``.
63+
5364
Examples
5465
--------
5566
@@ -61,6 +72,11 @@ class NormalDistribution(ContinuousDistribution):
6172
# Scale parameter must be a positive number
6273
scale = Parameter(invariant=lambda s: s > 0, error_message="Standard deviation (scale) must be positive.")
6374
75+
def __init__(self, loc, scale, dtype=np.float64):
76+
# Correct order: initialize dtype first
77+
super().__init__(dtype=dtype)
78+
self.loc = loc
79+
self.scale = scale
6480
"""
6581

6682
def __init__(

rework_pysatl_mpest/distributions/beta.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,33 @@
1515

1616

1717
class Beta(ContinuousDistribution):
18-
"""Class for the four-parameteric beta distribution.
19-
Parameters
20-
----------
21-
alpha : float
22-
The first shape parameter. Must be positive or zero.
23-
beta : float
24-
The second shape parameter. Must be positive or zero.
25-
left_border : float
26-
Left border of section [a, b]. Can be any real number.
27-
right_border : float
28-
Right border of section [a, b]. Can be any real number.
29-
30-
Attributes
31-
----------
32-
loc : float
33-
Location parameter.
34-
scale : float
35-
Scale parameter.
36-
scale : float
37-
Scale parameter (gamma). Must be positive.
38-
scale : float
39-
Scale parameter (gamma). Must be positive.
40-
41-
Methods
42-
-------
18+
"""Class for the four-parametric beta distribution.
19+
20+
Parameters
21+
----------
22+
alpha : float
23+
The first shape parameter. Must be positive or zero.
24+
beta : float
25+
The second shape parameter. Must be positive or zero.
26+
left_border : float
27+
Left border of section [a, b]. Can be any real number.
28+
right_border : float
29+
Right border of section [a, b]. Can be any real number.
30+
31+
Attributes
32+
----------
33+
alpha : float
34+
The first shape parameter.
35+
beta : float
36+
The second shape parameter.
37+
left_border : float
38+
Left border of the distribution support [a, b].
39+
right_border : float
40+
Right border of the distribution support [a, b].
41+
42+
43+
Methods
44+
-------
4345
4446
.. autosummary::
4547
:toctree: generated/
@@ -99,7 +101,7 @@ def pdf(self, X):
99101
where :math:`a` is the left_border parameter, :math:`b` is the
100102
right_border parameter, :math:`\\alpha` is the first shape parameter and
101103
:math:`\\beta` is the second shape parameter,:math:`B(\\alpha, \\beta) =
102-
\frac{\\Gamma(\\alpha)\\Gamma(\\beta)}{\\Gamma(\\alpha + \\beta)}`
104+
\\frac{\\Gamma(\\alpha)\\Gamma(\\beta)}{\\Gamma(\\alpha + \\beta)}`
103105
is the Beta function.
104106
105107
Parameters
@@ -112,7 +114,6 @@ def pdf(self, X):
112114
DType | NDArray[DType]
113115
The PDF values corresponding to each point in :attr:`X`.
114116
Return a scalar when given a scalar, and to return an array when given an array.
115-
116117
"""
117118

118119
X = np.asarray(X, dtype=self.dtype)
@@ -177,7 +178,7 @@ def lpdf(self, X):
177178
where :math:`a` is the left_border parameter, :math:`b` is the
178179
right_border parameter, :math:`\\alpha` is the first shape parameter and
179180
:math:`\\beta` is the second shape parameter, :math:`B(\\alpha, \\beta) =
180-
\frac{\\Gamma(\\alpha)\\Gamma(\\beta)}{\\Gamma(\\alpha + \\beta)}`
181+
\\frac{\\Gamma(\\alpha)\\Gamma(\\beta)}{\\Gamma(\\alpha + \\beta)}`
181182
182183
Parameters
183184
----------
@@ -211,7 +212,7 @@ def _dlog_alpha(self, X):
211212
212213
.. math::
213214
214-
\frac{\\partial \\ln f(x | \\alpha, \\beta, a, b)}{\\partial \\alpha} =
215+
\\frac{\\partial \\ln f(x | \\alpha, \\beta, a, b)}{\\partial \\alpha} =
215216
\\ln(x - a) - \\ln(b - a)
216217
- \\psi(\\alpha) + \\psi(\\alpha + \\beta)
217218

rework_pysatl_mpest/distributions/continuous_dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ContinuousDistribution(ABC, Generic[DType]):
3232
name: str
3333
The name of the distribution (e.g., 'Normal', 'Gamma').
3434
params: set[str]
35-
The names of all parameters of the distribution
35+
The names of all parameters of the distribution.
3636
params_to_optimize: set[str]
3737
Parameters names that are not fixed and can be optimized.
3838
fixed_params : set[str]

rework_pysatl_mpest/distributions/uniform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def pdf(self, X):
8585
8686
.. math::
8787
88-
f(x | \\alpha, \\beta) = frac{1}{\\beta - \\alpha}
88+
f(x | \\alpha, \\beta) = \\frac{1}{\\beta - \\alpha}
8989
9090
where :math:`\\alpha` is the left_border parameter and :math:`\\beta` is the
9191
right_border parameter. The function is zero for :math:`x < \\alpha` or :math:`x > \\beta`.

rework_pysatl_mpest/estimators/iterative/pipeline_step.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def clear_after_prune(self, removed_components_indices: list[int]) -> None:
9090
components.
9191
9292
Common use cases include:
93+
9394
- Deleting cached values or buffers associated with pruned components
9495
- Re-indexing remaining component-specific data to maintain contiguous
9596
indexing

rework_pysatl_mpest/estimators/iterative/steps/maximization_step.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ def clear_after_prune(self, removed_components_indices: list[int]) -> None:
159159
160160
Parameters
161161
----------
162-
state : PipelineState
163-
The current pipeline state containing removed_components_indices
164162
removed_components_indices : list[int]
165163
Tracks which component indices were removed during pruning.
166164
"""

rework_tests/unit/core/test_mixture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_init_with_invalid_weights_raises_value_error(
9292
@pytest.mark.parametrize(
9393
"invalid_weights, error_msg",
9494
[
95-
([0.4, 0.4], "Sum of the weights must be equal 1, but it equal "),
95+
([0.4, 0.4], "Sum of the weights must be equal 1, but it equals "),
9696
],
9797
)
9898
def test_init_with_invalid_sum_of_weights_raises_value_error(
@@ -108,7 +108,7 @@ def test_init_with_invalid_sum_of_weights_raises_value_error(
108108
def test_init_with_empty_components_raises_value_error(self, dtype):
109109
"""Tests that initialization with an empty component list raises a ValueError."""
110110

111-
with pytest.raises(ValueError, match="List of components cannot be an empty"):
111+
with pytest.raises(ValueError, match="List of components cannot be empty"):
112112
MixtureModel(components=[], dtype=dtype)
113113

114114
def test_init_casts_component_dtypes(self, dtype):

0 commit comments

Comments
 (0)