本篇文章主要核心目的在于研究明白HH神經元的數學模型,并且驗證其正確性。因此,在本篇文章中只會使用numpy函數庫用于構建神經元,以及matplotlib用于繪圖。
1.導入對應的庫
import numpy as np
import matplotlib.pyplot as plt
import re
import os
2.建立神經元的類別
HH神經元的數學模型如下所示:
對應的示例代碼如下:
class HHNeuron:def __init__(self, name, V_Neuron, G_Synapsis_Excitatory, G_Synapsis_Inhibitory, E_Excitatory, E_Inhibitory, E_local, G_local, V_Excitatory_Threshold,C_Membrane, tau_Synapsis,V_Reset_Threshold, V_Reset,I_Synapsis, T_refractory, T_rest,Connecting_Neuron, Q_Synapsis, Probability_Connecting,G_Synapsis_K, G_Synapsis_Na, E_K, E_Na,n_coefficient, m_coefficient, h_coefficient):# variable parametersself.name = nameself.V_Neuron = V_Neuronself.G_Synapsis_Excitatory = G_Synapsis_Excitatoryself.G_Synapsis_Inhibitory = G_Synapsis_Inhibitory# fixed parametersself.E_Excitatory = E_Excitatoryself.E_Inhibitory = E_Inhibitoryself.E_local = E_localself.G_local = G_localself.V_Excitatory_Threshold = V_Excitatory_Thresholdself.C_Membrane = C_Membraneself.T_refractory = T_refractory# adaptive parametersself.tau_Synapsis = tau_Synapsis# reset parametersself.V_Reset_Threshold = V_Reset_Thresholdself.V_Reset = V_Resetself.I_Synapsis = I_Synapsisself.T_rest = T_rest# connecting neuronsself.Connecting_Neuron = Connecting_Neuronself.Q_Synapsis = Q_Synapsisself.Probability_Connecting = Probability_Connecting# HH model parametersself.G_Synapsis_K = G_Synapsis_Kself.G_Synapsis_Na = G_Synapsis_Naself.E_K = E_Kself.E_Na = E_Naself.n_coefficient = n_coefficientself.m_coefficient = m_coefficientself.h_coefficient = h_coefficientdef refresh_membrane_potential(self):if self.T_rest<=0:self.V_Neuron =self.V_Neuron+dt*(self.G_Synapsis_Excitatory*(self.E_Excitatory-self.V_Neuron)+self.G_Synapsis_Inhibitory*(self.E_Inhibitory-self.V_Neuron)+self.G_local*(self.E_local-self.V_Neuron)+self.G_Synapsis_K*self.n_coefficient*self.n_coefficient*self.n_coefficient*self.n_coefficient*(self.E_K-self.V_Neuron)+self.G_Synapsis_Na*self.m_coefficient*self.m_coefficient*self.m_coefficient*self.h_coefficient*(self.E_Na-self.V_Neuron)+self.I_Synapsis)/self.C_Membraneelse:self.T_rest=self.T_rest-dtdef refresh_G_Synapsis_Excitatory(self):self.G_Synapsis_Excitatory = self.G_Synapsis_Excitatory-dt*self.G_Synapsis_Excitatory/self.tau_Synapsisdef refresh_G_Synapsis_Inhibitory(self):self.G_Synapsis_Inhibitory = self.G_Synapsis_Inhibitory-dt*self.G_Synapsis_Inhibitory/self.tau_Synapsisdef refresh_n_coefficient(self):self.n_coefficient = self.n_coefficient+dt*(0.032/mV*(15*mV-self.V_Neuron+self.V_Excitatory_Threshold)/(np.exp((15*mV-self.V_Neuron+self.V_Excitatory_Threshold)/5/mV)-1)*(1-self.n_coefficient)/ms-0.5*np.exp((10*mV-self.V_Neuron+self.V_Excitatory_Threshold)/40/mV)*self.n_coefficient/ms)def refresh_h_coefficient(self):self.h_coefficient = self.h_coefficient+dt*(0.128*np.exp((17*mV-self.V_Neuron+self.V_Excitatory_Threshold)/18/mV)*(1-self.h_coefficient)/ms-4/(1+np.exp((40*mV-self.V_Neuron+self.V_Excitatory_Threshold)/5/mV))*self.h_coefficient/ms)def refresh_m_coefficient(self):self.m_coefficient = self.m_coefficient+dt*(0.32/mV*(13*mV-self.V_Neuron+self.V_Excitatory_Threshold)/(np.exp((13*mV-self.V_Neuron+self.V_Excitatory_Threshold)/4/mV)-1)*(1-self.m_coefficient)/ms-0.28/mV*(self.V_Neuron-self.V_Excitatory_Threshold-40*mV)/(np.exp((self.V_Neuron-self.V_Excitatory_Threshold-40*mV)/5/mV)-1)*self.m_coefficient/ms)def fire(self, num1, num2):global fire_matrix# refresh self parameter# print(self.name)self.V_Neuron = self.V_Resetself.T_rest=self.T_refractoryif self.name[1]=='1':num1=num1+1fire_matrix1[extract_number_from_string(self.name)-1,test_input_index]=2for neuron1 in self.Connecting_Neuron:neuron1.G_Synapsis_Inhibitory=neuron1.G_Synapsis_Inhibitory+self.Q_Synapsisif self.name[1]=='2':num2=num2+1fire_matrix2[extract_number_from_string(self.name)-1,test_input_index]=2for neuron2 in self.Connecting_Neuron:neuron2.G_Synapsis_Excitatory=neuron2.G_Synapsis_Excitatory+self.Q_Synapsisreturn num1, num2def judge_fire(self, num1, num2):if self.V_Neuron>self.V_Reset_Threshold:print(self.V_Neuron)num1, num2=self.fire(num1, num2)else:passreturn num1, num2def Add_Synapsis(self, Synapsis):self.Connecting_Neuron.append(Synapsis)
3.建立直流激勵源進行仿真
for tick_time in time_sim:FS_HH_neuron.refresh_membrane_potential()single_membrane_potential.append(FS_HH_neuron.V_Neuron)FS_HH_neuron.refresh_G_Synapsis_Excitatory()FS_HH_neuron.refresh_G_Synapsis_Inhibitory()FS_HH_neuron.refresh_n_coefficient()FS_HH_neuron.refresh_h_coefficient()FS_HH_neuron.refresh_m_coefficient()FS_HH_neuron.judge_fire(0,0)
4.仿真結果
n參數:
m參數:
h參數:
?膜電位: