Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
duzc-Repos opened this issue Dec 3, 2021 · 3 comments
Open

Comments

@duzc-Repos
Copy link

duzc-Repos commented Dec 3, 2021

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
Copy link
Owner

Sorry for the long delay, where is your test file

@duzc-Repos
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants