Skip to content

Commit

Permalink
support for initial samples in SRacosTune
Browse files Browse the repository at this point in the history
  • Loading branch information
Servon committed Dec 31, 2020
1 parent e2bcfd8 commit 9086d73
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions zoopt/algos/opt_algorithms/racos/racos_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self):
self._data = []
# Save solutions with distinct x for tune init
self._init_data = []
self._need_copy = True
# self._positive_data are best-positive_size solutions set
self._positive_data = []
# self._negative_data are the other solutions
Expand Down Expand Up @@ -154,6 +155,24 @@ def tune_init_attribute(self):
:return: sample x
"""
self._parameter.set_negative_size(self._parameter.get_train_size() - self._parameter.get_positive_size())
if self._need_copy:
self._data_temp = copy.deepcopy(self._parameter.get_init_samples())
self._need_copy = False
self._iteration_num = self._parameter.get_train_size()
if self._data_temp is not None and self._best_solution is None:
size = min(len(self._data_temp), self._iteration_num)
if size > 0:
if isinstance(self._data_temp[0], Solution) is False:
x = self._objective.construct_solution(self._data_temp[0])
else:
x = self._data_temp[0]
del self._data_temp[0]
self._iteration_num -= 1
self._init_data.append(x)
if math.isnan(x.get_value()):
return x, True
else:
return self.tune_init_attribute()
x, distinct_flag = self.distinct_sample(self._objective.get_dim(), self._init_data, data_num=1)
if distinct_flag:
self._init_data.append(x)
Expand Down

0 comments on commit 9086d73

Please sign in to comment.