in LA-MCTS/lamcts/Classifier.py [0:0]
def propose_rand_samples_probe(self, nums_samples, path, lb, ub):
seed = np.random.randint(int(1e6))
sobol = SobolEngine(dimension = self.dims, scramble=True, seed=seed)
center = np.mean(self.X, axis = 0)
#check if the center located in the region
ratio, tmp = self.get_sample_ratio_in_region( np.reshape(center, (1, len(center) ) ), path )
if ratio == 0:
print("==>center not in the region, using random samples")
return self.propose_rand_samples(nums_samples, lb, ub)
# it is possible that the selected region has no points,
# so we need check here
axes = len( center )
final_L = []
for axis in range(0, axes):
L = np.zeros( center.shape )
L[axis] = 0.01
ratio = 1
while ratio >= 0.9:
L[axis] = L[axis]*2
if L[axis] >= (ub[axis] - lb[axis]):
break
lb_ = np.clip( center - L/2, lb, ub )
ub_ = np.clip( center + L/2, lb, ub )
cands_ = sobol.draw(10000).to(dtype=torch.float64).cpu().detach().numpy()
cands_ = (ub_ - lb_)*cands_ + lb_
ratio, tmp = self.get_sample_ratio_in_region(cands_, path )
final_L.append( L[axis] )
final_L = np.array( final_L )
lb_ = np.clip( center - final_L/2, lb, ub )
ub_ = np.clip( center + final_L/2, lb, ub )
print("center:", center)
print("final lb:", lb_)
print("final ub:", ub_)
count = 0
cands = np.array([])
while len(cands) < 10000:
count += 10000
cands = sobol.draw(count).to(dtype=torch.float64).cpu().detach().numpy()
cands = (ub_ - lb_)*cands + lb_
ratio, cands = self.get_sample_ratio_in_region(cands, path)
samples_count = len( cands )
#extract candidates
return cands