Skip to main content

BrainPy: Brain Dynamics Programming in Python

Project description

Header image of BrainPy - brain dynamics programming in Python.

Supported Python Version LICENSE Documentation PyPI version Linux CI Linux CI Linux CI

BrainPy is a flexible, efficient, and extensible framework for computational neuroscience and brain-inspired computation based on the Just-In-Time (JIT) compilation (built on top of JAX). It provides an integrative ecosystem for brain dynamics programming, including brain dynamics simulation, training, analysis, etc.

Install

BrainPy is based on Python (>=3.6) and can be installed on Linux (Ubuntu 16.04 or later), macOS (10.12 or later), and Windows platforms. Install the latest version of BrainPy:

$ pip install brain-py -U

The following packages are required for BrainPy:

numpy >= 1.15 and jax >= 0.2.10 (how to install jax?)

For detailed installation instructions, please refer to the documentation: Quickstart/Installation

Examples

import brainpy as bp

1. E-I balance network

class EINet(bp.dyn.Network):
  def __init__(self):
    E = bp.dyn.LIF(3200, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.)
    I = bp.dyn.LIF(800, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.)
    E.V[:] = bp.math.random.randn(3200) * 2 - 60.
    I.V[:] = bp.math.random.randn(800) * 2 - 60.
        
    E2E = bp.dyn.ExpCOBA(E, E, bp.conn.FixedProb(prob=0.02), E=0., g_max=0.6, tau=5.)
    E2I = bp.dyn.ExpCOBA(E, I, bp.conn.FixedProb(prob=0.02), E=0., g_max=0.6, tau=5.)
    I2E = bp.dyn.ExpCOBA(I, E, bp.conn.FixedProb(prob=0.02), E=-80., g_max=6.7, tau=10.)
    I2I = bp.dyn.ExpCOBA(I, I, bp.conn.FixedProb(prob=0.02), E=-80., g_max=6.7, tau=10.)
        
    super(EINet, self).__init__(E2E, E2I, I2E, I2I, E=E, I=I)
    

net = EINet()
runner = bp.dyn.DSRunner(net)
runner(100.)

2. Echo state network

i = bp.nn.Input(3)
r = bp.nn.Reservoir(100)
o = bp.nn.LinearReadout(3)

net = i >> r >> o

# Ridge Regression
trainer = bp.nn.RidgeTrainer(net, beta=1e-5)

# FORCE Learning
trainer = bp.nn.FORCELearning(net, alpha=1.)

3. Next generation reservoir computing

i = bp.nn.Input(3)
r = bp.nn.NVAR(delay=2, order=2)
o = bp.nn.LinearReadout(3)

net = i >> r >> o

trainer = bp.nn.RidgeTrainer(net, beta=1e-5)

4. Recurrent neural network

i = bp.nn.Input(3)
l1 = bp.nn.VanillaRNN(100)
l2 = bp.nn.VanillaRNN(200)
o = bp.nn.Dense(10)

net = i >> l1 >> l2 >> o

trainer = bp.nn.BPTT(net, 
                     loss='cross_entropy_loss',
                     optimizer=bp.optim.Adam(0.01))

5. Analyzing a low-dimensional FitzHugh–Nagumo neuron model

bp.math.enable_x64()

model = bp.dyn.FHN(1)
analyzer = bp.analysis.PhasePlane2D(model,
                                    target_vars={'V': [-3, 3], 'w': [-3., 3.]},
                                    pars_update={'I_ext': 0.8}, 
                                    resolutions=0.01)
analyzer.plot_nullcline()
analyzer.plot_vector_field()
analyzer.plot_fixed_point()
analyzer.plot_trajectory({'V': [-2.8], 'w': [-1.8]}, duration=100.)
analyzer.show_figure()

For more functions and examples, please refer to the documentation and examples.

License

GNU General Public License v3.0

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

brain-py-2.1.0.tar.gz (276.4 kB view details)

Uploaded Source

File details

Details for the file brain-py-2.1.0.tar.gz.

File metadata

  • Download URL: brain-py-2.1.0.tar.gz
  • Upload date:
  • Size: 276.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.11

File hashes

Hashes for brain-py-2.1.0.tar.gz
Algorithm Hash digest
SHA256 27382b56a17454468197c3e1b6f127222b2e2e083a0d3d26b46b6e0faa0003ea
MD5 5fe8dc6f1b7b11eeab4661119ec93da9
BLAKE2b-256 eff049ec2caf4269288d167218f2c85706a7f8fd2ed46055c457a34861451285

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page