Skip to content

Commit 6bf7cc0

Browse files
authored
Merge pull request #177 from PKU-NIP-Lab/updates
Updates and fixes
2 parents 8be34fe + fe95783 commit 6bf7cc0

File tree

5 files changed

+73
-237
lines changed

5 files changed

+73
-237
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ publishment.md
55

66
development
77

8+
examples/simulation/data
89
examples/analysis/data
910
extensions/.idea
1011
extensions/wheelhouse

README.md

Lines changed: 1 addition & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ BrainPy is a flexible, efficient, and extensible framework for computational neu
2727

2828

2929

30-
## Installation
30+
## Install
3131

3232
BrainPy is based on Python (>=3.7) 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:
3333

@@ -42,239 +42,6 @@ The following packages are required for ``BrainPy``:
4242
For detailed installation instructions, please refer to the documentation: [Quickstart/Installation](https://brainpy.readthedocs.io/en/latest/quickstart/installation.html)
4343

4444

45-
46-
## Examples
47-
48-
49-
50-
```python
51-
import brainpy as bp
52-
```
53-
54-
55-
56-
### 1. Operator level
57-
58-
Mathematical operators in BrainPy are the same as those in NumPy.
59-
60-
```python
61-
>>> import numpy as np
62-
>>> import brainpy.math as bm
63-
64-
# array creation
65-
>>> np_arr = np.zeros((2, 4)); np_arr
66-
array([[0., 0., 0., 0.],
67-
[0., 0., 0., 0.]])
68-
>>> bm_arr = bm.zeros((2, 4)); bm_arr
69-
JaxArray([[0., 0., 0., 0.],
70-
[0., 0., 0., 0.]], dtype=float32)
71-
72-
# in-place updating
73-
>>> np_arr[0] += 1.; np_arr
74-
array([[1., 1., 1., 1.],
75-
[0., 0., 0., 0.]])
76-
>>> bm_arr[0] += 1.; bm_arr
77-
JaxArray([[1., 1., 1., 1.],
78-
[0., 0., 0., 0.]], dtype=float32)
79-
80-
# random number generation
81-
>>> np.random.uniform(-0.1, 0.1, (2, 3))
82-
array([[-0.02773637, 0.03766689, -0.01363128],
83-
[-0.01946991, -0.06669802, 0.09426067]])
84-
>>> bm.random.uniform(-0.1, 0.1, (2, 3))
85-
JaxArray([[-0.03044081, -0.07787752, 0.04346445],
86-
[-0.01366713, -0.0522548 , 0.04372055]], dtype=float32)
87-
```
88-
89-
90-
91-
### 2. Integrator level
92-
93-
Numerical methods for ordinary differential equations (ODEs).
94-
95-
```python
96-
sigma = 10; beta = 8/3; rho = 28
97-
98-
@bp.odeint(method='rk4')
99-
def lorenz_system(x, y, z, t):
100-
dx = sigma * (y - x)
101-
dy = x * (rho - z) - y
102-
dz = x * y - beta * z
103-
return dx, dy, dz
104-
```
105-
106-
107-
108-
Numerical methods for stochastic differential equations (SDEs).
109-
110-
```python
111-
sigma = 10; beta = 8/3; rho = 28
112-
113-
def lorenz_noise(x, y, z, t):
114-
return 0.1*x, 0.1*y, 0.1*z
115-
116-
@bp.odeint(method='milstein', g=lorenz_noise)
117-
def lorenz_system(x, y, z, t):
118-
dx = sigma * (y - x)
119-
dy = x * (rho - z) - y
120-
dz = x * y - beta * z
121-
return dx, dy, dz
122-
```
123-
124-
125-
126-
Numerical methods for delay differential equations (DDEs).
127-
128-
```python
129-
xdelay = bm.TimeDelay(bm.zeros(1), delay_len=1., before_t0=1., dt=0.01)
130-
131-
@bp.ddeint(method='rk4', state_delays={'x': xdelay})
132-
def second_order_eq(x, y, t):
133-
dx = y
134-
dy = -y - 2 * x - 0.5 * xdelay(t - 1)
135-
return dx, dy
136-
```
137-
138-
139-
Numerical methods for fractional differential equations (FDEs).
140-
141-
```python
142-
sigma = 10; beta = 8/3; rho = 28
143-
144-
@bp.fdeint(method='GLShortMemory', alpha=0.97)
145-
def fractional_lorenz(x, y, z, t):
146-
dx = sigma * (y - x)
147-
dy = x * (rho - z) - y
148-
dz = x * y - beta * z
149-
return dx, dy, dz
150-
```
151-
152-
153-
### 3. Dynamics simulation level
154-
155-
Building an E-I balance network.
156-
157-
```python
158-
class EINet(bp.dyn.Network):
159-
def __init__(self):
160-
E = bp.dyn.LIF(3200, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.)
161-
I = bp.dyn.LIF(800, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.)
162-
E.V[:] = bp.math.random.randn(3200) * 2 - 60.
163-
I.V[:] = bp.math.random.randn(800) * 2 - 60.
164-
165-
E2E = bp.dyn.ExpCOBA(E, E, bp.conn.FixedProb(prob=0.02), E=0., g_max=0.6, tau=5.)
166-
E2I = bp.dyn.ExpCOBA(E, I, bp.conn.FixedProb(prob=0.02), E=0., g_max=0.6, tau=5.)
167-
I2E = bp.dyn.ExpCOBA(I, E, bp.conn.FixedProb(prob=0.02), E=-80., g_max=6.7, tau=10.)
168-
I2I = bp.dyn.ExpCOBA(I, I, bp.conn.FixedProb(prob=0.02), E=-80., g_max=6.7, tau=10.)
169-
170-
super(EINet, self).__init__(E2E, E2I, I2E, I2I, E=E, I=I)
171-
```
172-
173-
Simulating a whole-brain network by using rate models.
174-
175-
```python
176-
class WholeBrainNet(bp.dyn.Network):
177-
def __init__(self):
178-
super(WholeBrainNet, self).__init__()
179-
180-
self.areas = bp.dyn.RateFHN(80, x_ou_sigma=0.01, y_ou_sigma=0.01, name='fhn')
181-
self.conns = bp.dyn.DiffusiveDelayCoupling(self.areas, self.areas, 'x->input',
182-
conn_mat=conn_mat,
183-
delay_mat=delay_mat)
184-
185-
def update(self, _t, _dt):
186-
self.conns.update(_t, _dt)
187-
self.areas.update(_t, _dt)
188-
```
189-
190-
191-
192-
### 4. Dynamics training level
193-
194-
Training an echo state network.
195-
196-
```python
197-
i = bp.nn.Input(3)
198-
r = bp.nn.Reservoir(100)
199-
o = bp.nn.LinearReadout(3)
200-
201-
net = i >> r >> o
202-
203-
trainer = bp.nn.RidgeTrainer(net, beta=1e-5) # Ridge Regression
204-
205-
trainer = bp.nn.ForceTrainer(net, alpha=1.) # FORCE Learning
206-
```
207-
208-
209-
210-
Training a next-generation reservoir computing model.
211-
212-
```python
213-
i = bp.nn.Input(3)
214-
r = bp.nn.NVAR(delay=2, order=2)
215-
o = bp.nn.LinearReadout(3)
216-
217-
net = i >> r >> o
218-
219-
trainer = bp.nn.RidgeTrainer(net, beta=1e-5)
220-
```
221-
222-
223-
224-
Training an artificial recurrent neural network.
225-
226-
```python
227-
i = bp.nn.Input(3)
228-
l1 = bp.nn.VanillaRNN(100)
229-
l2 = bp.nn.VanillaRNN(200)
230-
o = bp.nn.Dense(10)
231-
232-
net = i >> l1 >> l2 >> o
233-
234-
trainer = bp.nn.BPTT(net,
235-
loss='cross_entropy_loss',
236-
optimizer=bp.optim.Adam(0.01))
237-
```
238-
239-
240-
241-
### 5. Dynamics analysis level
242-
243-
Analyzing a low-dimensional FitzHugh–Nagumo neuron model.
244-
245-
```python
246-
model = bp.dyn.FHN(1)
247-
248-
analyzer = bp.analysis.PhasePlane2D(
249-
model,
250-
target_vars={'V': [-3, 3], 'w': [-3., 3.]},
251-
pars_update={'I_ext': 0.8},
252-
resolutions=0.01
253-
)
254-
analyzer.plot_nullcline()
255-
analyzer.plot_vector_field()
256-
analyzer.plot_fixed_point()
257-
analyzer.show_figure()
258-
```
259-
260-
Analyzing a high-dimensional continuous-attractor neural network (CANN).
261-
262-
```python
263-
cann_model = CANN(100) # your high-dimensional CANN network
264-
265-
finder = bp.analysis.SlowPointFinder(f_cell=cann_model)
266-
finder.find_fps_with_gd_method(candidates=bm.random.random((1000, 100)))
267-
finder.filter_loss(tolerance=1e-5)
268-
finder.keep_unique(tolerance=0.03)
269-
finder.exclude_outliers(0.1)
270-
```
271-
272-
273-
### 6. More others
274-
275-
For **more functions and examples**, please refer to the [documentation](https://brainpy.readthedocs.io/) and [examples](https://brainpy-examples.readthedocs.io/).
276-
277-
27845
## License
27946

28047
[GNU General Public License v3.0](https://github.com/PKU-NIP-Lab/BrainPy/blob/master/LICENSE)

brainpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = "2.1.5"
3+
__version__ = "2.1.7"
44

55

66
try:

brainpy/dyn/synapses/abstract_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,9 @@ def update(self, _t, _dt):
12271227
post_g = bm.sum(self.g)
12281228
if not self.conn.include_self:
12291229
post_g = post_g - self.g
1230+
post_g = post_g * self.g_max
12301231
else:
1231-
post_g = self.g * self.g_max
1232+
post_g = self.g @ self.g_max
12321233
elif isinstance(self.conn, One2One):
12331234
post_g = self.g_max * self.g
12341235
else:
@@ -1242,4 +1243,4 @@ def update(self, _t, _dt):
12421243

12431244
# output
12441245
g_inf = 1 + self.cc_Mg / self.beta * bm.exp(-self.alpha * self.post.V)
1245-
self.post.input -= post_g * (self.post.V - self.E) / g_inf
1246+
self.post.input += post_g * (self.E - self.post.V) / g_inf

changelog.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,73 @@ brainpy 2.x (LTS)
66
*****************
77

88

9+
Version 2.1.6 (2022.04.20)
10+
==========================
11+
12+
13+
What's Changed
14+
~~~~~~~~~~~~~~
15+
16+
17+
18+
19+
Version 2.1.5 (2022.04.18)
20+
==========================
21+
22+
23+
What's Changed
24+
~~~~~~~~~~~~~~
25+
26+
* ``brainpy.math.random.shuffle`` is numpy like by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#153 <https://github.com/PKU-NIP-Lab/BrainPy/pull/153>`_
27+
* update LICENSE by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#155 <https://github.com/PKU-NIP-Lab/BrainPy/pull/155>`_
28+
* docs: add m1 warning by `@ztqakita <https://github.com/ztqakita>`_ in `#154 <https://github.com/PKU-NIP-Lab/BrainPy/pull/154>`_
29+
* compatible apis of 'brainpy.math' with those of 'jax.numpy' in most modules by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#156 <https://github.com/PKU-NIP-Lab/BrainPy/pull/156>`_
30+
* Important updates by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#157 <https://github.com/PKU-NIP-Lab/BrainPy/pull/157>`_
31+
* Updates by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#159 <https://github.com/PKU-NIP-Lab/BrainPy/pull/159>`_
32+
* Add LayerNorm, GroupNorm, and InstanceNorm as nn_nodes in normalization.py by `@c-xy17 <https://github.com/c-xy17>`_ in `#162 <https://github.com/PKU-NIP-Lab/BrainPy/pull/162>`_
33+
* feat: add conv & pooling nodes by `@ztqakita <https://github.com/ztqakita>`_ in `#161 <https://github.com/PKU-NIP-Lab/BrainPy/pull/161>`_
34+
* fix: update setup.py by `@ztqakita <https://github.com/ztqakita>`_ in `#163 <https://github.com/PKU-NIP-Lab/BrainPy/pull/163>`_
35+
* update setup.py by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#165 <https://github.com/PKU-NIP-Lab/BrainPy/pull/165>`_
36+
* fix: change trigger condition by `@ztqakita <https://github.com/ztqakita>`_ in `#166 <https://github.com/PKU-NIP-Lab/BrainPy/pull/166>`_
37+
* fix: add build_conn() function by `@ztqakita <https://github.com/ztqakita>`_ in `#164 <https://github.com/PKU-NIP-Lab/BrainPy/pull/164>`_
38+
* update synapses by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#167 <https://github.com/PKU-NIP-Lab/BrainPy/pull/167>`_
39+
* get the deserved name: brainpy by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#168 <https://github.com/PKU-NIP-Lab/BrainPy/pull/168>`_
40+
* update tests by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#169 <https://github.com/PKU-NIP-Lab/BrainPy/pull/169>`_
41+
42+
**Full Changelog**\ : `V2.1.4...V2.1.5 <https://github.com/PKU-NIP-Lab/BrainPy/compare/V2.1.4...V2.1.5>`_
43+
44+
45+
46+
Version 2.1.4 (2022.04.04)
47+
==========================
48+
49+
50+
What's Changed
51+
~~~~~~~~~~~~~~
52+
53+
* fix doc parsing bug by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#127 <https://github.com/PKU-NIP-Lab/BrainPy/pull/127>`_
54+
* Update overview_of_dynamic_model.ipynb by `@c-xy17 <https://github.com/c-xy17>`_ in `#129 <https://github.com/PKU-NIP-Lab/BrainPy/pull/129>`_
55+
* Reorganization of ``brainpylib.custom_op`` and adding interface in ``brainpy.math`` by `@ztqakita <https://github.com/ztqakita>`_ in `#128 <https://github.com/PKU-NIP-Lab/BrainPy/pull/128>`_
56+
* Fix: modify ``register_op`` and brainpy.math interface by `@ztqakita <https://github.com/ztqakita>`_ in `#130 <https://github.com/PKU-NIP-Lab/BrainPy/pull/130>`_
57+
* new features about RNN training and delay differential equations by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#132 <https://github.com/PKU-NIP-Lab/BrainPy/pull/132>`_
58+
* Fix `#123 <https://github.com/PKU-NIP-Lab/BrainPy/issues/123>`_\ : Add low-level operators docs and modify register_op by `@ztqakita <https://github.com/ztqakita>`_ in `#134 <https://github.com/PKU-NIP-Lab/BrainPy/pull/134>`_
59+
* feat: add generate_changelog by `@ztqakita <https://github.com/ztqakita>`_ in `#135 <https://github.com/PKU-NIP-Lab/BrainPy/pull/135>`_
60+
* fix `#133 <https://github.com/PKU-NIP-Lab/BrainPy/issues/133>`_\ , support batch size training with offline algorithms by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#136 <https://github.com/PKU-NIP-Lab/BrainPy/pull/136>`_
61+
* fix `#84 <https://github.com/PKU-NIP-Lab/BrainPy/issues/84>`_\ : support online training algorithms by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#137 <https://github.com/PKU-NIP-Lab/BrainPy/pull/137>`_
62+
* feat: add the batch normalization node by `@c-xy17 <https://github.com/c-xy17>`_ in `#138 <https://github.com/PKU-NIP-Lab/BrainPy/pull/138>`_
63+
* fix: fix shape checking error by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#139 <https://github.com/PKU-NIP-Lab/BrainPy/pull/139>`_
64+
* solve `#131 <https://github.com/PKU-NIP-Lab/BrainPy/issues/131>`_\ , support efficient synaptic computation for special connection types by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#140 <https://github.com/PKU-NIP-Lab/BrainPy/pull/140>`_
65+
* feat: update the API and test for batch normalization by `@c-xy17 <https://github.com/c-xy17>`_ in `#142 <https://github.com/PKU-NIP-Lab/BrainPy/pull/142>`_
66+
* Node is default trainable by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#143 <https://github.com/PKU-NIP-Lab/BrainPy/pull/143>`_
67+
* Updates training apis and docs by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#145 <https://github.com/PKU-NIP-Lab/BrainPy/pull/145>`_
68+
* fix: add dependencies and update version by `@ztqakita <https://github.com/ztqakita>`_ in `#147 <https://github.com/PKU-NIP-Lab/BrainPy/pull/147>`_
69+
* update requirements by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#146 <https://github.com/PKU-NIP-Lab/BrainPy/pull/146>`_
70+
* data pass of the Node is default SingleData by `@chaoming0625 <https://github.com/chaoming0625>`_ in `#148 <https://github.com/PKU-NIP-Lab/BrainPy/pull/148>`_
71+
72+
**Full Changelog**\ : `V2.1.3...V2.1.4 <https://github.com/PKU-NIP-Lab/BrainPy/compare/V2.1.3...V2.1.4>`_
73+
74+
75+
976
Version 2.1.3 (2022.03.27)
1077
==========================
1178

0 commit comments

Comments
 (0)