def test_spike_directionality(): st1 = SpikeTrain([100, 200, 300], [0, 1000]) st2 = SpikeTrain([105, 205, 300], [0, 1000]) assert_almost_equal(spk.spike_directionality(st1, st2), 2.0/3.0) assert_almost_equal(spk.spike_directionality(st1, st2, normalize=False), 2.0) # exchange order of spike trains should give exact negative profile assert_almost_equal(spk.spike_directionality(st2, st1), -2.0/3.0) assert_almost_equal(spk.spike_directionality(st2, st1, normalize=False), -2.0) st3 = SpikeTrain([105, 195, 500], [0, 1000]) assert_almost_equal(spk.spike_directionality(st1, st3), 0.0) assert_almost_equal(spk.spike_directionality(st1, st3, normalize=False), 0.0) assert_almost_equal(spk.spike_directionality(st3, st1), 0.0) D = spk.spike_directionality_matrix([st1, st2, st3], normalize=False) D_expected = np.array([[0, 2.0, 0.0], [-2.0, 0.0, -1.0], [0.0, 1.0, 0.0]]) assert_array_equal(D, D_expected) dir_profs = spk.spike_directionality_values([st1, st2, st3]) assert_array_equal(dir_profs[0], [1.0, 0.0, 0.0]) assert_array_equal(dir_profs[1], [-0.5, -1.0, 0.0])
spike_profile = spk.spike_profile(spike_trains[0], spike_trains[1]) x, y = spike_profile.get_plottable_data() plt.plot(x, y, '--k') print("SPIKE distance: %.8f" % spike_profile.avrg()) plt.show() import numpy as np from matplotlib import pyplot as plt import pyspike as spk st1 = spk.generate_poisson_spikes(1.0, [0, 20]) st2 = spk.generate_poisson_spikes(1.0, [0, 20]) d = spk.spike_directionality(st1, st2) #print "Spike Directionality of two Poissonian spike trains:", d E = spk.spike_train_order_profile(st1, st2) plt.figure() x, y = E.get_plottable_data() plt.plot(x, y, '-ob') plt.ylim(-1.1, 1.1) plt.xlabel("t") plt.ylabel("E") plt.title("Spike Train Order Profile") plt.show()