Brian到Brian2的转换
- 前言
- 简介:Changes for Brian1 users
- 关于物理单位:Physical units
- 没有导入的包:Unported pacakge
- 删除的类和函数以及在Brian2中的替代
- 关于神经元模型:Neural models
- 阈值和复位:Threshold & Reset:
- 不应期:Refractory
- 神经元子组:Subgroup
- 链接变量:Linked variables
- 关于突触:Synapse
- 声明突触和设置权重:Creating synapses and setting weights
- 权重矩阵和函数定义连接:Weights matrix & Connections defined by functions
- 延时:Delays
- 突触结构:Structure
- 和变量:Lumped variables (summed variables)
- 制作连接:Creating Synapses connection
- Multiple pathways
- 监测突触变量:Monitoring synaptic variables
- 未完不一定续
前言
官方英文链接:https://brian2.readthedocs.io/en/stable/introduction/changes.html
时间:2019年01月22日
系统:Ubuntu 16.04
架构:x86-64
简介:Changes for Brian1 users
Brian2与Brian1运行的方式基本相似,它们最大的不同就在于在Brian2中需要更加显示地定义模拟细节,从而避免不必要的错误:In most cases, Brian 2 works in a very similar way to Brian 1 but there are some important differences to be aware of. The major distinction is that in Brian 2 you need to be more explicit about the definition of your simulation in order to avoid inadvertent errors.
关于物理单位:Physical units
Brian2对物理单位的要求和检查更加严格,首先Brian2中增加了对数组单位的支持,然后为了一致性,单位会一直跟随带单位的数据。包括检测器(monitor)返回的状态变量也会带有单位。如果想要得到纯数据有三种方法:在变量后加“underscore”也就是“_”,例如“mon.t_”;除法,用带单位的数据除以单位,例如mon.t / second;用np.asarray()转换成数组。
没有导入的包:Unported pacakge
- brian.tools
- brian.hears (the Brian 1 version can be used via brian2.hears, though, see Brian Hears)
- brian.library.modelfitting
- brian.library.electrophysilogy
删除的类和函数以及在Brian2中的替代
Brian2尽可能地减少了类和函数的数量,但又努力增加足够的灵活性确保功能的丰富性。当从Brian1迁移到Brian2时遇到“NameError”可以考虑是否是模块被替换或删除了,可以查阅官方链接。
关于神经元模型:Neural models
阈值和复位:Threshold & Reset:
动作直接用公式代替。
不应期:Refractory
Brian1中的refractory是与reset紧密相关的,而且某些refractory与reset的组合是不被允许的,标准的refractory有两个作用,在refractory期间薄膜电压被钳制且不允许发射脉冲;在Brian2中refractory的发生不是与reset相关的,refractory的两个作用被分开使用,通过定义refractory的时间函数来定义细胞在某段时间内不得发射脉冲;第二个作用是除了薄膜电压其他细胞的变量也可以被钳制,只要在变量后加上“(unless refractory)”。
神经元子组:Subgroup
用数组的切片代替
链接变量:Linked variables
除了链接变量的声明语句,还需在需要在链接变量后说明。
group1 = NeuronGroup(N,
'dv/dt = -v / tau : volt')
group2 = NeuronGroup(N,
'''dv/dt = (-v + w) / tau : volt
w : volt (linked)''')
group2.w = linked_var(group1, 'v')
关于突触:Synapse
##Converting Brian 1’s Connection class
声明突触和设置权重:Creating synapses and setting weights
Brain2仅支持Synapses的突触定义方式,Brian1通常支持Connections的定义方式;Brian2中的连接关系定义和权重赋值是分开的。
conn1 = Synapses(source, target, 'w: siemens',
on_pre='ge += w')
conn1.connect(i=3, j=5)
conn1.w[3, 5] = 3*nS
权重矩阵和函数定义连接:Weights matrix & Connections defined by functions
Brian2中不再接受用矩阵来为权重赋值,提倡用数学表达式赋值,如果不得以要用矩阵就将矩阵展平进行赋值(展平的原则是前神经元的顺序(first all synapses for the first pre-synaptic cell, then all synapses for the second pre-synaptic cell, etc.))。
conn6 = Synapses(source, target, 'w: siemens',
on_pre='ge += w')
W = rand(20, 30)*nS
conn6.connect()
conn6.w = W.flatten()
conn6 =
conn6.connect()
conn6.w = 'random()'
另外,Brian2中连接和权值设定都是可以用字符串表达式来定制的,参考坐标是神经元的序号。
conn7 = Synapses(source, target, 'w: siemens',
on_pre='ge += w')
conn7.connect('i < 5 and j >=5 and j <10')
conn7.w[source[:5], target[5:10]] = 5*nS
conn8 = Synapses(source, target, 'w: siemens',
on_pre='ge += w')
conn8.connect()
conn8.w = '(1 + cos(i - j))*2*nS'
conn10 = ...
conn10.connect(p='exp(-abs(i - j)*.1)')
conn10.w = 2*nS
延时:Delays
Brian2中延时也可以用字符串表达式定义,默认是homogeneous,在Brian1中默认的也是homogeneous,但homogeneous和heterogeneous都需要声明“delay = True”以及延时最大值,Brain1中用两个数来定义随机分布已经不支持,转而使用字符串公式。
conn11 = Synapses(source, target, 'w : siemens',
on_pre='ge += w')
conn11.connect()
conn11.w = 3*nS
conn11.delay = 'rand()*5*ms'
###Modulation
在Brian2中没有modulation这个关键词了,转而在"on_pre"中直接定义。
conn12 = Connection(source, target, 'ge',
modulation='u')
conn12 = Synapses(source, target, 'w : siemens',
on_pre='ge += w * u_pre')
突触结构:Structure
Brian2不支持Structure了,所有的突触数据都是以sparse data structure,然后也不支持在模拟期间修改权值。
##Converting Brian 1’s Synapses class
###“pre”和“post”重命名为“on_pre”和“on_post”
stdp_syn = Synapses(inputs, neurons, model='''
w:1
dApre/dt = -Apre/taupre : 1 (event-driven)
dApost/dt = -Apost/taupost : 1 (event-driven)''',
on_pre='''ge + =w
Apre += delta_Apre
w = clip(w + Apost, 0, gmax)''',
on_post='''Apost += delta_Apost
w = clip(w + Apre, 0, gmax)''')
和变量:Lumped variables (summed variables)
用突触定义的“model”中添加后缀定义为“(summed)”的变量,而不是Brian1中定义一个神经元变量。
neurons = NeuronGroup(1, model='''
dv/dt = (gtot - v)/(10*ms) : 1
gtot : 1''')
syn = Synapses(inputs, neurons,
model='''
dg/dt = -a*g+b*x*(1-g) : 1
dx/dt = -c*x : 1
w : 1 # synaptic weight
gtot_post = g : 1 (summed)''',
on_pre='x += w')
制作连接:Creating Synapses connection
定义中的关键参数:i, j, n, p
syn = Synapses(...)
syn.connect(i=3, j=5)
syn.connect()
syn.connect(j='1')
syn.connect(i=4, j=7, n=3)
syn.connect(p=0.02)
Multiple pathways
暂时还没理解这个Multiple pathways具体意义是什么,就是“pre”和“post”通路都有的意思吗?Brian2中使用dictionary格式来定义,Brian1中用tuple来定义。
S = Synapses(...,
pre={'pre_transmission':
'ge += w',
'pre_plasticity':
'''w = clip(w + Apost, 0, inf)
Apre += delta_Apre'''},
post='''Apost += delta_Apost
w = clip(w + Apre, 0, inf)''')
S.connect()
S.pre_plasticity.delay[:, :] = 3*ms
监测突触变量:Monitoring synaptic variables
Brian2中不需要定义indices,可以直接在“StateMonitor”通过"record"定义记录范围。
syn = Synapses(...)
indices = syn.synapse_index((slice(None), 3))
mon = StateMonitor(S, 'w', record=indices)
syn = Synapses(...)
mon = StateMonitor(S, 'w', record=S[:, 3])
未完不一定续
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)