本文整理汇总了Python中numpy.random.get_state方法的典型用法代码示例。如果您正苦于以下问题:Python random.get_state方法的具体用法?Python random.get_state怎么用?Python random.get_state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.random
的用法示例。
在下文中一共展示了random.get_state方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _real_init
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values):
self.randomstate = npr.get_state()
# Input dimensionality.
self.D = dims
# Initial length scales.
self.ls = np.ones(self.D)
# Initial amplitude.
self.amp2 = np.std(values)+1e-4
# Initial observation noise.
self.noise = 1e-3
# Initial mean.
self.mean = np.mean(values)
# Save hyperparameter samples
self.hyper_samples.append((self.mean, self.noise, self.amp2,
self.ls))
示例2: _real_init
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values, durations):
self.randomstate = npr.get_state()
# Identify constraint violations
# Note that we'll treat NaNs and Infs as these values as well
# as an optional user defined value
goodvals = np.nonzero(np.logical_and(values != self.bad_value,
np.isfinite(values)))[0]
# Input dimensionality.
self.D = dims
# Initial length scales.
self.ls = np.ones(self.D)
self.constraint_ls = np.ones(self.D)
# Initial amplitude.
self.amp2 = np.std(values[goodvals])+1e-4
self.constraint_amp2 = 1.0
# Initial observation noise.
self.noise = 1e-3
self.constraint_noise = 1e-3
self.constraint_gain = 1
# Initial mean.
self.mean = np.mean(values[goodvals])
self.constraint_mean = 0.5
示例3: save
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def save(self, path):
del self.params_gen
self.random_state = random.get_state()
super(RandomProposer, self).save(path)
示例4: _real_init
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values):
self.locker.lock_wait(self.state_pkl)
self.randomstate = npr.get_state()
if os.path.exists(self.state_pkl):
fh = open(self.state_pkl, 'r')
state = pickle.load(fh)
fh.close()
self.D = state['dims']
self.ls = state['ls']
self.amp2 = state['amp2']
self.noise = state['noise']
self.mean = state['mean']
self.hyper_samples = state['hyper_samples']
self.needs_burnin = False
else:
# Input dimensionality.
self.D = dims
# Initial length scales.
self.ls = np.ones(self.D)
# Initial amplitude.
self.amp2 = np.std(values)+1e-4
# Initial observation noise.
self.noise = 1e-3
# Initial mean.
self.mean = np.mean(values)
# Save hyperparameter samples
self.hyper_samples.append((self.mean, self.noise, self.amp2,
self.ls))
self.locker.unlock(self.state_pkl)
示例5: save_random_state
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def save_random_state():
state = get_state()
try:
yield
finally:
set_state(state)
示例6: __enter__
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def __enter__(self):
from numpy import random
self.startstate = random.get_state()
random.seed(self.seed)
示例7: local_seed
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def local_seed(seed):
state = random.get_state()
try:
random.seed(seed)
yield
finally:
random.set_state(state)
示例8: _real_init
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def _real_init(self, dims, values, durations):
self.locker.lock_wait(self.state_pkl)
self.randomstate = npr.get_state()
if os.path.exists(self.state_pkl):
fh = open(self.state_pkl, 'rb')
state = pickle.load(fh)
fh.close()
self.D = state['dims']
self.ls = state['ls']
self.amp2 = state['amp2']
self.noise = state['noise']
self.mean = state['mean']
self.constraint_ls = state['constraint_ls']
self.constraint_amp2 = state['constraint_amp2']
self.constraint_noise = state['constraint_noise']
self.constraint_mean = state['constraint_mean']
self.constraint_gain = state['constraint_gain']
self.needs_burnin = False
else:
# Identify constraint violations
# Note that we'll treat NaNs and Infs as these values as well
# as an optional user defined value
goodvals = np.nonzero(np.logical_and(values != self.bad_value,
np.isfinite(values)))[0]
# Input dimensionality.
self.D = dims
# Initial length scales.
self.ls = np.ones(self.D)
self.constraint_ls = np.ones(self.D)
# Initial amplitude.
self.amp2 = np.std(values[goodvals])+1e-4
self.constraint_amp2 = 1.0
# Initial observation noise.
self.noise = 1e-3
self.constraint_noise = 1e-3
self.constraint_gain = 1
# Initial mean.
self.mean = np.mean(values[goodvals])
self.constraint_mean = 0.5
self.locker.unlock(self.state_pkl)
示例9: preserve_random_state
# 需要导入模块: from numpy import random [as 别名]
# 或者: from numpy.random import get_state [as 别名]
def preserve_random_state(func):
""" Decorator to preserve the numpy.random state during a function.
Parameters
----------
func : function
function around which to preserve the random state.
Returns
-------
wrapper : function
Function which wraps the input function by saving the state before
calling the function and restoring the function afterward.
Examples
--------
Decorate functions like this::
@preserve_random_state
def do_random_stuff(x, y):
return x + y * numpy.random.random()
Notes
-----
If numpy.random is not importable, the state is not saved or restored.
"""
try:
from numpy.random import get_state, seed, set_state
@contextmanager
def save_random_state():
state = get_state()
try:
yield
finally:
set_state(state)
def wrapper(*args, **kwargs):
with save_random_state():
seed(1234567890)
return func(*args, **kwargs)
wrapper.__name__ = func.__name__
return wrapper
except ImportError:
return func