-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added random_state option for MF algo and CoClustering to controle
randomization. Also moved get_rng() in utils.py
- Loading branch information
1 parent
936b809
commit 9a6c673
Showing
9 changed files
with
166 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'''The utils module contains the get_rng function.''' | ||
|
||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
import numbers | ||
|
||
import numpy as np | ||
|
||
|
||
def get_rng(random_state): | ||
'''Return a 'validated' RNG. | ||
If random_state is None, use RandomState singleton from numpy. Else if | ||
it's an integer, consider it's a seed and initialized an rng with that | ||
seed. If it's already an rng, return it. | ||
''' | ||
if random_state is None: | ||
return np.random.mtrand._rand | ||
elif isinstance(random_state, (numbers.Integral, np.integer)): | ||
return np.random.RandomState(random_state) | ||
if isinstance(random_state, np.random.RandomState): | ||
return random_state | ||
raise ValueError('Wrong random state. Expecting None, an int or a numpy ' | ||
'RandomState instance, got a ' | ||
'{}'.format(type(random_state))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.