MCPcopy Create free account
hub / github.com/bayesian-optimization/BayesianOptimization / ensure_rng

Function ensure_rng

bayes_opt/util.py:8–30  ·  view source on GitHub ↗

Create a random number generator based on an optional seed. Parameters ---------- random_state : np.random.RandomState or int or None, default=None Random state to use. if `None`, will create an unseeded random state. If `int`, creates a state using the argument as seed.

(random_state: int | np.random.RandomState | None = None)

Source from the content-addressed store, hash-verified

6
7
8def ensure_rng(random_state: int | np.random.RandomState | None = None) -> np.random.RandomState:
9 """Create a random number generator based on an optional seed.
10
11 Parameters
12 ----------
13 random_state : np.random.RandomState or int or None, default=None
14 Random state to use. if `None`, will create an unseeded random state.
15 If `int`, creates a state using the argument as seed. If a
16 `np.random.RandomState` simply returns the argument.
17
18 Returns
19 -------
20 np.random.RandomState
21
22 """
23 if random_state is None:
24 random_state = np.random.RandomState()
25 elif isinstance(random_state, int):
26 random_state = np.random.RandomState(random_state)
27 elif not isinstance(random_state, np.random.RandomState):
28 error_msg = "random_state should be an instance of np.random.RandomState, an int, or None."
29 raise TypeError(error_msg)
30 return random_state

Callers 9

test_ensure_rngFunction · 0.90
random_sampleMethod · 0.90
__init__Method · 0.90
random_sampleMethod · 0.90
suggestMethod · 0.90
suggestMethod · 0.90
random_sampleMethod · 0.90
random_sampleMethod · 0.90
random_sampleMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_ensure_rngFunction · 0.72
random_sampleMethod · 0.72