Skip to content

Propagate agreemennt_method to compare_multiple_sorters #3737

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
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
3 changes: 2 additions & 1 deletion src/spikeinterface/comparison/basecomparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ class MixinSpikeTrainComparison:
* n_jobs
"""

def __init__(self, delta_time=0.4, n_jobs=-1):
def __init__(self, delta_time=0.4, agreement_method="count", n_jobs=-1):
self.delta_time = delta_time
self.n_jobs = n_jobs
self.agreement_method = agreement_method
self.sampling_frequency = None
self.delta_frames = None

Expand Down
10 changes: 9 additions & 1 deletion src/spikeinterface/comparison/multicomparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class MultiSortingComparison(BaseMultiComparison, MixinSpikeTrainComparison):
Minimum agreement score to match units
chance_score : float, default: 0.1
Minimum agreement score to for a possible match
agreement_method : "count" | "distance", default: "count"
The method to compute agreement scores. The "count" method computes agreement scores from spike counts.
The "distance" method computes agreement scores from spike time distance functions.
n_jobs : int, default: -1
Number of cores to use in parallel. Uses all available if -1
spiketrain_mode : "union" | "intersection", default: "union"
Expand All @@ -60,6 +63,7 @@ def __init__(
delta_time=0.4, # sampling_frequency=None,
match_score=0.5,
chance_score=0.1,
agreement_method="count",
n_jobs=-1,
spiketrain_mode="union",
verbose=False,
Expand All @@ -75,7 +79,9 @@ def __init__(
chance_score=chance_score,
verbose=verbose,
)
MixinSpikeTrainComparison.__init__(self, delta_time=delta_time, n_jobs=n_jobs)
MixinSpikeTrainComparison.__init__(
self, delta_time=delta_time, agreement_method=agreement_method, n_jobs=n_jobs
)
self.set_frames_and_frequency(self.object_list)
self._spiketrain_mode = spiketrain_mode
self._spiketrains = None
Expand All @@ -93,6 +99,8 @@ def _compare_ij(self, i, j):
sorting2_name=self.name_list[j],
delta_time=self.delta_time,
match_score=self.match_score,
chance_score=self.chance_score,
agreement_method=self.agreement_method,
n_jobs=self.n_jobs,
verbose=False,
)
Expand Down
10 changes: 10 additions & 0 deletions src/spikeinterface/comparison/tests/test_multisortingcomparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ def test_compare_multiple_sorters(setup_module):
)
msc = compare_multiple_sorters([sorting1, sorting2, sorting3], verbose=True)
msc_shuffle = compare_multiple_sorters([sorting3, sorting1, sorting2])
msc_dist = compare_multiple_sorters([sorting3, sorting1, sorting2], agreement_method="distance")

agr = msc._do_agreement_matrix()
agr_shuffle = msc_shuffle._do_agreement_matrix()
agr_dist = msc_dist._do_agreement_matrix()

print(agr)
print(agr_shuffle)
print(agr_dist)

assert len(msc.get_agreement_sorting(minimum_agreement_count=3).get_unit_ids()) == 3
assert len(msc.get_agreement_sorting(minimum_agreement_count=2).get_unit_ids()) == 5
Expand All @@ -57,7 +60,14 @@ def test_compare_multiple_sorters(setup_module):
assert len(msc.get_agreement_sorting(minimum_agreement_count=2).get_unit_ids()) == len(
msc_shuffle.get_agreement_sorting(minimum_agreement_count=2).get_unit_ids()
)
assert len(msc.get_agreement_sorting(minimum_agreement_count=3).get_unit_ids()) == len(
msc_dist.get_agreement_sorting(minimum_agreement_count=3).get_unit_ids()
)
assert len(msc.get_agreement_sorting(minimum_agreement_count=2).get_unit_ids()) == len(
msc_dist.get_agreement_sorting(minimum_agreement_count=2).get_unit_ids()
)
assert len(msc.get_agreement_sorting().get_unit_ids()) == len(msc_shuffle.get_agreement_sorting().get_unit_ids())
assert len(msc.get_agreement_sorting().get_unit_ids()) == len(msc_dist.get_agreement_sorting().get_unit_ids())
agreement_2 = msc.get_agreement_sorting(minimum_agreement_count=2, minimum_agreement_count_only=True)
assert np.all([agreement_2.get_unit_property(u, "agreement_number")] == 2 for u in agreement_2.get_unit_ids())

Expand Down