summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/PySpike_testdata.txt43
-rw-r--r--examples/averages.py59
-rw-r--r--examples/distance_matrix.py38
-rw-r--r--examples/merge.py29
-rw-r--r--examples/multivariate.py51
-rw-r--r--examples/performance.py71
-rw-r--r--examples/plot.py45
-rw-r--r--examples/profiles.py66
-rw-r--r--examples/spike_sync.py50
-rw-r--r--examples/spike_train_order.py52
10 files changed, 504 insertions, 0 deletions
diff --git a/examples/PySpike_testdata.txt b/examples/PySpike_testdata.txt
new file mode 100644
index 0000000..41b2362
--- /dev/null
+++ b/examples/PySpike_testdata.txt
@@ -0,0 +1,43 @@
+# PySpike exemplary spike trains
+# lines starting with # are ignored, just like empty lines
+
+64.886 305.81 696 937.77 1059.7 1322.2 1576.1 1808.1 2121.5 2381.1 2728.6 2966.9 3223.7 3473.7 3644.3 3936.3
+65.553 307.49 696.63 948.66 1070.4 1312.2 1712.7 1934.3 2117.6 2356.9 2727.3 2980.6 3226.9 3475.7 3726.4 3944
+69.064 319.1 688.32 947.85 1071.8 1300.8 1697.2 1930.6 2139.4 2354.2 2723.7 2963.6 3221.3 3470.1
+59.955 313.83 692.23 955.95 1070.4 1319.6 1681.9 1963.5 2151.4 2373.8 2729.4 2971.2 3220.2 3475.5 3632.3 3788.9
+59.977 306.84 686.09 935.08 1059.9 1325.9 1543.4 1821.9 2150.2 2390.4 2724.5 2969.6 3222.5 3471.5 3576 3913.9
+66.415 313.41 688.83 931.43 1051.8 1304.6 1555.6 1820.2 2150.5 2383.1 2723.4 2947.7 3196.6 3443.5 3575 3804.9
+66.449 311.02 689.26 947.12 1058.9 1286.6 1708.2 1957.3 2124.8 2375.7 2709.4 2977.6 3191.1 3449.6 3590.4 3831.2
+63.764 318.45 697.48 936.97 1059.3 1325 1687.9 1944.7 2132.5 2377.1 2713.1 2976.6 3196.8 3442.6 3741.6 3998.3
+63.906 314.79 693.26 937.12 1065.9 1315.8 1584.3 1821.5 2126.3 2396.8 2709.1 2967 3197.4 3444 3732.8 3849.5
+69.493 316.62 689.81 943.62 1071.9 1296.3 1654.8 1931.9 2127.5 2390.6 2708.9 2950.4 3194.8 3445.2 3670.1 3903.3
+61.789 317.53 555.82 813.15 1198.7 1448.7 1686.7 1943.5 2060.7 2311.4 2658.2 2900.2 3167.4 3418.2 3617.3 3771
+64.098 309.86 567.27 813.91 1182 1464.3 1576.8 1822.5 2063.1 2311.7 2655.8 2911.7 3168.3 3418.2 3586.4 3999.7
+68.59 315.5 559.52 806.23 1182.5 1441.1 1567.2 1804.8 2074.9 2315.8 2655.1 2913.2 3165.9 3419.5 3648.1 3884.4
+66.507 314.42 556.42 814.83 1182.5 1440.3 1701.3 1911.1 2069.7 2319.3 2662.3 2903.2 3167.4 3418.5 3545 3893.9
+72.744 318.45 554.4 819.64 1186.9 1449.7 1676 1957.4 2051.4 2302.8 2657.8 2916.2 3169.4 3416.7 3570.4 3884.8
+64.779 324.42 560.56 828.99 1174.8 1439.9 1563.7 1790.6 2067.7 2287.6 2657.4 2905.2 3139.2 3389.1 3507.8 3807.5
+64.852 316.63 568.89 815.61 1198.3 1454.1 1710.6 1933.9 2091.5 2309.6 2660.9 2907.5 3137.2 3389.3 3617.2
+63.089 314.52 553.8 827.06 1183.9 1457.6 1558.9 1808.3 2064.5 2337.1 2653.6 2897 3143.7 3385.7 3668.7 3803.8
+62.23 315.16 564.35 812.15 1199.6 1448.9 1562.7 1839.1 2069.7 2308.9 2649.6 2919.7 3141 3389.9 3723.6 3882.2
+69.662 311.93 564.91 805.25 1209.7 1451.4 1691.9 1932.1 2044.2 2329.4 2657.1 2908.5 3142.8 3390.5 3597.3 3991.1
+183.42 431.34 562.41 809.57 1086.3 1308.9 1555.9 1831.3 2057 2326.9 2591.3 2831.4 3113.9 3367.9 3555.3 3956
+188.49 442.39 572.4 810.76 1065 1326.7 1564.3 1803.4 2060.4 2322.4 2607.2 2824.1 3110.2 3363.9 3644.1 3819.6
+177 437.76 569.82 819.66 1064.1 1309.2 1685.7 1957.5 2066.9 2313.8 2593.2 2847 3116.8 3364.5 3727.3 3881.6
+193.9 441.93 586.9 804.98 1062.5 1312.4 1542.4 1793.1 2073.9 2314.7 2587.8 2845.9 3112.4 3359.8
+193.01 440.26 555.64 814.08 1056.3 1315 1689.9 1961.4 2049.1 2305 2593.9 2847.5 3110.6 3361.1 3711.6 3914.7
+194.71 437.57 566.18 806.73 1069.2 1314.6 1682.7 1942.2 2061.8 2304.6 2607.6 2841.7 3082.9 3330.3 3679.7 3848.2
+184.88 441.22 570.92 794.35 1063.7 1309.9 1678.7 1930 2058 2321.3 2606.7 2845 3084.8 3337.3 3640 3952.1
+189.66 443.59 560.67 816.89 1070.4 1303.4 1550.1 1815.5 2057.6 2323.7 2587.1 2843.5 3086.6 3333.6 3618.2 3815.4
+190.41 440.77 568.96 808.56 1073.8 1322.1 1686.5 1952.8 2068.7 2335.7 2595.7 2845.4 3086 3333.5 3635.6 3939.3
+181.16 440.67 577.54 823.52 1052.5 1322.3 1578.4 1822.2 2079.4 2309.1 2596.9 2851.9 3083.5 3335.1 3531.2 3770.6
+181.09 434.97 687.15 943.33 1192.9 1444 1699.4 1942 2194.6 2445.9 2549.4 2785.1 3056.5 3308.2 3620.5 3932.7
+186.7 446.53 688.18 942.86 1186.1 1441.9 1688.1 1922.2 2196.6 2455.3 2534.8 2776.5 3060.3 3309.4 3514.1 3808.6
+196.76 446 681.26 948.27 1195.8 1433.1 1699 1933 2201.2 2461.4 2547.4 2777.8 3055.7 3307.1 3590.6 3952.8
+200.68 427.11 695.67 946.42 1178.6 1440.1 1538.4 1809 2199.8 2432.5 2531.6 2793.2 3056.6 3308.6 3510.6 3928.1
+190.83 429.57 698.73 931.16 1190.6 1428.9 1698.3 1935 2176.8 2424.7 2530.5 2766.9 3062 3309.7 3689.8
+181.47 441.93 682.32 943.01 1190.1 1459.1 1570.6 1819.6 2189.8 2437.9 2543.3 2782.8 3025.9 3280.2 3581 3855.9
+191.38 435.69 702.76 935.62 1188.3 1438.3 1564.2 1823.9 2191.3 2444.9 2531.9 2782.4 3030.7 3275.7 3677.7 3829.2
+191.97 433.85 686.29 932.65 1183.1 1432.7 1563.9 1826.5 2214.1 2436.8 2529.8 2778.3 3028.3 3281.8 3582 3863.4
+189.51 453.21 691.3 940.86 1180.1 1430.1 1567.1 1835 2199 2448.2 2526.7 2773.8 3030.5 3280.1 3576.2 3893.6
+190.88 435.48 692.66 940.51 1189.5 1448.9 1575.1 1824.2 2190.8 2425.9 2530.6 2783.3 3033.3 3279.5 3733 3838.9
diff --git a/examples/averages.py b/examples/averages.py
new file mode 100644
index 0000000..8b405d0
--- /dev/null
+++ b/examples/averages.py
@@ -0,0 +1,59 @@
+""" averages.py
+
+Simple example showing how to compute averages of distance profiles
+
+Copyright 2014, Mario Mulansky <mario.mulansky@gmx.net>
+
+Distributed under the BSD License
+"""
+
+from __future__ import print_function
+
+import pyspike as spk
+
+spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt",
+ edges=(0, 4000))
+
+f = spk.isi_profile(spike_trains[0], spike_trains[1])
+
+print("ISI-distance: %.8f" % f.avrg())
+
+isi1 = f.avrg(interval=(0, 1000))
+isi2 = f.avrg(interval=(1000, 2000))
+isi3 = f.avrg(interval=[(0, 1000), (2000, 3000)])
+isi4 = f.avrg(interval=[(1000, 2000), (3000, 4000)])
+
+print("ISI-distance (0-1000): %.8f" % isi1)
+print("ISI-distance (1000-2000): %.8f" % isi2)
+print("ISI-distance (0-1000) and (2000-3000): %.8f" % isi3)
+print("ISI-distance (1000-2000) and (3000-4000): %.8f" % isi4)
+print()
+
+f = spk.spike_profile(spike_trains[0], spike_trains[1])
+
+print("SPIKE-distance: %.8f" % f.avrg())
+
+spike1 = f.avrg(interval=(0, 1000))
+spike2 = f.avrg(interval=(1000, 2000))
+spike3 = f.avrg(interval=[(0, 1000), (2000, 3000)])
+spike4 = f.avrg(interval=[(1000, 2000), (3000, 4000)])
+
+print("SPIKE-distance (0-1000): %.8f" % spike1)
+print("SPIKE-distance (1000-2000): %.8f" % spike2)
+print("SPIKE-distance (0-1000) and (2000-3000): %.8f" % spike3)
+print("SPIKE-distance (1000-2000) and (3000-4000): %.8f" % spike4)
+print()
+
+f = spk.spike_sync_profile(spike_trains[0], spike_trains[1])
+
+print("SPIKE-Synchronization: %.8f" % f.avrg())
+
+spike_sync1 = f.avrg(interval=(0, 1000))
+spike_sync2 = f.avrg(interval=(1000, 2000))
+spike_sync3 = f.avrg(interval=[(0, 1000), (2000, 3000)])
+spike_sync4 = f.avrg(interval=[(1000, 2000), (3000, 4000)])
+
+print("SPIKE-Sync (0-1000): %.8f" % spike_sync1)
+print("SPIKE-Sync (1000-2000): %.8f" % spike_sync2)
+print("SPIKE-Sync (0-1000) and (2000-3000): %.8f" % spike_sync3)
+print("SPIKE-Sync (1000-2000) and (3000-4000): %.8f" % spike_sync4)
diff --git a/examples/distance_matrix.py b/examples/distance_matrix.py
new file mode 100644
index 0000000..0e4d825
--- /dev/null
+++ b/examples/distance_matrix.py
@@ -0,0 +1,38 @@
+""" distance_matrix.py
+
+Simple example showing how to compute the isi distance matrix of a set of spike
+trains.
+
+Copyright 2014, Mario Mulansky <mario.mulansky@gmx.net>
+
+Distributed under the BSD License
+"""
+
+
+from __future__ import print_function
+
+import matplotlib.pyplot as plt
+
+import pyspike as spk
+
+# first load the data, interval ending time = 4000, start=0 (default)
+spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt", 4000)
+
+print(len(spike_trains))
+
+plt.figure()
+isi_distance = spk.isi_distance_matrix(spike_trains)
+plt.imshow(isi_distance, interpolation='none')
+plt.title("ISI-distance")
+
+plt.figure()
+spike_distance = spk.spike_distance_matrix(spike_trains, interval=(0, 1000))
+plt.imshow(spike_distance, interpolation='none')
+plt.title("SPIKE-distance, T=0-1000")
+
+plt.figure()
+spike_sync = spk.spike_sync_matrix(spike_trains, interval=(2000, 4000))
+plt.imshow(spike_sync, interpolation='none')
+plt.title("SPIKE-Sync, T=2000-4000")
+
+plt.show()
diff --git a/examples/merge.py b/examples/merge.py
new file mode 100644
index 0000000..b4437a3
--- /dev/null
+++ b/examples/merge.py
@@ -0,0 +1,29 @@
+""" merge.py
+
+Simple example showing the merging of two spike trains.
+
+Copyright 2014, Mario Mulansky <mario.mulansky@gmx.net>
+
+Distributed under the BSD License
+"""
+
+from __future__ import print_function
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+import pyspike as spk
+
+# first load the data, ending time = 4000
+spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt", 4000)
+
+merged_spike_train = spk.merge_spike_trains([spike_trains[0], spike_trains[1]])
+
+print(merged_spike_train.spikes)
+
+plt.plot(spike_trains[0], np.ones_like(spike_trains[0]), 'o')
+plt.plot(spike_trains[1], np.ones_like(spike_trains[1]), 'x')
+plt.plot(merged_spike_train.spikes,
+ 2*np.ones_like(merged_spike_train), 'o')
+
+plt.show()
diff --git a/examples/multivariate.py b/examples/multivariate.py
new file mode 100644
index 0000000..e9579a5
--- /dev/null
+++ b/examples/multivariate.py
@@ -0,0 +1,51 @@
+""" Example for the multivariate spike distance
+
+Copyright 2014, Mario Mulansky <mario.mulansky@gmx.net>
+
+"""
+from __future__ import print_function
+import time
+import pyspike as spk
+
+
+def time_diff_in_ms(start, end):
+ """ Returns the time difference end-start in ms.
+ """
+ return (end-start)*1000
+
+
+t_start = time.clock()
+
+# load the data
+time_loading = time.clock()
+spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt",
+ edges=(0, 4000))
+t_loading = time.clock()
+
+print("Number of spike trains: %d" % len(spike_trains))
+num_of_spikes = sum([len(spike_trains[i])
+ for i in range(len(spike_trains))])
+print("Number of spikes: %d" % num_of_spikes)
+
+# calculate the multivariate spike distance
+f = spk.spike_profile(spike_trains)
+
+t_spike = time.clock()
+
+# print the average
+avrg = f.avrg()
+print("Spike distance from average: %.8f" % avrg)
+
+t_avrg = time.clock()
+
+# compute average distance directly, should give the same result as above
+spike_dist = spk.spike_distance(spike_trains)
+print("Spike distance directly: %.8f" % spike_dist)
+
+t_dist = time.clock()
+
+print("Loading: %9.1f ms" % time_diff_in_ms(t_start, t_loading))
+print("Computing profile: %9.1f ms" % time_diff_in_ms(t_loading, t_spike))
+print("Averaging: %9.1f ms" % time_diff_in_ms(t_spike, t_avrg))
+print("Computing distance: %9.1f ms" % time_diff_in_ms(t_avrg, t_dist))
+print("Total: %9.1f ms" % time_diff_in_ms(t_start, t_dist))
diff --git a/examples/performance.py b/examples/performance.py
new file mode 100644
index 0000000..30691f8
--- /dev/null
+++ b/examples/performance.py
@@ -0,0 +1,71 @@
+"""
+Compute distances of large sets of spike trains for performance tests
+
+Copyright 2015, Mario Mulansky <mario.mulansky@gmx.net>
+
+Distributed under the BSD License
+
+"""
+
+from __future__ import print_function
+
+import pyspike as spk
+from datetime import datetime
+import cProfile
+import pstats
+
+# in case you dont have the cython backends, disable the warnings as follows:
+# spk.disable_backend_warning = True
+
+M = 100 # number of spike trains
+r = 1.0 # rate of Poisson spike times
+T = 1E3 # length of spike trains
+
+print("%d spike trains with %d spikes" % (M, int(r*T)))
+
+spike_trains = []
+
+t_start = datetime.now()
+for i in range(M):
+ spike_trains.append(spk.generate_poisson_spikes(r, T))
+t_end = datetime.now()
+runtime = (t_end-t_start).total_seconds()
+
+sort_by = 'tottime'
+# sort_by = 'cumtime'
+
+print("Spike generation runtime: %.3fs" % runtime)
+print()
+
+print("================ ISI COMPUTATIONS ================")
+print(" MULTIVARIATE DISTANCE")
+cProfile.run('spk.isi_distance(spike_trains)', 'performance.stat')
+p = pstats.Stats('performance.stat')
+p.strip_dirs().sort_stats(sort_by).print_stats(5)
+
+print(" MULTIVARIATE PROFILE")
+cProfile.run('spk.isi_profile(spike_trains)', 'performance.stat')
+p = pstats.Stats('performance.stat')
+p.strip_dirs().sort_stats(sort_by).print_stats(5)
+
+print("================ SPIKE COMPUTATIONS ================")
+print(" MULTIVARIATE DISTANCE")
+cProfile.run('spk.spike_distance(spike_trains)', 'performance.stat')
+p = pstats.Stats('performance.stat')
+p.strip_dirs().sort_stats(sort_by).print_stats(5)
+
+print(" MULTIVARIATE PROFILE")
+cProfile.run('spk.spike_profile(spike_trains)', 'performance.stat')
+p = pstats.Stats('performance.stat')
+p.strip_dirs().sort_stats(sort_by).print_stats(5)
+
+print("================ SPIKE-SYNC COMPUTATIONS ================")
+print(" MULTIVARIATE DISTANCE")
+cProfile.run('spk.spike_sync(spike_trains)', 'performance.stat')
+p = pstats.Stats('performance.stat')
+p.strip_dirs().sort_stats(sort_by).print_stats(5)
+
+print(" MULTIVARIATE PROFILE")
+cProfile.run('spk.spike_sync_profile(spike_trains)', 'performance.stat')
+p = pstats.Stats('performance.stat')
+p.strip_dirs().sort_stats(sort_by).print_stats(5)
diff --git a/examples/plot.py b/examples/plot.py
new file mode 100644
index 0000000..a0e04da
--- /dev/null
+++ b/examples/plot.py
@@ -0,0 +1,45 @@
+""" plot.py
+
+Simple example showing how to load and plot spike trains and their distance
+profiles.
+
+Copyright 2014, Mario Mulansky <mario.mulansky@gmx.net>
+
+Distributed under the BSD License
+"""
+
+
+from __future__ import print_function
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+import pyspike as spk
+
+
+spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt",
+ edges=(0, 4000))
+
+# plot the spike times
+for (i, spike_train) in enumerate(spike_trains):
+ plt.scatter(spike_train, i*np.ones_like(spike_train), marker='|')
+
+# profile of the first two spike trains
+f = spk.isi_profile(spike_trains, indices=[0, 1])
+x, y = f.get_plottable_data()
+
+plt.figure()
+plt.plot(x, np.abs(y), '--k', label="ISI-profile")
+
+print("ISI-distance: %.8f" % f.avrg())
+
+f = spk.spike_profile(spike_trains, indices=[0, 1])
+x, y = f.get_plottable_data()
+
+plt.plot(x, y, '-b', label="SPIKE-profile")
+
+print("SPIKE-distance: %.8f" % f.avrg())
+
+plt.legend(loc="upper left")
+
+plt.show()
diff --git a/examples/profiles.py b/examples/profiles.py
new file mode 100644
index 0000000..8412ffb
--- /dev/null
+++ b/examples/profiles.py
@@ -0,0 +1,66 @@
+""" profiles.py
+
+Simple example showing some functionality of distance profiles.
+
+Copyright 2015, Mario Mulansky <mario.mulansky@gmx.net>
+
+Distributed under the BSD License
+"""
+
+
+from __future__ import print_function
+
+import pyspike as spk
+
+spike_trains = spk.load_spike_trains_from_txt("PySpike_testdata.txt",
+ edges=(0, 4000))
+
+##### ISI PROFILES #######
+
+# compute the ISI profile of the first two spike trains
+f = spk.isi_profile(spike_trains[0], spike_trains[1])
+
+# ISI values at certain points
+t = 1200
+print("ISI value at t =", t, ":", f(t))
+t = [900, 1100, 2000, 3100]
+print("ISI value at t =", t, ":", f(t))
+print("Average ISI distance:", f.avrg())
+print()
+
+# compute the multivariate ISI profile
+f = spk.isi_profile(spike_trains)
+
+t = 1200
+print("Multivariate ISI value at t =", t, ":", f(t))
+t = [900, 1100, 2000, 3100]
+print("Multivariate ISI value at t =", t, ":", f(t))
+print("Average multivariate ISI distance:", f.avrg())
+print()
+print()
+
+# for plotting, use the get_plottable_data() member function, see plot.py
+
+
+##### SPIKE PROFILES #######
+
+# compute the SPIKE profile of the first two spike trains
+f = spk.spike_profile(spike_trains[0], spike_trains[1])
+
+# SPIKE distance values at certain points
+t = 1200
+print("SPIKE value at t =", t, ":", f(t))
+t = [900, 1100, 2000, 3100]
+print("SPIKE value at t =", t, ":", f(t))
+print("Average SPIKE distance:", f.avrg())
+print()
+
+# compute the multivariate SPIKE profile
+f = spk.spike_profile(spike_trains)
+
+# SPIKE values at certain points
+t = 1200
+print("Multivariate SPIKE value at t =", t, ":", f(t))
+t = [900, 1100, 2000, 3100]
+print("Multivariate SPIKE value at t =", t, ":", f(t))
+print("Average multivariate SPIKE distance:", f.avrg())
diff --git a/examples/spike_sync.py b/examples/spike_sync.py
new file mode 100644
index 0000000..13ca0ce
--- /dev/null
+++ b/examples/spike_sync.py
@@ -0,0 +1,50 @@
+from __future__ import print_function
+
+import matplotlib.pyplot as plt
+
+import pyspike as spk
+
+spike_trains = spk.load_spike_trains_from_txt("../test/SPIKE_Sync_Test.txt",
+ edges=(0, 4000))
+
+plt.figure()
+
+f = spk.spike_sync_profile(spike_trains[0], spike_trains[1])
+x, y = f.get_plottable_data()
+plt.plot(x, y, '--ok', label="SPIKE-SYNC profile")
+print(f.x)
+print(f.y)
+print(f.mp)
+
+print("Average:", f.avrg())
+
+
+f = spk.spike_profile(spike_trains[0], spike_trains[1])
+x, y = f.get_plottable_data()
+
+plt.plot(x, y, '-b', label="SPIKE-profile")
+
+plt.axis([0, 4000, -0.1, 1.1])
+plt.legend(loc="center right")
+
+plt.figure()
+
+plt.subplot(211)
+
+f = spk.spike_sync_profile(spike_trains)
+x, y = f.get_plottable_data()
+plt.plot(x, y, '-b', alpha=0.7, label="SPIKE-Sync profile")
+
+x1, y1 = f.get_plottable_data(averaging_window_size=50)
+plt.plot(x1, y1, '-k', lw=2.5, label="averaged SPIKE-Sync profile")
+
+plt.subplot(212)
+
+f_psth = spk.psth(spike_trains, bin_size=50.0)
+x, y = f_psth.get_plottable_data()
+plt.plot(x, y, '-k', alpha=1.0, label="PSTH")
+
+
+print("Average:", f.avrg())
+
+plt.show()
diff --git a/examples/spike_train_order.py b/examples/spike_train_order.py
new file mode 100644
index 0000000..3a42472
--- /dev/null
+++ b/examples/spike_train_order.py
@@ -0,0 +1,52 @@
+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")
+
+
+###### Optimize spike train order of 20 Random spike trains #######
+
+M = 20
+
+spike_trains = [spk.generate_poisson_spikes(1.0, [0, 100]) for m in xrange(M)]
+
+F_init = spk.spike_train_order(spike_trains)
+
+print "Initial Synfire Indicator for 20 Poissonian spike trains:", F_init
+
+D_init = spk.spike_directionality_matrix(spike_trains)
+
+phi, _ = spk.optimal_spike_train_sorting(spike_trains)
+
+F_opt = spk.spike_train_order(spike_trains, indices=phi)
+
+print "Synfire Indicator of optimized spike train sorting:", F_opt
+
+D_opt = spk.permutate_matrix(D_init, phi)
+
+plt.figure()
+plt.imshow(D_init)
+plt.title("Initial Directionality Matrix")
+
+plt.figure()
+plt.imshow(D_opt)
+plt.title("Optimized Directionality Matrix")
+
+plt.show()