コード例 #1
0
 def experiment_optimal_mimic(self):
     prob_length = 20
     fl = CustomProblem(prob_length, self.problem_type)
     problem = fl.create_problem()
     pop_size = 800
     rand_state = 42
     max_attempt = 100
     max_iter = 1000
     keep_pct = 0.1
     start = time.time()
     alg = Mimic(problem, rand_state, max_attempt, max_iter, pop_size,
                 keep_pct)
     best_fitness = alg.optimize()
     end = time.time()
     diff = abs(end - start)
     print('time taken for Mimic - Sixpeaks: ' + str(diff))
コード例 #2
0
    def experiment_mimic_1(self):
        prob_lengths = np.arange(7, 30)
        result = np.zeros((len(self.rand_seeds), len(prob_lengths)))
        pop_size = 200
        keep_pct = 0.1

        for i in range(len(self.rand_seeds)):
            rand_state = self.rand_seeds[i]
            for j in range(len(prob_lengths)):
                prob_length = prob_lengths[j]
                fl = CustomProblem(prob_length.item(), self.problem_type)
                problem = fl.create_problem()
                alg = Mimic(problem, rand_state, 10, 1000, pop_size, keep_pct)
                best_fitness = alg.optimize()
                result[i][j] = best_fitness

        print(str(result))
        avg_result = np.mean(result, axis=0)
        print('avg result for varying input size' + str(avg_result))
        title = self.problem_type + ' with mimic - Input Size Variation'
        plot_curve(prob_lengths, avg_result, title, 'Input Size', 'Best Score')
コード例 #3
0
    def experiment_mimic_5(self):
        keep_pcts = np.arange(0.1, 1, 0.1)
        result = np.zeros((len(self.rand_seeds), len(keep_pcts)))
        pop_size = 800
        max_iter = np.inf

        for i in range(len(self.rand_seeds)):
            rand_state = self.rand_seeds[i]
            for j in range(len(keep_pcts)):
                prob_length = 20
                fl = CustomProblem(prob_length, self.problem_type)
                problem = fl.create_problem()
                max_attempt = 200
                keep_pct = keep_pcts[j].item()
                alg = Mimic(problem, rand_state, max_attempt, max_iter,
                            pop_size, keep_pct)
                best_fitness = alg.optimize()
                result[i][j] = best_fitness

        avg_result = np.mean(result, axis=0)
        print('avg result ' + str(avg_result))
        title = self.problem_type + ' with Mimic - Keep PCT Variation'
        plot_curve(keep_pcts, avg_result, title, 'Keep PCT', 'Best Score')
コード例 #4
0
    def experiment_mimic_4(self):
        pop_sizes = np.arange(200, 1000, 200)
        result = np.zeros((len(self.rand_seeds), len(pop_sizes)))
        max_iter = np.inf
        keep_pct = 0.1

        for i in range(len(self.rand_seeds)):
            rand_state = self.rand_seeds[i]
            for j in range(len(pop_sizes)):
                prob_length = 20
                fl = CustomProblem(prob_length, self.problem_type)
                problem = fl.create_problem()
                max_attempt = 200
                pop_size = pop_sizes[j].item()
                alg = Mimic(problem, rand_state, max_attempt, max_iter,
                            pop_size, keep_pct)
                best_fitness = alg.optimize()
                result[i][j] = best_fitness

        avg_result = np.mean(result, axis=0)
        print('avg result ' + str(avg_result))
        title = self.problem_type + ' with Mimic - Population Size Variation'
        plot_curve(pop_sizes, avg_result, title, 'Population Size',
                   'Best Score')
コード例 #5
0
    def experiment_mimic_3(self):
        max_iters = np.arange(1000, 5000, 100)
        result = np.zeros((len(self.rand_seeds), len(max_iters)))
        pop_size = 800
        keep_pct = 0.6

        for i in range(len(self.rand_seeds)):
            rand_state = self.rand_seeds[i]
            for j in range(len(max_iters)):
                prob_length = 20
                fl = CustomProblem(prob_length, self.problem_type)
                problem = fl.create_problem()
                max_attempt = 200
                max_iter = max_iters[j].item()
                alg = Mimic(problem, rand_state, max_attempt, max_iter,
                            pop_size, keep_pct)
                best_fitness = alg.optimize()
                result[i][j] = best_fitness

        avg_result = np.mean(result, axis=0)
        print('avg result ' + str(avg_result))
        title = self.problem_type + ' with Mimic - Max Iterations Variation'
        plot_curve(max_iters, avg_result, title, 'Max Iterations',
                   'Best Score')
コード例 #6
0
 def experiment_mimc(self):
     fl = FlipFlop(7)
     problem = fl.create_problem()
     alg = Mimic(problem, 42, 10, 1000, 200, 0.1)
     alg.optimize()