Пример #1
0
def test_spike_train_order():
    st1 = SpikeTrain([100, 200, 300], [0, 1000])
    st2 = SpikeTrain([105, 205, 300], [0, 1000])
    st3 = SpikeTrain([105, 195, 500], [0, 1000])

    expected_x12 = np.array([0, 100, 105, 200, 205, 300, 1000])
    expected_y12 = np.array([1, 1, 1, 1, 1, 0, 0])
    expected_mp12 = np.array([1, 1, 1, 1, 1, 2, 2])

    f = spk.spike_train_order_profile(st1, st2)

    assert f.almost_equal(DiscreteFunc(expected_x12, expected_y12,
                                       expected_mp12))
    assert_almost_equal(f.avrg(), 2.0/3.0)
    assert_almost_equal(f.avrg(normalize=False), 4.0)
    assert_almost_equal(spk.spike_train_order(st1, st2), 2.0/3.0)
    assert_almost_equal(spk.spike_train_order(st1, st2, normalize=False), 4.0)

    expected_x23 = np.array([0, 105, 195, 205, 300, 500, 1000])
    expected_y23 = np.array([0, 0, -1, -1, 0, 0, 0])
    expected_mp23 = np.array([2, 2, 1, 1, 1, 1, 1])

    f = spk.spike_train_order_profile(st2, st3)

    assert_array_equal(f.x, expected_x23)
    assert_array_equal(f.y, expected_y23)
    assert_array_equal(f.mp, expected_mp23)
    assert f.almost_equal(DiscreteFunc(expected_x23, expected_y23,
                                       expected_mp23))
    assert_almost_equal(f.avrg(), -1.0/3.0)
    assert_almost_equal(f.avrg(normalize=False), -2.0)
    assert_almost_equal(spk.spike_train_order(st2, st3), -1.0/3.0)
    assert_almost_equal(spk.spike_train_order(st2, st3, normalize=False), -2.0)

    f = spk.spike_train_order_profile_multi([st1, st2, st3])

    expected_x = np.array([0, 100, 105, 195, 200, 205, 300, 500, 1000])
    expected_y = np.array([2, 2, 2, -2, 0, 0, 0, 0, 0])
    expected_mp = np.array([2, 2, 4, 2, 2, 2, 4, 2, 2])

    assert_array_equal(f.x, expected_x)
    assert_array_equal(f.y, expected_y)
    assert_array_equal(f.mp, expected_mp)

    # Averaging the profile should be the same as computing the synfire indicator directly.
    assert_almost_equal(f.avrg(), spk.spike_train_order([st1, st2, st3]))

    # We can also compute the synfire indicator from the Directionality Matrix:
    D_matrix = spk.spike_directionality_matrix([st1, st2, st3], normalize=False)
    num_spikes = np.sum(len(st) for st in [st1, st2, st3])
    syn_fire = np.sum(np.triu(D_matrix)) / num_spikes
    assert_almost_equal(f.avrg(), syn_fire)
Пример #2
0
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()



#%% Michael
cd '/home/nel/Dropbox_old/toshare_slice/QPP4-1_slice1_FOV3/'