Skip to content

Rename approximator.summaries to summarize with deprecation #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bayesflow/approximators/continuous_approximator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

import keras
import warnings

from bayesflow.adapters import Adapter
from bayesflow.networks import InferenceNetwork, SummaryNetwork
Expand Down Expand Up @@ -539,7 +540,7 @@
batch_shape, conditions=inference_conditions, **filter_kwargs(kwargs, self.inference_network.sample)
)

def summaries(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
def summarize(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
"""
Computes the learned summary statistics of given summary variables.

Expand Down Expand Up @@ -570,6 +571,14 @@

return summaries

def summaries(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
"""
.. deprecated:: 2.0.4
`summaries` will be removed in version 2.0.5, it was renamed to `summarize` which should be used instead.
"""
warnings.warn("`summaries` was renamed to `summarize` and will be removed in version 2.0.5.", FutureWarning)
return self.summarize(data=data, **kwargs)

Check warning on line 580 in bayesflow/approximators/continuous_approximator.py

View check run for this annotation

Codecov / codecov/patch

bayesflow/approximators/continuous_approximator.py#L579-L580

Added lines #L579 - L580 were not covered by tests

def log_prob(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
"""
Computes the log-probability of given data under the model. The `data` dictionary is preprocessed using the
Expand Down
11 changes: 10 additions & 1 deletion bayesflow/approximators/model_comparison_approximator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import keras
import numpy as np
import warnings

from bayesflow.adapters import Adapter
from bayesflow.datasets import OnlineDataset
Expand Down Expand Up @@ -404,7 +405,7 @@

return keras.ops.convert_to_numpy(keras.ops.softmax(output) if probs else output)

def summaries(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
def summarize(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
"""
Computes the learned summary statistics of given summary variables.

Expand Down Expand Up @@ -435,6 +436,14 @@

return summaries

def summaries(self, data: Mapping[str, np.ndarray], **kwargs) -> np.ndarray:
"""
.. deprecated:: 2.0.4
`summaries` will be removed in version 2.0.5, it was renamed to `summarize` which should be used instead.
"""
warnings.warn("`summaries` was renamed to `summarize` and will be removed in version 2.0.5.", FutureWarning)
return self.summarize(data=data, **kwargs)

Check warning on line 445 in bayesflow/approximators/model_comparison_approximator.py

View check run for this annotation

Codecov / codecov/patch

bayesflow/approximators/model_comparison_approximator.py#L444-L445

Added lines #L444 - L445 were not covered by tests

def _compute_logits(self, classifier_conditions: Tensor) -> Tensor:
"""Helper to compute projected logits from the classifier network."""
logits = self.classifier_network(classifier_conditions)
Expand Down
4 changes: 2 additions & 2 deletions bayesflow/diagnostics/metrics/model_misspecification.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def summary_space_comparison(
"statistics, or want to compare raw data and not summary statistics, please use the "
f"`bootstrap_comparison` function with `comparison_fn={comparison_fn_name}` on the respective arrays."
)
observed_summaries = convert_to_numpy(approximator.summaries(observed_data))
reference_summaries = convert_to_numpy(approximator.summaries(reference_data))
observed_summaries = convert_to_numpy(approximator.summarize(observed_data))
reference_summaries = convert_to_numpy(approximator.summarize(reference_data))

distance_observed, distance_null = bootstrap_comparison(
observed_samples=observed_summaries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

def test_valid_summaries(approximator_with_summaries, mean_std_summary_network, monkeypatch):
monkeypatch.setattr(approximator_with_summaries, "summary_network", mean_std_summary_network)
summaries = approximator_with_summaries.summaries({"summary_variables": keras.ops.ones((2, 3))})
summaries = approximator_with_summaries.summarize({"summary_variables": keras.ops.ones((2, 3))})
assert_allclose(summaries, keras.ops.stack([keras.ops.ones((2,)), keras.ops.zeros((2,))], axis=-1))


def test_no_summary_network(approximator_with_summaries, monkeypatch):
monkeypatch.setattr(approximator_with_summaries, "summary_network", None)

with pytest.raises(ValueError):
approximator_with_summaries.summaries({"summary_variables": keras.ops.ones((2, 3))})
approximator_with_summaries.summarize({"summary_variables": keras.ops.ones((2, 3))})


def test_no_summary_variables(approximator_with_summaries, mean_std_summary_network, monkeypatch):
monkeypatch.setattr(approximator_with_summaries, "summary_network", mean_std_summary_network)

with pytest.raises(ValueError):
approximator_with_summaries.summaries({})
approximator_with_summaries.summarize({})