Skip to content

Commit dab577f

Browse files
committed
Unified docstrings formatting for sphinx
1 parent f21e6ef commit dab577f

File tree

5 files changed

+28
-44
lines changed

5 files changed

+28
-44
lines changed

bayesflow/approximators/point_approximator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class PointApproximator(ContinuousApproximator):
1515
A workflow for fast amortized point estimation of a conditional distribution.
1616
1717
The distribution is approximated by point estimators, parameterized by a feed-forward
18-
:class:`bayesflow.networks.PointInferenceNetwork`. Conditions can be compressed by an optional summary network
19-
(inheriting from :class:`bayesflow.networks.SummaryNetwork`) or used directly as input to the inference network.
18+
:py:class:`~bayesflow.networks.PointInferenceNetwork`. Conditions can be compressed by an optional summary network
19+
(inheriting from :py:class:`~bayesflow.networks.SummaryNetwork`) or used directly as input to the inference network.
2020
"""
2121

2222
def estimate(
@@ -90,7 +90,7 @@ def sample(
9090
for the sampling process.
9191
split : bool, optional
9292
If True, the sampled arrays are split along the last axis, by default False.
93-
Currently not supported for :class:`PointApproximator` .
93+
Currently not supported for :py:class:`PointApproximator` .
9494
**kwargs
9595
Additional keyword arguments passed to underlying processing functions.
9696

bayesflow/scores/multivariate_normal_score.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MultivariateNormalScore(ParametricDistributionScore):
2323
This variable contains names of prediction heads that should lead to a warning when the adapter is applied
2424
in inverse direction to them.
2525
26-
For more information see :class:`ScoringRule`.
26+
For more information see :py:class:`ScoringRule`.
2727
"""
2828

2929
def __init__(self, dim: int = None, links: dict = None, **kwargs):

bayesflow/scores/normed_difference_score.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class NormedDifferenceScore(ScoringRule):
1515

1616
def __init__(self, k: int, **kwargs):
1717
super().__init__(**kwargs)
18+
19+
#: Exponent to absolute difference
1820
self.k = k
21+
1922
self.config = {"k": k}
2023

2124
def get_head_shapes_from_target_shape(self, target_shape: Shape):
@@ -24,13 +27,15 @@ def get_head_shapes_from_target_shape(self, target_shape: Shape):
2427
return dict(value=target_shape[1:])
2528

2629
def score(self, estimates: dict[str, Tensor], targets: Tensor, weights: Tensor = None) -> Tensor:
27-
"""
28-
Computes the scoring function based on the absolute difference between estimates and targets.
30+
r"""
31+
Computes the scoring function based on the absolute difference between **estimates** and **targets**.
32+
33+
:math:`S(\hat \theta, \theta; k) = | \hat \theta - \theta |^k`
2934
30-
This function extracts the "value" tensor from the `estimates` dictionary and computes
35+
This function extracts the Tensor named ``"value"`` from the **estimates** dictionary and computes
3136
the element-wise absolute difference between the estimates and the true targets. The
32-
difference is then exponentiated by `self.k`. The final score is computed using the
33-
`aggregate` method, which optionally applies weighting.
37+
difference is then exponentiated by :py:attr:`k`. The final score is computed using the
38+
:py:func:`aggregate()` method, which optionally applies weighting.
3439
3540
Parameters
3641
----------

bayesflow/scores/parametric_distribution_score.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,10 @@ def sample(self, *args, **kwargs):
2323
raise NotImplementedError
2424

