def zad4(): import matplotlib.pyplot as plt import numpy as np go.reset_params() ut.reset_params() results = {} factory.set_type('floating_point') ut.n_features = 1 eGA.n_iter = 10000 f = 'f6' iters = {} for size in [30, 50, 100, 200]: go.population_size = size factory.set_function_to_minimize(f) for p in [0.1, 0.3, 0.6, 0.9]: key = f+'-p_size'+str(size) + '-p_mut-'+str(p) go.p_mutation = p results[key] = [] iters[key] = [] for i in range(n_tries): res, iter = eGA.minimize(n_iter_trace=True) results[key].append(abs(res.fitness)) iters[key].append(iter) #plotting iters res = [] iter_ = [] labels = [0.1, 0.3, 0.6, 0.9] for p in labels: size = 30 res.append(results[f+'-p_size'+str(size) + '-p_mut-'+str(p)]) iter_.append(iters[f+'-p_size'+str(size) + '-p_mut-'+str(p)]) plt.boxplot(res, labels=labels) plt.show()
def zad1(): go.reset_params() ut.reset_params() results = {'f1': [], 'f2': [], 'f6': [], 'f7': []} iters = {} factory.set_type('floating_point') for curr in results: factory.set_function_to_minimize(curr) ut.n_features = 5 if curr == 'f2' else 2 iters[curr] = [] for i in range(n_tries): res, iter = eGA.minimize(n_iter_trace=True) results[curr].append(abs(res.fitness)) iters[curr].append(iter)
def zad5(): go.reset_params() ut.reset_params() results = {} iters = {} factory.set_type('floating_point') for dim in [3,5,7]: go.tournament_size = dim for f in ['f6']: key = f+'-k'+str(dim) factory.set_function_to_minimize(f) results[key] = [] iters[key] = [] for i in range(n_tries): res, iter = eGA.minimize(n_iter_trace=True) results[key].append(abs(res.fitness)) iters[key].append(iter)
def zad2(): go.reset_params() ut.reset_params() results = {} factory.set_type('floating_point') iters = {} for dim in [1,3,6,10]: for f in ['f6', 'f7']: ut.n_features = dim key = f+'-d'+str(dim) factory.set_function_to_minimize(f) results[key] = [] iters[key] = [] for i in range(n_tries): res, iter = eGA.minimize(n_iter_trace=True) results[key].append(abs(res.fitness)) iters[key].append(iter)
def zad3(): results = {} iters = {} go.reset_params() ut.reset_params() ut.binary_n_bits = 32 for method in ['floating_point', 'binary']: factory.set_type(method) for dim in [3,6]: ut.n_features = dim for f in ['f6', 'f7']: ut.n_features = dim key = f+'-'+method+'-d'+str(dim) factory.set_function_to_minimize(f) results[key] = [] iters[key] = [] for i in range(n_tries): res, iter = eGA.minimize(n_iter_trace=True) results[key].append(abs(res.fitness)) iters[key].append(iter)