# 需要导入模块: 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)