Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 28, 2025
1 parent 4d4f0d4 commit 33b2e79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/spikeinterface/sortingcomponents/clustering/circus.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CircusClustering:
"hdbscan_kwargs": {
"min_cluster_size": 20,
"min_samples": 1,
#"cluster_selection_epsilon": 0.1,
# "cluster_selection_epsilon": 0.1,
"cluster_selection_method": "eom",
"allow_single_cluster": True,
"core_dist_n_jobs": 1,
Expand Down
16 changes: 9 additions & 7 deletions src/spikeinterface/sortingcomponents/clustering/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def split_clusters(
# stop reccursivity when recursive_depth is reach
extra_ball = recursion_level < recursive_depth
else:
# always reccursive
# always reccursive
extra_ball = True

if extra_ball:
Expand Down Expand Up @@ -212,7 +212,7 @@ def split(
n_pca_features=2,
minimum_overlap_ratio=0.25,
projection_mode="pca",
percentile_variance_explained=95
percentile_variance_explained=95,
):
local_labels = np.zeros(peak_indices.size, dtype=np.int64)

Expand Down Expand Up @@ -252,11 +252,13 @@ def split(
nb_dimensions = min(flatten_features.shape[0], flatten_features.shape[1])
if projection_mode == "pca":
from sklearn.decomposition import PCA

tsvd = PCA(nb_dimensions, whiten=True)
elif projection_mode == "tsvd":
from sklearn.decomposition import TruncatedSVD

tsvd = TruncatedSVD(nb_dimensions)

final_features = tsvd.fit_transform(flatten_features)
thr = np.percentile(tsvd.explained_variance_ratio_, percentile_variance_explained)
indices = tsvd.explained_variance_ratio_ > thr
Expand All @@ -266,9 +268,11 @@ def split(
if flatten_features.shape[1] > n_pca_features:
if projection_mode == "pca":
from sklearn.decomposition import PCA

tsvd = PCA(n_pca_features, whiten=True)
elif projection_mode == "tsvd":
from sklearn.decomposition import TruncatedSVD

tsvd = TruncatedSVD(n_pca_features)

final_features = tsvd.fit_transform(flatten_features)
Expand Down Expand Up @@ -323,15 +327,13 @@ def split(
if k > -1:
centroid = final_features[:, :2][mask].mean(axis=0)
ax.text(centroid[0], centroid[1], f"Label {k}", fontsize=10, color="k")

ax = axs[1]
ax.plot(flatten_wfs[mask].T, color=colors[k], alpha=0.1)
if k > -1:
ax.plot(np.median(flatten_wfs[mask].T, axis=1), color=colors[k], lw=2)
ax.set_xlabel("PCA features")



ax = axs[3]
ax.plot(final_features[mask].T, color=colors[k], alpha=0.1)
if k > -1:
Expand All @@ -341,7 +343,7 @@ def split(
if tsvd is not None:
ax = axs[2]
sorted_components = np.argsort(tsvd.explained_variance_ratio_)[::-1]
ax.plot(tsvd.explained_variance_ratio_[sorted_components], c='k')
ax.plot(tsvd.explained_variance_ratio_[sorted_components], c="k")
del tsvd

axs[0].set_title(f"{clusterer} level={recursion_level}")
Expand Down

0 comments on commit 33b2e79

Please sign in to comment.