2525
def score(self, estimates: dict[str, Tensor], targets: Tensor, weights: Tensor = None) -> Tensor:
26-
"""
27-
Computes the quantile-based scoring function.
28-
29-
This function extracts the "value" tensor from the `estimates` dictionary and computes
30-
the pointwise difference between the estimates and the targets, expanding the target
31-
dimensions as necessary.
32-
33-
The scoring function applies a quantile-based transformation to the difference, computing the
34-
mean score across a specified axis. The final score is then aggregated, optionally applying weights.
35-
36-
Parameters
37-
----------
38-
estimates : dict[str, Tensor]
39-
A dictionary containing tensors of estimated values. The "value" key must be present.
40-
targets : Tensor
41-
A tensor of true target values. The shape is adjusted to align with estimates.
42-
weights : Tensor, optional
43-
A tensor of weights corresponding to each estimate-target pair. If provided, it is used
44-
to compute a weighted aggregate score.
45-
46-
Returns
47-
-------
48-
Tensor
49-
The aggregated quantile-based score, computed using the absolute pointwise difference
50-
transformed by the quantile adjustment, optionally weighted.
26+
r"""
27+
Computes the log-score for a predicted parametric probability distribution given realized **targets**.
28+
29+
:math:`S(\hat p_\phi, \theta; k) = \log(\hat p_\phi(\theta))`
5130
"""
5231
scores = -self.log_prob(x=targets, **estimates)
5332
score = self.aggregate(scores, weights)

bayesflow/scores/scoring_rule.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class ScoringRule:
1515
when sampling from the true distribution. By minimizing an expected score, estimates with
1616
different properties can be obtained.
1717
18-
To define a custom :class:`ScoringRule`, inherit from this class and overwrite the score method.
18+
To define a custom :py:class:`ScoringRule`, inherit from this class and overwrite the score method.
1919
For proper serialization, any new constructor arguments must be taken care of in a `get_config` method.
2020
2121
Estimates are typically parameterized by projection heads consisting of a neural network component
2222
and a link to project into the correct output space.
2323
24-
A :class:`ScoringRule` can score estimates consisting of multiple parts. See :class:`MultivariateNormalScore`
25-
for an example of a :class:`ParametricDistributionScore`. That score evaluates an estimated mean
24+
A :py:class:`ScoringRule` can score estimates consisting of multiple parts. See :py:class:`MultivariateNormalScore`
25+
for an example of a :py:class:`ParametricDistributionScore`. That score evaluates an estimated mean
2626
and covariance simultaneously.
2727
"""
2828

@@ -34,7 +34,7 @@ class ScoringRule:
3434
Prediction heads can output estimates in spaces other than the target distribution space.
3535
To such estimates the adapter cannot be straightforwardly applied in inverse direction,
3636
because the adapter is built to map vectors from the inference variable space. When subclassing
37-
:class:`ScoringRule`, add the names of such heads to the following list to warn users about difficulties
37+
:py:class:`ScoringRule`, add the names of such heads to the following list to warn users about difficulties
3838
with a type of estimate whenever the adapter is applied to them in inverse direction.
3939
"""
4040

@@ -128,7 +128,7 @@ def get_head(self, key: str, output_shape: Shape) -> keras.Sequential:
128128
2. dense: A trainable linear projection with as many units as are required by the next component.
129129
3. reshape: Changes shape of output of projection to match requirements of next component.
130130
4. link: Transforms unconstrained values into a constrained space for the final estimator.
131-
See :mod:`bayesflow.links` for examples.
131+
See :py:mod:`~bayesflow.links` for examples.
132132
133133
This method initializes the components in reverse order to meet all requirements and returns them.
134134
@@ -138,7 +138,7 @@ def get_head(self, key: str, output_shape: Shape) -> keras.Sequential:
138138
Name of head for which to request a link.
139139
output_shape: Shape
140140
The necessary shape of estimated values for the given key as returned by
141-
:func:`get_head_shapes_from_target_shape()`.
141+
:py:func:`get_head_shapes_from_target_shape()`.
142142
143143
Returns
144144
-------
@@ -181,7 +181,7 @@ def score(self, estimates: dict[str, Tensor], targets: Tensor, weights: Tensor)
181181
182182
Examples
183183
--------
184-
The following shows how to score estimates with a :class:`MeanScore`. All :class:`ScoringRule` s
184+
The following shows how to score estimates with a :py:class:`MeanScore`. All :py:class:`ScoringRule`\ s
185185
follow this pattern, only differing in the structure of the estimates dictionary.
186186
187187
>>> import keras
@@ -207,7 +207,7 @@ def score(self, estimates: dict[str, Tensor], targets: Tensor, weights: Tensor)
207207

208208
def aggregate(self, scores: Tensor, weights: Tensor = None) -> Tensor:
209209
"""
210-
Computes the mean of scores, optionally applying weights.
210+
Computes the mean of **scores**, optionally applying **weights**.
211211
212212
This function computes the mean value of the given scores. When weights are provided,
213213
it first multiplies the scores by the weights and then computes the mean of the result.
@@ -224,8 +224,8 @@ def aggregate(self, scores: Tensor, weights: Tensor = None) -> Tensor:
224224
Returns
225225
-------
226226
Tensor
227-
The aggregated score computed as a weighted mean if `weights` is provided,
228-
or as the simple mean of `scores` otherwise.
227+
The aggregated score computed as a weighted mean if **weights** is provided,
228+
or as the simple mean of **scores** otherwise.
229229
"""
230230

231231
if weights is not None:

0 commit comments

Comments
 (0)