-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathplot_recurrence.py
executable file
·45 lines (37 loc) · 1.08 KB
/
plot_recurrence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
# coding: UTF-8
from __future__ import division, print_function
import numpy as np
import pylab as plt
from scipy.spatial.distance import pdist, squareform
def rec_plot(s, eps=0.10, steps=10):
d = pdist(s[:,None])
d = np.floor(d/eps)
d[d>steps] = steps
Z = squareform(d)
return Z
def moving_average(s, r=5):
return np.convolve(s, np.ones((r,))/r, mode='valid')
if __name__ == "__main__":
# Generate singal
N = 200
eps = 0.1
steps = 10
# Plot unifrom dist filtered with moving average
ru = np.random.uniform(low=-1, high=1, size=N)
ru_filtered = moving_average(ru)
plt.title("Normal")
plt.subplot(221)
plt.plot(ru_filtered)
plt.title("Unitary")
plt.subplot(223)
plt.imshow(rec_plot(ru_filtered, eps=eps, steps=steps))
# Plot normal dist filtered with moving average
rn = np.random.normal(size=N)
rn_filtered = moving_average(rn)
plt.subplot(222)
plt.plot(rn_filtered)
plt.title("Normal")
plt.subplot(224)
plt.imshow(rec_plot(rn_filtered, eps=eps, steps=steps))
plt.show()