aestrivex / bctpy

brain connectivity toolbox for python
GNU General Public License v3.0
295 stars 138 forks source link

IndexError: index 2278 is out of bounds for axis 0 with size 2278 #104

Open duzc-Repos opened 2 years ago

duzc-Repos commented 2 years ago

Hi, when I use the generative_model() function, the following error occured. I have uploaded my test file and my running environment is python 3.8.12, numpy 1.20.3, scipy 1.6.2, bctpy 0.5.2. Please help me why this happened.


/mnt/d/software_for_wsl2/miniconda3/lib/python3.8/site-packages/bct/algorithms/generative.py:444: RuntimeWarning: divide by zero encountered in power
  Fd = D ** eta
/mnt/d/software_for_wsl2/miniconda3/lib/python3.8/site-packages/bct/algorithms/generative.py:444: RuntimeWarning: divide by zero encountered in reciprocal
  Fd = D ** eta
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    test_B = bct.generative_model(A_test, D, 321, eta=[eta], gamma=[gam], model_type='euclidean', model_var='powerlaw')
  File "/mnt/d/software_for_wsl2/miniconda3/lib/python3.8/site-packages/bct/algorithms/generative.py", line 528, in generative_model
    B[:,:,j] = euclidean_gen(A, D, m, ep, model_var)
  File "/mnt/d/software_for_wsl2/miniconda3/lib/python3.8/site-packages/bct/algorithms/generative.py", line 460, in euclidean_gen
    A[u[r], v[r]] = A[v[r], u[r]] = 1
IndexError: index 2278 is out of bounds for axis 0 with size 2278
···

PS: I also read the source code of `euclidean_gen()` function in `generative_model()` function. It seems that this function would modify the value of __seed network__ `A` out of this function. but my error still occured when I add `B=A.copy()` and modify the value on B for each loop.

[test.zip](https://github.com/aestrivex/bctpy/files/7648017/test.zip)
aestrivex commented 2 years ago

Sorry for the long delay, where is your test file

duzc-Repos commented 2 years ago

Thank you, it seems fine after I fixed it. Generally, I find two problems:

  1. the input seed network A would be modified *_gen, e.g. euclidean_gen(), so I add A = A.copy() at the beginning for every *_gen() function.
  2. index error, the following is an example:
    
    # example in "euclidean_gen"

for i in range(mseed, m): C = np.append(0, np.cumsum(P[u, v]))

r = np.sum(rng.random_sample()*C[-1] >= C)

r = np.sum(rng.random_sample()*C[-1] >= C) - 1 # modified by duzc
b[i] = r
P = Fd
#P[u[b[:i]], v[b[:i]]] = P[v[b[:i]], u[b[:i]]] = 0
P[u[b[:i+1]], v[b[:i+1]]] = P[v[b[:i+1]], u[b[:i+1]]] = 0 # modified by duzc

A[u[r], v[r]] = A[v[r], u[r]] = 1


Please help me check it if convenient.
duzc-Repos commented 2 years ago

The test file you can find in https://github.com/duzc-Repos/Code_for_Reproduction/tree/main/2021_NC_DanyalAkarca/bct_duzc_test_data and https://github.com/duzc-Repos/Code_for_Reproduction/blob/main/2021_NC_DanyalAkarca/test_bct_duzc.py are my test file