Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/dynamics_analysis/highdim_RNN_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(
self.alpha = 1
else:
self.alpha = dt / self.tau
self.rng = bm.random.RandomState(seed=seed)
self.rng = bm.random.RandomState(seed)

# input weight
self.w_ir = bm.TrainVar(bp.init.parameter(w_ir, (num_input, num_hidden)))
Expand Down
12 changes: 7 additions & 5 deletions examples/dynamics_simulation/whole_brain_simulation_with_fhn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-


import os

import matplotlib.pyplot as plt
import numpy as np

Expand All @@ -25,11 +27,11 @@ class Network(bp.DynSysGroup):
def __init__(self, signal_speed=20.):
super(Network, self).__init__()

# Please download the processed data "hcp.npz" of the
# ConnectomeDB of the Human Connectome Project (HCP)
# from the following link:
# - https://share.weiyun.com/wkPpARKy
hcp = np.load('../../tests/simulation/data/hcp.npz')
# HCP connectome data ("hcp.npz", processed from the ConnectomeDB of
# the Human Connectome Project) is bundled with BrainPy at
# ``brainpy/dyn/rates/data/hcp.npz``.
hcp_path = os.path.join(os.path.dirname(bp.__file__), 'dyn', 'rates', 'data', 'hcp.npz')
hcp = np.load(hcp_path)
conn_mat = bm.asarray(hcp['Cmat'])
bm.fill_diagonal(conn_mat, 0)
delay_mat = bm.round(hcp['Dmat'] / signal_speed / bm.dt).astype(bm.int_)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

import os

import matplotlib.pyplot as plt
import numpy as np

Expand All @@ -26,11 +28,11 @@ class Network(bp.DynSysGroup):
def __init__(self, noise=0.14):
super(Network, self).__init__()

# Please download the processed data "hcp.npz" of the
# ConnectomeDB of the Human Connectome Project (HCP)
# from the following link:
# - https://share.weiyun.com/wkPpARKy
hcp = np.load('../../tests/simulation/data/hcp.npz')
# HCP connectome data ("hcp.npz", processed from the ConnectomeDB of
# the Human Connectome Project) is bundled with BrainPy at
# ``brainpy/dyn/rates/data/hcp.npz``.
hcp_path = os.path.join(os.path.dirname(bp.__file__), 'dyn', 'rates', 'data', 'hcp.npz')
hcp = np.load(hcp_path)
conn_mat = bm.asarray(hcp['Cmat'])
bm.fill_diagonal(conn_mat, 0)
gc = 0.6 # global coupling strength
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamics_training/Song_2016_EI_RNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
self.i_size = num_hidden - self.e_size
self.alpha = dt / self.tau
self.sigma_rec = (2 * self.alpha) ** 0.5 * sigma_rec # Recurrent noise
self.rng = bm.random.RandomState(seed=seed)
self.rng = bm.random.RandomState(seed)

# hidden mask
mask = np.tile([1] * self.e_size + [-1] * self.i_size, (num_hidden, 1))
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamics_training/integrate_flax_into_brainpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Network(bp.DynamicalSystem):
def __init__(self):
super(Network, self).__init__()
self.cnn = bp.layers.FromFlax(CNN(), bm.ones([1, 4, 28, 1]))
self.rnn = bp.layers.GRUCell(256, 100)
self.rnn = bp.dyn.GRUCell(256, 100)
self.linear = bp.layers.Dense(100, 10)

def update(self, x):
Expand Down
6 changes: 3 additions & 3 deletions examples/training_ann_models/mnist_ResNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def update(self, s, x):


class ResNet(bp.DynamicalSystem):
def __init__(self, block, num_blocks, num_classes=10, zero_init_residual=False):
def __init__(self, block, num_blocks, num_classes=10, in_channels=3, zero_init_residual=False):
super(ResNet, self).__init__()
self.in_planes = 64

self.conv1 = bp.layers.Conv2D(3, 64, kernel_size=(3, 3), strides=(1, 1), padding=(1, 1),
self.conv1 = bp.layers.Conv2D(in_channels, 64, kernel_size=(3, 3), strides=(1, 1), padding=(1, 1),
w_initializer=weight_init)
self.bn1 = bp.layers.BatchNorm2D(64)
self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=1)
Expand Down Expand Up @@ -208,7 +208,7 @@ def main():
y_test = bm.asarray(test_set.targets, dtype=bm.int_)

with bm.training_environment():
net = ResNet18(num_classes=10)
net = ResNet18(num_classes=10, in_channels=1)

# loss function
def loss_fun(X, Y, fit=True):
Expand Down
Loading