cNMF
cNMF copied to clipboard
error in the tutorial: "high is out of bounds for int32"
Hello, When running the tutorial notebook analyze_pbmc_example_data.ipynb I get the following error:
ValueError Traceback (most recent call last) ~\AppD```
ata\Local\Temp\ipykernel_25820\2126166754.py in
1 ## Prepare the data, I.e. subset to 2000 high-variance genes, and variance normalize ----> 2 cnmf_obj.prepare(counts_fn=countfn, components=np.arange(5,11), n_iter=20, seed=14, num_highvar_genes=2000) ~\PycharmProjects\cNMF\src\cnmf\cnmf.py in prepare(self, counts_fn, components, n_iter, densify, tpm_fn, seed, beta_loss, num_highvar_genes, genes_file) 358 359 self.save_norm_counts(norm_counts) --> 360 (replicate_params, run_params) = self.get_nmf_iter_params(ks=components, n_iter=n_iter, random_state_seed=seed, beta_loss=beta_loss) 361 self.save_nmf_iter_params(replicate_params, run_params) 362
~\PycharmProjects\cNMF\src\cnmf\cnmf.py in get_nmf_iter_params(self, ks, n_iter, random_state_seed, beta_loss) 484 485 np.random.seed(seed=random_state_seed) --> 486 nmf_seeds = np.random.randint(low=1, high=(2**32)-1, size=n_runs) 487 488 replicate_params = []
mtrand.pyx in numpy.random.mtrand.RandomState.randint()
_bounded_integers.pyx in numpy.random._bounded_integers._rand_int32()
ValueError: high is out of bounds for int32
The issue can be solved by adding "dtype=np.int64" at line 486 in cNMF\src\cnmf\cnmf.py
nmf_seeds = np.random.randint(low=1, high=(2**32)-1, size=n_runs, dtype=np.int64)
Ron
Hi, thank you for this comment and for using cNMF. It is strange that I'm not getting this error in settings outside of the tutorial and indeed I'm having a hard time reproducing the error. What version of numpy are you using? It seems reasonable for me to just update the code like you did to explicitly define the integer type
Thanks for the reply and for publishing this great code! I'm using numpy 1.21.5 with conda - Python 3.7 I think the install instructions don't indicate what version to use.
Thanks for the reply and for publishing this great code! I'm using numpy 1.21.5 with conda - Python 3.7 I think the install instructions don't indicate what version to use.
In Python Version 3.7.12 with NumPy 1.21.6, the following method might be helpful:
modify
~\.conda\envs\cnmf_env\Lib\site-packages\cnmf\cnmf.py
In line 508, changehigh=(2**32)-1
intohigh=(2**31)-1
It works for me, might worth trying.
I put the "508 nmf_seeds = np. Random. Randint (low = 1, high = (2 * * 32) - 1, size = n_runs)" in "high = (2 * * 32) - 1" replaced by "high = (2 * * 31) - 1", runs successfully!
Adjusted in commit https://github.com/dylkot/cNMF/commit/c94962d60490896361c0e8b659a29862145f3672