diff --git a/examples/dynamics_analysis/highdim_RNN_Analysis.py b/examples/dynamics_analysis/highdim_RNN_Analysis.py index 87cb41ae3..a96a1c1d9 100644 --- a/examples/dynamics_analysis/highdim_RNN_Analysis.py +++ b/examples/dynamics_analysis/highdim_RNN_Analysis.py @@ -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))) diff --git a/examples/dynamics_simulation/whole_brain_simulation_with_fhn.py b/examples/dynamics_simulation/whole_brain_simulation_with_fhn.py index bd2ff7c62..b6aeab940 100644 --- a/examples/dynamics_simulation/whole_brain_simulation_with_fhn.py +++ b/examples/dynamics_simulation/whole_brain_simulation_with_fhn.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +import os + import matplotlib.pyplot as plt import numpy as np @@ -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_) diff --git a/examples/dynamics_simulation/whole_brain_simulation_with_sl_oscillator.py b/examples/dynamics_simulation/whole_brain_simulation_with_sl_oscillator.py index eece6cb8b..509ec5e79 100644 --- a/examples/dynamics_simulation/whole_brain_simulation_with_sl_oscillator.py +++ b/examples/dynamics_simulation/whole_brain_simulation_with_sl_oscillator.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import os + import matplotlib.pyplot as plt import numpy as np @@ -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 diff --git a/examples/dynamics_training/Song_2016_EI_RNN.py b/examples/dynamics_training/Song_2016_EI_RNN.py index c7209823c..6feb3b22e 100644 --- a/examples/dynamics_training/Song_2016_EI_RNN.py +++ b/examples/dynamics_training/Song_2016_EI_RNN.py @@ -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)) diff --git a/examples/dynamics_training/integrate_flax_into_brainpy.py b/examples/dynamics_training/integrate_flax_into_brainpy.py index acb0d1e0a..6dccd09f3 100644 --- a/examples/dynamics_training/integrate_flax_into_brainpy.py +++ b/examples/dynamics_training/integrate_flax_into_brainpy.py @@ -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): diff --git a/examples/training_ann_models/mnist_ResNet.py b/examples/training_ann_models/mnist_ResNet.py index 9355bce72..19d9860cc 100644 --- a/examples/training_ann_models/mnist_ResNet.py +++ b/examples/training_ann_models/mnist_ResNet.py @@ -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) @@ -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):