-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFHNmodel_PhaseField.py
90 lines (74 loc) · 1.91 KB
/
FHNmodel_PhaseField.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 24 07:59:41 2018
@author: user
"""
#https://www.math.auckland.ac.nz/~hinke/preprints/lko_puzzle.pdf
#http://www.k.mei.titech.ac.jp/members/nakao/Etc/phasereduction-iscie.pdf
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.integrate as integrate
from tqdm import tqdm
I = 0.34 #external stimulus
a = 0.7
b = 0.8
c = 10
# beginning point
u0 = 1.710
v0 = 0.374
X0 = [u0, v0]
#time
dt = 0.001
idt = 1/dt
t = np.arange(0, 40, dt)
T = 4095 #msec
def FHN(state, t):
"""
FitzHugh-Nagumo added pulse perturbation model
u : the membrane potential
v : a recovery variable
"""
u, v = state
dudt = c * (-v + u - pow(u,3)/3 + I)
dvdt = u - b * v + a
return dudt, dvdt
def PhaseField(u,v):
#軌道を計算
Xp = integrate.odeint(FHN, [u,v], t)
#軌道中の点と原点の距離を計算
d = Xp-X0
L2 = d[:,0]**2 + d[:,1]**2
#軌道中の点で最も原点に近い最初の点のindex(=time)を取得
tau_0 = np.argmin(L2)
#周期で割って余りを出す
tau = tau_0 % T
#位相を2piで割った値
theta_per_2pi = 1 - tau / T
#Phase
#theta = theta_per_2pi * 2*np.pi
return theta_per_2pi
ds = 0.01
U, V = np.meshgrid(np.arange(-3, 3, ds),
np.arange(2, -1, -ds))
ulen, vlen = U.shape
arr_PhaseField = np.zeros((ulen,vlen))
#Compute Phase
pbar = tqdm(total=ulen*vlen)
for i in range (ulen):
for j in range(vlen):
u = U[i,j]
v = V[i,j]
arr_PhaseField[i,j] = PhaseField(u,v)
pbar.update(1)
pbar.close()
# Show heatmap
plt.figure(figsize=(5,5))
sns.heatmap(arr_PhaseField, cmap = "hsv",
xticklabels = False, yticklabels = False,
cbar = False)
plt.xlabel("u : membrane potential")
plt.ylabel("v : recovery variable")
plt.title("FitzHugh-Nagumo Phase Field")
plt.savefig('FHN_PhaseField.png')
plt.show()