def train(self):
    print('\n\n===== Evolution ====')
    start_evolution_time = time.time()
    while (self.cycles > 0):
        sample = []
        sample_accs = []
        while (len(sample) < self.sample_size):
            candidate = np.random.randint(0, len(self.population))
            sample.append(self.population[candidate])
            sample_accs.append(self.accuracies[candidate])
        (max_sample_acc_index, max_sample_acc) = self._get_best_individual_accuracy(sample_accs)
        parent = sample[max_sample_acc_index]
        child = parent.copy()
        child = self._mutate_individual(child)
        child_actions = self._construct_action([child])
        gnn = self.form_gnn_info(child_actions[0])
        (_, child_acc) = self.submodel_manager.train(gnn, format=self.args.format)
        print('parent: ', str(parent), ' val_score: ', str(max_sample_acc), '| child: ', str(child), ', val_score: ', str(child_acc))
        self.accuracies.append(child_acc)
        self.population.append(child)
        if ((self.cycles % self.args.eval_cycle) == 0):
            self.derive_from_population()
        self.population.popleft()
        self.accuracies.popleft()
        print('[POPULATION STATS] Mean/Median/Best: ', np.mean(self.accuracies), np.median(self.accuracies), np.max(self.accuracies))
        self.cycles -= 1
    end_evolution_time = time.time()
    total_evolution_time = (end_evolution_time - start_evolution_time)
    print(('Time spent on evolution: ' + str(total_evolution_time)))
    print(('Total elapsed time: ' + str((total_evolution_time + self.init_time))))
    print('===== Evolution DONE ====')
def train(self):
    print('\n\n===== Evolution ====')
    start_evolution_time = time.time()
    while (self.cycles > 0):
        sample = []
        sample_accs = []
        while (len(sample) < self.sample_size):
            candidate = np.random.randint(0, len(self.population))
            sample.append(self.population[candidate])
            sample_accs.append(self.accuracies[candidate])
        (max_sample_acc_index, max_sample_acc) = self._get_best_individual_accuracy(sample_accs)
        parent = sample[max_sample_acc_index]
        child = parent.copy()
        child = self._mutate_individual(child)
        child_actions = self._construct_action([child])
        gnn = self.form_gnn_info(child_actions[0])
        (_, child_acc) = self.submodel_manager.train(gnn, format=self.args.format)
        print('parent: ', str(parent), ' val_score: ', str(max_sample_acc), '| child: ', str(child), ', val_score: ', str(child_acc))
        self.accuracies.append(child_acc)
        self.population.append(child)
        if ((self.cycles % self.args.eval_cycle) == 0):
            self.derive_from_population()
        self.population.popleft()
        self.accuracies.popleft()
        print('[POPULATION STATS] Mean/Median/Best: ', np.mean(self.accuracies), np.median(self.accuracies), np.max(self.accuracies))
        self.cycles -= 1
    end_evolution_time = time.time()
    total_evolution_time = (end_evolution_time - start_evolution_time)
    print(('Time spent on evolution: ' + str(total_evolution_time)))
    print(('Total elapsed time: ' + str((total_evolution_time + self.init_time))))
    print('===== Evolution DONE ====')