BrainPy-Models: An example package accompany with BrainPy.
Project description
BrainPy-Models
Note: We welcome your contributions for model implementations.
BrainPy-Models
is a repository accompany with BrainPy, which is a framework for spiking neural network simulation. With BrainPy, we implements the most canonical and effective neuron models and synapse models, and show them in BrainPy-Models
.
Here, users can directly import our models into your network, and also can learn examples of how to use BrainPy from Documentations.
We provide the following models:
Installation
Install from source code:
python setup.py install
Install BrainPy-Models
using conda
:
conda install bpmodels -c brainpy
Install BrainPy-Models
using pip
:
pip install bpmodels
The following packages need to be installed to use BrainPy-Models
:
- Python >= 3.7
- Matplotlib >= 2.0
- brainpy-simulator >= 0.3.0
Quick Start
The use of bpmodels
is very convenient, let's take an example of the implementation of the E-I balanced network.
We start by importing the brainpy
and bpmodels
packages and set profile.
import brainpy as bp
import bpmodels
import numpy as np
import matplotlib.pyplot as plt
# set profile
bp.profile.set(jit=True, device='cpu',
numerical_method='exponential')
The E-I balanced network is based on leaky Integrate-and-Fire (LIF) neurons connecting with single exponential decay synapses. As showed in the table above, bpmodels
provides pre-defined LIF neuron model and exponential synapse model, so we can use bpmodels.neurons.get_LIF
and bpmodels.synapses.get_exponential
to get the pre-defined models.
V_rest = -52.
V_reset = -60.
V_th = -50.
neu = bpmodels.neurons.get_LIF(V_rest=V_rest, V_reset = V_reset, V_th=V_th, noise=0., mode='scalar')
syn = bpmodels.synapses.get_exponential(tau_decay = 2., mode='scalar')
# build network
num_exc = 500
num_inh = 500
prob = 0.1
JE = 1 / np.sqrt(prob * num_exc)
JI = 1 / np.sqrt(prob * num_inh)
group = bp.NeuGroup(neu, geometry=num_exc + num_inh, monitors=['spike'])
group.ST['V'] = np.random.random(num_exc + num_inh) * (V_th - V_rest) + V_rest
exc_conn = bp.SynConn(syn,
pre_group=group[:num_exc],
post_group=group,
conn=bp.connect.FixedProb(prob=prob))
exc_conn.ST['w'] = JE
inh_conn = bp.SynConn(syn,
pre_group=group[num_exc:],
post_group=group,
conn=bp.connect.FixedProb(prob=prob))
exc_conn.ST['w'] = -JI
net = bp.Network(group, exc_conn, inh_conn)
net.run(duration=500., inputs=(group, 'ST.input', 3.))
# visualization
fig, gs = bp.visualize.get_figure(4, 1, 2, 10)
fig.add_subplot(gs[:3, 0])
bp.visualize.raster_plot(net.ts, group.mon.spike, xlim=(50, 450))
fig.add_subplot(gs[3, 0])
rates = bp.measure.firing_rate(group.mon.spike, 5.)
plt.plot(net.ts, rates)
plt.xlim(50, 450)
plt.show()
Then you would expect to see the following output:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file bpmodels-0.2.3.tar.gz
.
File metadata
- Download URL: bpmodels-0.2.3.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db6d9d73ff2d9e93c510fa0bc7430fa21dde05c7eed85674e820f7a9b991ff58 |
|
MD5 | 1c7b0149d38e0a2e643acb8a6595d0b9 |
|
BLAKE2b-256 | b8059bbd90c3578d8d92eb63f8adcc77a8220f8b15e6b99c73cda840f7a5f771 |