Skip to content
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

docs(decomposer): improve error messages #194

Merged
merged 1 commit into from
Aug 25, 2024
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
4 changes: 2 additions & 2 deletions tests/models/test_decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_raise_warning_for_low_init_rank_reduction(mock_data_array):
decomposer = Decomposer(
n_modes=target_variance, init_rank_reduction=init_rank_reduction
)
warn_msg = ".*components were computed which explain.*of the variance but.*of explained variance was requested. Consider increasing the `init_rank_reduction`"
warn_msg = "Dataset has .* components, explaining .* of the variance. However, .*explained variance was requested. Please consider increasing `init_rank_reduction`"
with pytest.warns(UserWarning, match=warn_msg):
decomposer.fit(mock_data_array)

Expand All @@ -243,7 +243,7 @@ def test_compute_at_least_one_component(mock_data_array):
)

# Warning is raised to indicate that the value of init_rank_reduction is too low
warn_msg = "`init_rank_reduction=.*` is too low and results in zero components. One component will be computed instead."
warn_msg = "`init_rank_reduction=.*` is too low resulting in zero components. One component will be computed instead."
with pytest.warns(UserWarning, match=warn_msg):
decomposer.fit(mock_data_array)

Expand Down
6 changes: 3 additions & 3 deletions xeofs/models/decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def fit(self, X, dims=("sample", "feature")):
self.n_modes_precompute = int(rank * self.init_rank_reduction)
if self.n_modes_precompute < 1:
warnings.warn(
f"`init_rank_reduction={self.init_rank_reduction}` is too low and results in zero components. One component will be computed instead."
f"`init_rank_reduction={self.init_rank_reduction}` is too low resulting in zero components. One component will be computed instead."
)
self.n_modes_precompute = 1

# TODO(nicrie): perhaps we can just set n_modes to rank if it is larger than rank (possible solution for #158)
if self.n_modes_precompute > rank:
raise ValueError(
f"n_modes must be smaller or equal to the rank of the data object (rank={rank})"
f"n_modes must be less than or equal to the rank of the dataset (rank = {rank})."
)

# Check if data is small enough to use exact SVD
Expand Down Expand Up @@ -212,7 +212,7 @@ def fit(self, X, dims=("sample", "feature")):
)
if n_modes_required > self.n_modes_precompute:
warnings.warn(
f"{self.n_modes_precompute} components were computed which explain {total_explained_variance:.2%} of the variance but {self.n_modes:.2%} of explained variance was requested. Consider increasing the `init_rank_reduction`."
f"Dataset has {self.n_modes_precompute} components, explaining {total_explained_variance:.2%} of the variance. However, {self.n_modes:.2%} explained variance was requested. Please consider increasing `init_rank_reduction`."
)
n_modes_required = self.n_modes_precompute

Expand Down
Loading