def dissimilarity(self, other, c=(5, 5, 5, 1, 5, 1)): """ The distance/dissimilarity of two genomes, similar to NEAT dist = (c0*S + c1*D + c2*E)/N + c3*T + c4*K + c5*X where S sum of difference in same genes D number of disjoint genes E number of excess genes N length of larger gene T difference in optimizer + hyperparameters K mean of difference in same nodes X difference in trained epochs """ genes_1, genes_2 = map(lambda x: x.genes_by_id, [self, other]) ids_1, ids_2 = map(lambda x: set(x.keys()), [genes_1, genes_2]) nodes_1, nodes_2 = map(lambda x: x.nodes_by_id, [self, other]) node_ids = set(nodes_1.keys()) & set(nodes_2.keys()) N = 1 # TODO: max(len(ids_1), len(ids_2)) excess_start = max(ids_1 | ids_2) + 1 S = sum([ genes_1[_id].dissimilarity(genes_2[_id]) for _id in ids_1 & ids_2 ]) D = len([_id for _id in ids_1 ^ ids_2 if _id < excess_start]) E = len(ids_1 ^ ids_2) - D T = self.optimizer.dissimilarity(other.optimizer) K = sum([nodes_1[_id].dissimilarity(nodes_2[_id]) for _id in node_ids]) / len(node_ids) X = limited_growth(np.abs(self.trained - other.trained), 1, 10) return (c[0] * S + c[1] * D + c[2] * E) / N + c[3] * T + c[4] * K + c[5] * X
def dissimilarity(self, other): if not isinstance(other, self.__class__): return 1 dist = np.array([ self.size_change - other.size_change, self.activation != other.activation ]) importance = np.array([0.6, 0.4]) relevance = np.array([80, 0.01]) return np.sum(limited_growth(np.abs(dist), importance, relevance))
def dissimilarity(self, other): if not isinstance(other, self.__class__): return 1 dist = np.array([ self.height - other.height, self.width - other.width, self.stride - other.stride, self.padding - other.padding, self.pooling != other.pooling ]) importance = np.array([0.2, 0.2, 0.1, 0.1, 0.4]) relevance = np.array([5, 5, 3, 3, 0.01]) return np.sum(limited_growth(np.abs(dist), importance, relevance))
def dissimilarity(self, other): if type(other) != ADAMGene: return 1 dist = np.array([ self.log_learning_rate - other.log_learning_rate, self.log_weight_decay - other.log_weight_decay ]) importance = np.array([0.8, 0.2]) relevance = np.array([5, 3]) return np.sum(limited_growth(np.abs(dist), importance, relevance))
def dissimilarity(self, other): if not isinstance(other, self.__class__): return 1 dist = np.array([ self.height - other.height, self.width - other.width, self.stride - other.stride, self.padding - other.padding, self.depth_size_change - other.depth_size_change, self.depth_mult - other.depth_mult ]) importance = np.array([0.2, 0.2, 0.1, 0.05, 0.1, 0.35]) relevance = np.array([5, 5, 3, 3, 5, 8]) return np.sum(limited_growth(np.abs(dist), importance, relevance))