You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import sys
import matplotlib.pyplot as plt
import numpy as np
import brainpy as bp
import brainpy.math as bm
import os
from scipy.sparse import coo_matrix, csr_matrix
Apologies for the delayed response. Based on your description, I have some understanding of the issue. It seems that in BrainPy, for CSR matrix connections, the handling of multiple connections hasn't been considered. In BrainPy's CSRConn , the problem of repeated connections is indeed not considered. If we print the conn matrix here and pre_ids, post_ids, it will be like this.
csr:
conn_mat: [[False True]
[False False]]
pre ids: [0]
post ids: [1]
ij:
conn_mat: [[False True]
[False False]]
pre ids: [0 0]
post ids: [1 1]
To address this, I suggest considering a custom function to handle multiple connections. This could involve assigning weight values to each connection. In BrainPy, the CSR matrix multiplication operator can accept weights to perform the corresponding calculations.
import sys
import matplotlib.pyplot as plt
import numpy as np
import brainpy as bp
import brainpy.math as bm
import os
from scipy.sparse import coo_matrix, csr_matrix
brainpy version 2.5.0
class EINet(bp.DynSysGroup):
def init(self, E_neuron, I_neuron, E_params, I_params, E2E_synapse, E2I_synapse, I2E_synapse, I2I_synapse, E2E_synapse_params, E2I_synapse_params, I2E_synapse_params, I2I_synapse_params, E2E_comm, E2I_comm, I2E_comm, I2I_comm):
super().init()
def get_run_func(EI_net, E_inp_kwargs, I_inp_kwargs, E_size, I_size, input_type='constant'):
if input_type == 'constant':
def run_func(i):
return EI_net.step_run(i, E_inp_kwargs['mean'], I_inp_kwargs['mean'])
if input_type == 'wiener':
def run_func(i):
local_E_inp = np.random.randn(E_size)*E_inp_kwargs['std'] + E_inp_kwargs['mean']
local_I_inp = np.random.randn(I_size)*I_inp_kwargs['std'] + I_inp_kwargs['mean']
return EI_net.step_run(i, local_E_inp, local_I_inp)
return run_func
E2E_weight = 1
E2I_weight = 0
I2E_weight = 0
I2I_weight = 0
E_size = 2
I_size = 2
E_params = {'size': E_size, 'V_th': 20.0, 'V_reset': -5.0, 'V_rest':0., 'tau_ref': 5.0, 'R': 1.0, 'tau': 10.0}
I_params = {'size': I_size, 'V_th': 20.0, 'V_reset': -5.0, 'V_rest':0., 'tau_ref': 5.0, 'R': 1.0, 'tau': 10.0}
E2E_synapse_params = {'delay': 0}
E2I_synapse_params = {'delay': 0}
I2E_synapse_params = {'delay': 0}
I2I_synapse_params = {'delay': 0}
E_inp_mean = np.zeros(E_size)
E_inp_mean[0] = 30 # 只在第一个神经元输入电流
E_inp_std = 0
I_inp_mean = 0
I_inp_std = 0
dt = 1.
bm.set_dt(dt)
for mode in ['csr', 'ij']:
if mode == 'csr':
# 利用csr创建conn
row_indices = np.array([0, 0])
col_indices = np.array([1, 1])
E2E_csr = csr_matrix((np.ones_like(row_indices), (row_indices, col_indices)), shape=(E_size, E_size))
E2E_conn = bp.connect.SparseMatConn(E2E_csr)
if mode == 'ij':
# 利用ij创建conn
pre_list = np.array([0, 0])
post_list = np.array([1, 1])
E2E_conn = bp.conn.IJConn(i=pre_list, j=post_list)
E2E_conn = E2E_conn(pre_size=E_size, post_size=E_size)
The text was updated successfully, but these errors were encountered: