Skip to content

Commit

Permalink
Fixed ruff warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
AS-L-C committed Jul 13, 2024
1 parent 5539612 commit c7f3f5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 10 additions & 6 deletions modules/transforms/liftings/graph2hypergraph/spectral_lifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def __init__(
def init_clust_alg(self, cluster_alg: str):
cluster_algs = {"KMeans": KMeans}
if cluster_alg not in cluster_algs:
warnings.warn(
f"KMeans will be used since the algorithm {cluster_alg} was not recognized. Available algorithms: {list(cluster_algs.values())}"
warnings.warn( # noqa: B028
f"KMeans will be used since the algorithm {cluster_alg} was not recognized. Available algorithms: {list(cluster_algs.values())}",
stacklevel=2,
)
self.cluster_alg = cluster_algs.get(cluster_alg, KMeans)

Expand Down Expand Up @@ -81,6 +82,7 @@ def find_gap(a):
s = v[:k].std()
if v[k] > m + s * a:
return k - 1
return None

def find_k_largest_diff():
"""Finds index largest gap usings absolute differences"""
Expand All @@ -101,13 +103,15 @@ def find_k_largest_diff():

if k is None or k == 1:
# Fall back to using largest absolute difference in case gap heuristic did not work
warnings.warn(
"Unable to confidently determine the number of clusters n_c. The largest difference between consecutive eigenvalues was used to determine the number of clusters. Please provide n_c."
warnings.warn( # noqa: B028
"Unable to confidently determine the number of clusters n_c. The largest difference between consecutive eigenvalues was used to determine the number of clusters. Please provide n_c.",
stacklevel=2,
)
k = find_k_largest_diff()
if k == 1:
warnings.warn(
"Please provide the number of clusters n_c. The heuristics identified a single cluster and n_c was set to 2."
warnings.warn( # noqa: B028
"Please provide the number of clusters n_c. The heuristics identified a single cluster and n_c was set to 2.",
stacklevel=2,
)
k += 1
return k
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Test the message passing module."""

import torch

from modules.data.utils.utils import load_manual_graph
from modules.transforms.liftings.graph2hypergraph.spectral_lifting import (
SpectralLifting,
Expand Down

0 comments on commit c7f3f5c

Please sign in to comment.