MCPcopy
hub / github.com/mne-tools/mne-python / check_random_state

Function check_random_state

mne/utils/check.py:207–225  ·  view source on GitHub ↗

Turn seed into a numpy.random.mtrand.RandomState instance. If seed is None, return the RandomState singleton used by np.random.mtrand. If seed is an int, return a new RandomState instance seeded with seed. If seed is already a RandomState instance, return it. Otherwise raise ValueEr

(seed)

Source from the content-addressed store, hash-verified

205
206# adapted from scikit-learn utils/validation.py
207def check_random_state(seed):
208 """Turn seed into a numpy.random.mtrand.RandomState instance.
209
210 If seed is None, return the RandomState singleton used by np.random.mtrand.
211 If seed is an int, return a new RandomState instance seeded with seed.
212 If seed is already a RandomState instance, return it.
213 Otherwise raise ValueError.
214 """
215 if seed is None or seed is np.random:
216 return np.random.mtrand._rand
217 if isinstance(seed, int | np.integer):
218 return np.random.mtrand.RandomState(seed)
219 if isinstance(seed, np.random.mtrand.RandomState):
220 return seed
221 if isinstance(seed, np.random.Generator):
222 return seed
223 raise ValueError(
224 f"{seed!r} cannot be used to seed a numpy.random.mtrand.RandomState instance"
225 )
226
227
228def _check_event_id(event_id, events):

Callers 15

test_checkFunction · 0.90
_cortex_parcellationFunction · 0.85
select_sourcesFunction · 0.85
_get_drop_indicesFunction · 0.85
bootstrapFunction · 0.85
random_permutationFunction · 0.85
_fitMethod · 0.85
infomaxFunction · 0.85
_compute_mxne_sureFunction · 0.85
power_iteration_kronFunction · 0.85
permutation_t_testFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_checkFunction · 0.72