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

random_polyagamma sometimes hangs in version 1.3.1 #102

Closed
macks22 opened this issue Aug 30, 2021 · 5 comments
Closed

random_polyagamma sometimes hangs in version 1.3.1 #102

macks22 opened this issue Aug 30, 2021 · 5 comments
Labels
random_polyagamma related to the random sampling function

Comments

@macks22
Copy link

macks22 commented Aug 30, 2021

Description of issue

The random_polyagamma function hangs without accepting a KeyboardInterrupt with some inputs in version 1.3.1.

Steps to reproduce:

Environment setup

On both OSX and Linux:

conda create -y -n pgsample -c conda-forge python=3.7 ipykernel pip
conda activate pgsample
pip install polyagamma==1.3.1

Run the following Python code, using the attached data. Execution hangs on the last line.

import pickle
import numpy as np
import polyagamma


psi = np.loadtxt("psi.txt")
state_keys = np.loadtxt("state_keys.txt")
state = ("MT19937", state_keys, 566, 0, 0.0)

random_state = np.random.RandomState()
random_state.set_state(state)

assert np.isnan(psi).sum() == 0
assert np.isinf(psi).sum() == 0
print(np.min(psi), np.max(psi))

n = np.ones(len(psi), dtype='float64')
out = polyagamma.random_polyagamma(n, psi, random_state=random_state._bit_generator)

state_keys.txt
psi.txt

@zoj613
Copy link
Owner

zoj613 commented Aug 30, 2021

Hi @macks22, I think this issue is the same as #83 , which has been resolved by #85. I cannot reproduce the example on v1.3.2-beta.3. I recommend you upgrade the version to the latest pre-release.

@zoj613
Copy link
Owner

zoj613 commented Aug 30, 2021

Also, I would replace n with a 1 literal to save the extra step of creating an array, It will be broadcasted with psi's shape internally.
change:

n = np.ones(len(psi), dtype='float64')
out = polyagamma.random_polyagamma(n, psi, random_state=random_state._bit_generator)

to

out = polyagamma.random_polyagamma(1, psi, random_state=random_state._bit_generator)

@zoj613 zoj613 added the random_polyagamma related to the random sampling function label Aug 30, 2021
@macks22
Copy link
Author

macks22 commented Aug 30, 2021

@zoj613 thanks for the fast response and the tips! In numpy==1.21.2, there is no publicly available bit_generator attribute on the numpy.random.RandomState object. I'm not sure when this was removed.

Is there a polyagamma version available via conda that has this fix incorporated? We are using polyagamma as part of a package which has the requirement that it must be conda-installable. This is a requirement for us in order to compatible with another package whose users are restricted to the use of conda for installation. Hence all of our dependencies must be conda-installable.

@zoj613
Copy link
Owner

zoj613 commented Aug 30, 2021

@zoj613 thanks for the fast response and the tips! In numpy==1.21.2, there is no publicly available bit_generator attribute on the numpy.random.RandomState object. I'm not sure when this was removed.

Is there a polyagamma version available via conda that has this fix incorporated? We are using polyagamma as part of a package which has the requirement that it must be conda-installable. This is a requirement for us in order to compatible with another package whose users are restricted to the use of conda for installation. Hence all of our dependencies must be conda-installable.

Oh yeah, that was my mistake. The public bit_generator is only available for the np.random.Generator class as per scikit-learn/scikit-learn#20669 (comment). The version on conda is the latest v1.3.2b3, so it should satisfy your project requirements, see here.

@macks22
Copy link
Author

macks22 commented Aug 30, 2021

I've confirmed that this bug is resolved with the 1.3.2b3 version of polyagamma. Thanks @zoj613!

@macks22 macks22 closed this as completed Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
random_polyagamma related to the random sampling function
Projects
None yet
Development

No branches or pull requests

2 participants