Skip to content

Commit

Permalink
add birch clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Aug 7, 2024
1 parent f51e492 commit f986621
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/depiction/tools/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import xarray
from numpy.typing import NDArray
from sklearn.cluster import KMeans, BisectingKMeans
from sklearn.cluster import KMeans, BisectingKMeans, Birch

from depiction.clustering.extrapolate import extrapolate_labels
from depiction.clustering.maxmin_sampling import maxmin_sampling
Expand All @@ -19,6 +19,7 @@
class MethodEnum(Enum):
KMEANS = "kmeans"
BISECTINGKMEANS = "bisectingkmeans"
BIRCH = "birch"


app = cyclopts.App()
Expand Down Expand Up @@ -55,7 +56,7 @@ def clustering(
method_params: str,
n_best_features: int = 30,
n_samples_cluster: int = 10000,
n_landmarks: int = 50,
n_landmarks: int = 200,
) -> None:
rng = np.random.default_rng(42)

Expand Down Expand Up @@ -116,6 +117,9 @@ def compute_labels(features: NDArray[float], method: MethodEnum, method_params:
elif method == MethodEnum.BISECTINGKMEANS:
clu = BisectingKMeans(n_clusters=10).fit(features)
return clu.labels_
elif method == MethodEnum.BIRCH:
clu = Birch(n_clusters=10).fit(features)
return clu.labels_
else:
raise ValueError(f"Method {method} not implemented")

Expand Down
22 changes: 12 additions & 10 deletions src/depiction_cluster_sandbox/run_cluster_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ def main():

samples = []
samples += ["concatenated"]
cluster_variants = [
"cluster_kmeans_default.png",
"cluster_bisectingkmeans_default.png",
"cluster_kmeans_featscv.png",
"cluster_bisectingkmeans_featscv.png",
"cluster-umap_kmeans_default.png",
"cluster-umap_kmeans_featscv.png",
]
result_files = [
work_dir / "work" / sample / cluster_variant for sample in samples for cluster_variant in cluster_variants

cluster_algos = ["kmeans", "bisectingkmeans", "birch"]
cluster_artifacts = [
file
for algo in cluster_algos
for file in [
f"cluster_{algo}_default.png",
f"cluster-umap2-{algo}_default-cluster.png",
f"cluster-umap2-{algo}_default-image_index.png",
]
]

result_files = [work_dir / "work" / sample / artifact for sample in samples for artifact in cluster_artifacts]

snakemake = SnakemakeInvoke(continue_on_error=False, snakefile_name=snakefile_path)
snakemake.invoke(
work_dir=work_dir,
Expand Down

0 comments on commit f986621

Please sign in to comment.