From 1b7d88acfef112a2417b29a725f69aaf53553a30 Mon Sep 17 00:00:00 2001 From: Servon Date: Tue, 27 Oct 2020 18:22:44 +0800 Subject: [PATCH] add comments --- zoopt/algos/opt_algorithms/racos/racos_classification.py | 4 ++-- zoopt/algos/opt_algorithms/racos/sracos.py | 4 ++-- zoopt/dimension.py | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zoopt/algos/opt_algorithms/racos/racos_classification.py b/zoopt/algos/opt_algorithms/racos/racos_classification.py index fb300e1..bead4c5 100644 --- a/zoopt/algos/opt_algorithms/racos/racos_classification.py +++ b/zoopt/algos/opt_algorithms/racos/racos_classification.py @@ -162,12 +162,12 @@ def mixed_classification(self): len_negative = len(self.__negative_solution) index_set = list(range(self.__solution_space.get_size())) remain_index_set = list(range(self.__solution_space.get_size())) - types = self.__solution_space.get_types() + types = self.__solution_space.get_types() # continuous, discrete, grid order_or_precision = self.__solution_space.get_order_or_precision() while len_negative > 0: if len(remain_index_set) == 0: ToolFunction.log('ERROR: sampled two same solutions, please raise issues on github') - k = remain_index_set[np.random.randint(0, len(remain_index_set))] + k = remain_index_set[np.random.randint(0, len(remain_index_set))] # randomly choose a index k x_pos_k = self.__x_positive.get_x_index(k) # continuous diff --git a/zoopt/algos/opt_algorithms/racos/sracos.py b/zoopt/algos/opt_algorithms/racos/sracos.py index 3e6feba..88df0e3 100755 --- a/zoopt/algos/opt_algorithms/racos/sracos.py +++ b/zoopt/algos/opt_algorithms/racos/sracos.py @@ -307,13 +307,13 @@ def sample_solution(self, ub=1): :return: a solution containing trial """ sampled_data = self._positive_data + self._negative_data - if np.random.random() < self._parameter.get_probability(): + if np.random.random() < self._parameter.get_probability(): # exploitation classifier = RacosClassification( self._objective.get_dim(), self._positive_data, self._negative_data, ub) classifier.mixed_classification() solution, distinct_flag = self.distinct_sample_classifier( classifier, sampled_data, True, self._parameter.get_train_size()) - else: + else: # exploration solution, distinct_flag = self.distinct_sample(self._objective.get_dim(), sampled_data) return solution, distinct_flag diff --git a/zoopt/dimension.py b/zoopt/dimension.py index d74081d..755249e 100644 --- a/zoopt/dimension.py +++ b/zoopt/dimension.py @@ -247,7 +247,8 @@ def __init__(self, dim_list=[]): self._size = len(dim_list) self._regions = list(map(lambda x: x[1], dim_list)) self._types = list(map(lambda x: x[0], dim_list)) - self._order_or_precision = list(map(lambda x: x[2] if len(x) == 3 else None, dim_list)) + self._order_or_precision = list(map(lambda x: x[2] if len(x) == 3 else None, + dim_list)) # Note: for grid valuetype, len(x)=2 for _dim in dim_list: if _dim[0] == ValueType.CONTINUOUS: