Copulas icon indicating copy to clipboard operation
Copulas copied to clipboard

Update random state implementation

Open katxiao opened this issue 3 years ago • 0 comments

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 avatar Feb 10 '22 19:02 katxiao