def test_returns_correct_distance_for_multiunits(self):
     a0 = neo.SpikeTrain(sp.array([1.0, 5.0, 7.0]) * pq.s, t_stop=8.0 * pq.s)
     a1 = neo.SpikeTrain(sp.array([1.0, 2.0, 5.0]) * pq.s, t_stop=8.0 * pq.s)
     b0 = neo.SpikeTrain(sp.array([2.0, 4.0, 5.0]) * pq.s, t_stop=8.0 * pq.s)
     b1 = neo.SpikeTrain(sp.array([3.0, 8.0]) * pq.s, t_stop=9.0 * pq.s)
     units = {0: [a0, a1], 1: [b0, b1]}
     weighting = 0.3
     expected = sp.array([[0.0, 2.37006181], [2.37006181, 0.0]])
     actual = stm.van_rossum_multiunit_dist(units, weighting)
     assert_array_almost_equal(expected, actual)
Example #2
0
 def test_compare_square_with_spykeutils(self):
     for cos in self.cos:
         for tau in self.tau:
             sutils_d = stm.van_rossum_multiunit_dist(self.sutils_units,
                                                      weighting=cos,
                                                      tau=tau)
             pymuvr_d_square = pymuvr.square_distance_matrix(self.pymuvr_observations,
                                                             cos,
                                                             tau)                
             np.testing.assert_allclose(sutils_d, pymuvr_d_square, atol=5e-5)
Example #3
0
 def test_compare_square_with_spykeutils(self):
     for cos in self.cos:
         for tau in self.tau:
             sutils_d = stm.van_rossum_multiunit_dist(self.sutils_units,
                                                      weighting=cos,
                                                      tau=tau*pq.s)
             pymuvr_d_square = pymuvr.square_distance_matrix(self.pymuvr_observations,
                                                             cos,
                                                             tau)                
             np.testing.assert_allclose(sutils_d, pymuvr_d_square, atol=5e-5)
 def test_allows_tau_equal_to_infinity_with_multiunits(self):
     a0 = neo.SpikeTrain(sp.array([1.0, 5.0, 7.0]) * pq.s, t_stop=8.0 * pq.s)
     a1 = neo.SpikeTrain(sp.array([5.0]) * pq.s, t_stop=8.0 * pq.s)
     b0 = neo.SpikeTrain(sp.array([2.0, 4.0, 5.0]) * pq.s, t_stop=8.0 * pq.s)
     b1 = neo.SpikeTrain(sp.array([3.0, 8.0]) * pq.s, t_stop=9.0 * pq.s)
     units = {0: [a0, a1], 1: [b0, b1]}
     weighting = 0.3
     tau = sp.inf * pq.s
     dist = sp.sqrt(5.0 + weighting * 4.0)
     expected = sp.array([[0.0, dist], [dist, 0.0]])
     actual = stm.van_rossum_multiunit_dist(units, weighting, tau)
     assert_array_almost_equal(expected, actual)
def main():
    n_observations = 5
    n_cells = 50
    rate = 30
    tstop = 3
    cos = 0.1
    tau = 0.012

    sutils_units, pymuvr_observations = generate_spike_trains(n_observations, n_cells, rate, tstop)
    sutils_start = time.clock()
    sutils_d = stm.van_rossum_multiunit_dist(sutils_units, weighting=cos, tau=tau * pq.s)
    sutils_stop = time.clock()
    pymuvr_start = time.clock()
    pymuvr_d = pymuvr.square_distance_matrix(pymuvr_observations, cos, tau)
    pymuvr_stop = time.clock()

    print("\nspykeutils distance matrix:\n{0}\n\n".format(sutils_d))
    print("\npymuvr distance matrix:\n{0}\n\n".format(pymuvr_d))
    print("Time elapsed: pymuvr {0}s, spykeutils {1}s".format(pymuvr_stop-pymuvr_start, sutils_stop-sutils_start))
def main():
    n_observations = 5
    n_cells = 50
    rate = 30
    tstop = 3
    cos = 0.1
    tau = 0.012

    sutils_units, pymuvr_observations = generate_spike_trains(
        n_observations, n_cells, rate, tstop)
    sutils_start = time.clock()
    sutils_d = stm.van_rossum_multiunit_dist(sutils_units,
                                             weighting=cos,
                                             tau=tau * pq.s)
    sutils_stop = time.clock()
    pymuvr_start = time.clock()
    pymuvr_d = pymuvr.square_distance_matrix(pymuvr_observations, cos, tau)
    pymuvr_stop = time.clock()

    print("\nspykeutils distance matrix:\n{0}\n\n".format(sutils_d))
    print("\npymuvr distance matrix:\n{0}\n\n".format(pymuvr_d))
    print("Time elapsed: pymuvr {0}s, spykeutils {1}s".format(
        pymuvr_stop - pymuvr_start, sutils_stop - sutils_start))
tau = 5.0 * pq.ms


def trains_as_multiunits(trains, trains_per_unit, num_units):
    units = {}
    for i in xrange(num_units):
        units[i] = trains[i * trains_per_unit:(i + 1) * trains_per_unit]
    return units


metrics = {
    'vp': (r'$D_{\mathrm{V}}$ (multi-unit)',
           lambda units: stm.victor_purpura_multiunit_dist(
               units, 0.7, 2.0 / tau)),
    'vr': (r'$D_{\mathrm{R}}$ (multi-unit)',
           lambda units: stm.van_rossum_multiunit_dist(units, 0.5, tau))}


def print_available_metrics():
    for key in metrics:
        print "%s  (%s)" % (key, metrics[key][0])


class BenchmarkData(object):
    def __init__(
            self, spike_count_range, train_count_range, num_units_range,
            firing_rate=50 * pq.Hz):
        self.spike_count_range = spike_count_range
        self.train_count_range = train_count_range
        self.num_units_range = num_units_range
        self.num_trains_per_spike_count = \
 def calc_metric(self, trains):
     return stm.van_rossum_multiunit_dist({0: trains}, 1)
    'es': ('event synchronization',
           lambda trains: stm.event_synchronization(trains, tau, sort=False)),
    'hm': ('Hunter-Milton similarity measure',
           lambda trains: stm.hunter_milton_similarity(trains, tau)),
    'norm': ('norm distance',
             lambda trains: stm.norm_dist(
                 trains, sigproc.CausalDecayingExpKernel(tau), sampling_rate)),
    'ss': ('Schreiber et al. similarity measure',
           lambda trains: stm.schreiber_similarity(
               trains, sigproc.GaussianKernel(tau), sort=False)),
    'vr': ('van Rossum distance',
           lambda trains: stm.van_rossum_dist(trains, tau, sort=False)),
    'vp': ('Victor-Purpura\'s distance',
           lambda trains: stm.victor_purpura_dist(trains, 2.0 / tau)),
    'vr_mu': ('van Rossum multi-unit distance',
              lambda trains: stm.van_rossum_multiunit_dist(
                  trains_as_multiunits(trains), 0.5, tau)),
    'vp_mu': ('Victor-Purpura\'s multi-unit distance',
              lambda trains: stm.victor_purpura_multiunit_dist(
                  trains_as_multiunits(trains), 0.3, 2.0 / tau))}


def print_available_metrics():
    for key in metrics:
        print "%s  (%s)" % (key, metrics[key][0])


def print_summary(profile_file):
    stats = pstats.Stats(profile_file)
    stats.strip_dirs().sort_stats('cumulative').print_stats(
        r'^spike_train_metrics.py:\d+\([^_<].*(?<!compute)\)')