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

Update random state implementation #314

Open
katxiao opened this issue Feb 10, 2022 · 0 comments
Open

Update random state implementation #314

katxiao opened this issue Feb 10, 2022 · 0 comments
Labels
internal The issue doesn't change the API or functionality

Comments

@katxiao
Copy link
Contributor

katxiao commented Feb 10, 2022

Problem Description

Currently, we are fixing the random_state using a decorator that wraps around the desired functions (sample). This wrapper sets the global random state to the model's desired random state and then resets it after the function has completed.

Instead of setting and unsetting the global random state, we can pass this state through to the scipy functions being called and/or use this global state to execute random method calls.

For example, this sample function could be:

    def sample(self, n_samples=1):
        self.check_fit()
        return self.MODEL_CLASS.rvs(size=n_samples, random_state=self.random_state**self._params)

We can also change np.random library calls to be on the model's self.random_state.
For example:

self.random_state.rand()

Expected behavior

As a result of this change, the global random state (np.random.get_state()) will not be altered. The generated sample data should still follow the progression of the specified seed or random state.

@katxiao katxiao added the internal The issue doesn't change the API or functionality label Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal The issue doesn't change the API or functionality
Projects
None yet
Development

No branches or pull requests

1 participant