예제 #1
0
 def test_multicomp_graph(self):
     msc = sc.compare_multiple_sorters([self._sorting, self._sorting, self._sorting])
     sw.plot_multicomp_graph(msc, edge_cmap='viridis', node_cmap='rainbow', draw_labels=False)
     sw.plot_multicomp_agreement(msc)
     sw.plot_multicomp_agreement_by_sorter(msc)
     fig, axes = plt.subplots(len(msc.sorting_list), 1)
     sw.plot_multicomp_agreement_by_sorter(msc, axes=axes)
def compare_sorters(sort1, sort2):
    comp_KL_MS4 = sc.compare_two_sorters(sorting1=sort1, sorting2=sort2)
    mapped_units = comp_KL_MS4.get_mapped_sorting1().get_mapped_unit_ids()

    print('Klusta units:', sort1.get_unit_ids())
    print('Mapped Mountainsort4 units:', mapped_units)

    comp_multi = sc.compare_multiple_sorters(sorting_list=[sort1, sort2],
                                             name_list=['klusta', 'ms4'])

    sorting_agreement = comp_multi.get_agreement_sorting(minimum_matching=2)

    print('Units in agreement between Klusta and Mountainsort4:',
          sorting_agreement.get_unit_ids())

    w_multi = sw.plot_multicomp_graph(comp_multi)
    plt.show()
#############################################################################
# The multiple sorters comparison internally computes pairwise comparison,
# that can be accessed as follows:

print(mcmp.comparisons[0].sorting1, mcmp.comparisons[0].sorting2)
mcmp.comparisons[0].get_mapped_sorting1().get_mapped_unit_ids()

#############################################################################
print(mcmp.comparisons[1].sorting1, mcmp.comparisons[1].sorting2)
mcmp.comparisons[0].get_mapped_sorting1().get_mapped_unit_ids()

#############################################################################
# The global multi caomparison can be visualized with this graph

sw.plot_multicomp_graph(mcmp)

#############################################################################
#  We can see that there is a better agreement between tridesclous and
#  mountainsort (5 units matched), while klusta only has two matched units
#  with tridesclous, and three with mountainsort.

#############################################################################
# Consensus-based method
# ---------------------------
#
# We can pull the units in agreement with different sorters using the
# :code:`get_agreement_sorting` method. This allows to make spike sorting more
# robust by integrating the output of several algorithms. On the other
# hand, it might suffer from weak performance of single algorithms.
#
comp_multi = sc.compare_multiple_sorters(
    sorting_list=[sorting_MS4, sorting_KL], name_list=['klusta', 'ms4'])

##############################################################################
# When comparing with a ground-truth sorting extractor (1), you can get the sorting performance and plot a confusion
# matrix

comp_gt_KL.get_performance()
w_conf = sw.plot_confusion_matrix(comp_gt_KL)

##############################################################################
# When comparing two sorters (2), we can see the matching of units between sorters. For example, this is how to extract
# the unit ids of Mountainsort4 (sorting2) mapped to the units of Klusta (sorting1). Units which are not mapped has -1
# as unit id.

mapped_units = comp_KL_MS4.get_mapped_sorting1().get_mapped_unit_ids()

print('Klusta units:', sorting_KL.get_unit_ids())
print('Mapped Mountainsort4 units:', mapped_units)

##############################################################################
# When comparing multiple sorters (3), you can extract a :code:`SortingExtractor` object with units in agreement
# between sorters. You can also plot a graph showing how the units are matched between the sorters.

sorting_agreement = comp_multi.get_agreement_sorting(minimum_matching=2)

print('Units in agreement between Klusta and Mountainsort4:',
      sorting_agreement.get_unit_ids())

w_multi = sw.plot_multicomp_graph(comp_multi)
예제 #5
0
# example signal-to-noise ratio. Quality metrics can be computed using the :code:`toolkit.validation` submodule

import spikeinterface.toolkit as st

snrs = st.validation.compute_snrs(sorting_true,
                                  recording,
                                  save_as_property=True)

w_perf = sw.plot_sorting_performance(comp_MS4,
                                     property_name='snr',
                                     metric='accuracy')

##############################################################################
# Widgets using MultiSortingComparison
# -------------------------------------
#
# We can also compare all three SortingExtractor objects, obtaining a :code:`MultiSortingComparison` object.

multicomp = sc.compare_multiple_sorters(
    [sorting_true, sorting_MS4, sorting_KL])

##############################################################################
# plot_multicomp_graph()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~

w_multi = sw.plot_multicomp_graph(multicomp,
                                  edge_cmap='coolwarm',
                                  node_cmap='viridis',
                                  draw_labels=False,
                                  colorbar=True)