brainpy-largescale depends on brainpy
Project description
brainpy-largescale
安装
只支持Linux
系统下安装
pip install brainpy-largescale
引入库
import brainpy as bp
import bpl
设置硬件平台
bpl.set_platform('cpu')
目前只支持cpu,因brainpy 目前有个问题,不支持gpu。
创建神经元簇
用简单但最典型的神经元模型 Leaky Integrate-and-Fire (LIF) 模型来构建兴奋性和抑制性神经元组
a = bpl.neurons.LIF(300, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.)
b = bpl.neurons.LIF(100, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.)
创建突触
在定义 LIF 神经元组时,可以根据用户的需要调整参数。第一个参数表示神经元的数量。这里兴奋性和抑制性神经元的比例设置为 4:1。 V_rest 表示静息电位,V_th 表示触发阈值,V_reset 表示触发后的复位值,tau 为时间常数,tau_ref 为不应期的持续时间。方法是指在模拟中使用的数值积分方法。 那么这两组之间的突触连接可以定义如下:
d = bpl.synapses.Exponential(a, b, bp.conn.FixedProb(0.4, seed=123), g_max=10, tau=5., delay_step=1)
在这里,我们使用指数突触模型 (bpl.synapses.Exponential) 来模拟突触连接。在模型的参数中,前两个分别表示突触前和突触后神经元组。第三个是指连接类型。在此示例中,我们使用 bp.conn.FixedProb,它以给定的概率将突触前神经元连接到突触后神经元(详细信息可在 Synaptic Connection 中获得)。以下三个参数描述了突触的动态特性,最后一个是 LIF 模型中的数值积分方法。
构建网络
定义完所有组件后,就可以组合成一个网络:
net = bpl.Network(a, b, d)
net.build()
增加输入
增加电流输入
inputs = [bpl.device.Input(a, 20), bpl.device.Input(b, 10)]
增加脉冲监测
monitor_spike = bpl.device.Monitor([a, b], bpl.device.MonitorKey.spike)
增加电压监测
monitor_volt = bpl.device.Monitor([b], bpl.device.MonitorKey.volt)
脉冲和电压监测合并到一个List:
monitors = [monitor_spike, monitor_volt]
增加脉冲和电压回调函数
def spike(a: List[Tuple[int, float]]):
if a:
print(a)
def volt(a: List[Tuple[int, float, float]]):
# print(a)
pass
运行网络
构建 SNN 后,我们可以将其用于动态模拟。要运行模拟,我们需要先将网络模型包装到运行器中,用户可以按如下方式初始DSRunner:
runner = bpl.runner.DSRunner(
net,
monitors=monitors,
inputs=inputs,
jit=False,
spike_callback=spike,
volt_callback=volt,
)
runner.run(10.)
其中调用函数接收模拟时间(通常以毫秒为单位)作为输入。
## 可视化
import matplotlib.pyplot as plt
if 'spike' in runner.mon:
bp.visualize.raster_plot(runner.mon.ts, runner.mon['spike'], show=True)
What is brainpy-largescale?
Run BrainPy in multiple processes.
brainpy-largescale depends on BrainPy and brainpy-lib, use the following instructions to install brainpy package.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for brainpy_largescale-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42fe8af7d89b6fb448964e972a08ebc8a86d6c4b13e5990e6dc9617e1d249af9 |
|
MD5 | 3d4e9ae03120b91c3ad82157bf1b3912 |
|
BLAKE2b-256 | e9818a7325d43d5279887b599f2ff0e948f32209da02677c436d7ae2a11926af |