def __init__(self, fitness, temperature): all_indices = range(52) all_Z = [ 3, 4, 5, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 55, 56, 57, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83 ] self._Z_dict = dict(zip(all_indices, all_Z)) self._reverse_dict = dict(zip(all_Z, all_indices)) self._db = M_Database() self._fitness = fitness self._temp = temperature self._exclusions = get_excluded_list()
class FitnessEvaluator(): def __init__(self, fitness, temperature): all_indices = range(52) all_Z = [ 3, 4, 5, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 55, 56, 57, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83 ] self._Z_dict = dict(zip(all_indices, all_Z)) self._reverse_dict = dict(zip(all_Z, all_indices)) self._db = M_Database() self._fitness = fitness self._temp = temperature self._exclusions = get_excluded_list() def array_to_score(self, genome): genome = self.convert_raw_to_Z(genome) gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind = self._db.get_data( genome[0], genome[1], genome[2]) if self._fitness.__name__ == "eval_fitness_simple_exclusion": if genome in self._exclusions: return 0 return eval_fitness_simple(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) if self._fitness.__name__ == "eval_fitness_complex_exclusion": if genome in self._exclusions: return 0 return eval_fitness_complex(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) if self._fitness.__name__ == "eval_fitness_complex_product_exclusion": if genome in self._exclusions: return 0 return eval_fitness_complex_product(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) raw_fit = self._fitness(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) # scaled_fit = math.exp(raw_fit/self._temp) return raw_fit def convert_Z_to_raw(self, array): # note that we are representing as A, X, B to get symmetry between A & B A = self._reverse_dict[array[0]] B = self._reverse_dict[array[2]] X = array[1] return (A, B, X) def convert_raw_to_Z(self, array): # note that we are representing as A, X, B to get symmetry between A & B A = self._Z_dict[array[0]] B = self._Z_dict[array[2]] X = array[1] return (A, B, X)
def __init__(self, fitness, temperature): all_indices = range(52) all_Z = [3, 4, 5, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 55, 56, 57, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83] self._Z_dict = dict(zip(all_indices, all_Z)) self._reverse_dict = dict(zip(all_Z, all_indices)) self._db = M_Database() self._fitness = fitness self._temp = temperature self._exclusions = get_excluded_list()
class FitnessEvaluator(): def __init__(self, fitness, temperature): all_indices = range(52) all_Z = [3, 4, 5, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 55, 56, 57, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83] self._Z_dict = dict(zip(all_indices, all_Z)) self._reverse_dict = dict(zip(all_Z, all_indices)) self._db = M_Database() self._fitness = fitness self._temp = temperature self._exclusions = get_excluded_list() def array_to_score(self, genome): genome = self.convert_raw_to_Z(genome) gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind = self._db.get_data(genome[0], genome[1], genome[2]) if self._fitness.__name__ == "eval_fitness_simple_exclusion": if genome in self._exclusions: return 0 return eval_fitness_simple(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) if self._fitness.__name__ == "eval_fitness_complex_exclusion": if genome in self._exclusions: return 0 return eval_fitness_complex(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) if self._fitness.__name__ == "eval_fitness_complex_product_exclusion": if genome in self._exclusions: return 0 return eval_fitness_complex_product(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) raw_fit = self._fitness(gap_dir, gap_ind, heat, vb_dir, cb_dir, vb_ind, cb_ind) # scaled_fit = math.exp(raw_fit/self._temp) return raw_fit def convert_Z_to_raw(self, array): # note that we are representing as A, X, B to get symmetry between A & B A = self._reverse_dict[array[0]] B = self._reverse_dict[array[2]] X = array[1] return (A, B, X) def convert_raw_to_Z(self, array): # note that we are representing as A, X, B to get symmetry between A & B A = self._Z_dict[array[0]] B = self._Z_dict[array[2]] X = array[1] return (A, B, X)