def __init__(self, problem, num_of_generations, num_of_individuals): self.utils = NSGA2Utils(problem, num_of_individuals) self.population = None self.num_of_generations = num_of_generations self.on_generation_finished = [] self.num_of_individuals = num_of_individuals
def __init__(self, problem, num_of_generations, num_of_individuals): print("Initializing Evolution Process Elements") self.utils = NSGA2Utils(problem, num_of_individuals) self.population = None self.num_of_generations = num_of_generations #"""200 How much the Genetic Algo goes one for""" self.on_generation_finished = [] self.num_of_individuals = num_of_individuals #"""200 How many Chromosomes"""
def __init__(self, problem, num_of_generations=1000, num_of_individuals=100, num_of_tour_particips=2, tournament_prob=0.9, p_c=0.6, p_m=0.3, p_risked=0.5, full=True): """ Attributes ---------- utils : NSGA2Utils class of utile functions population : Population population class num_of_generations : int number of generations num_of_individuals : int population size problem : Problem problem definition class num_of_tour_particips : int number of indivisuals per selection tournament tournament_prob : float paramters in binary selection tournament (not used for now) p_c : float crossover probability p_m : float mutaion probability p_risked : float probability of doing the crossover on the risky assets full : boolean True: cross over on the whole portfolio , False : cross over on a part of the portfolio """ self.utils = NSGA2Utils(problem, num_of_individuals, num_of_tour_particips, tournament_prob, p_c, p_m, p_risked, full) self.population = None self.num_of_generations = num_of_generations self.on_generation_finished = [] self.num_of_individuals = num_of_individuals self.problem = problem
def __init__(self, problem, evolutions_df, dataset_name, protected_variable,num_of_generations=5, num_of_individuals=10, num_of_tour_particips=2, tournament_prob=0.9, crossover_param=2, mutation_param=5, mutation_prob=0.3, beta_method="uniform"): self.utils = NSGA2Utils(problem, num_of_individuals, num_of_tour_particips, tournament_prob, crossover_param, mutation_param, mutation_prob, beta_method) self.population = None self.evolutions_df = evolutions_df self.dataset_name = dataset_name self.protected_variable = protected_variable self.num_of_generations = num_of_generations self.on_generation_finished = [] self.num_of_individuals = num_of_individuals self.mutation_prob = mutation_prob self.beta_method = beta_method
def __init__(self, problem, vardim, iteration, num_of_generations, num_of_individuals, mutation_prob, num_of_genes_to_mutate, num_of_tour_particips): self.utils = NSGA2Utils(problem, vardim, num_of_generations, num_of_individuals, mutation_prob, num_of_genes_to_mutate, num_of_tour_particips) self.population = None self.vardim = vardim self.iteration = iteration self.num_of_generations = num_of_generations self.on_generation_finished = [] self.num_of_individuals = num_of_individuals
def __init__(self, problem, num_of_generations=1000, num_of_individuals=100, num_of_tour_particips=2, tournament_prob=0.9, crossover_param=2, mutation_param=5): self.utils = NSGA2Utils(problem, num_of_individuals, num_of_tour_particips, tournament_prob, crossover_param, mutation_param) self.population = None self.num_of_generations = num_of_generations self.on_generation_finished = [] self.num_of_individuals = num_of_individuals
def init_population(self, portfolio_size, N, Q, Q_rfa, C): """ Parameters ---------- portfolio_size : int number of risky assets N : int population size Q : float quantity limit for risky assets C : int cardinality limit Q_rfa : float quantity limit for RFA Returns ------- list list of individuals """ solutions = [] for i in range(N): if (np.all(self.initial_portfolio == None)): solution = [ 0 + (Q - 0) * np.random.random() for j in range(portfolio_size) ] solution.append(0 + (Q_rfa - 0) * np.random.random()) else: solution = self.initial_portfolio solutions.append( NSGA2Utils.check_fix_solution(self, np.array(solution), portfolio_size, C, Q, Q_rfa)) return solutions
x = i children_test.append(x) #try to run a single generation newish_population = NSGAmethods.runNSGA_generation(pop_test, children_test, testProblemParameters) #stuff to set up the NSGA code's child creation proceedure problem = Problem(num_of_variables=1, objectives=[basic1, basic2], variables_range=[(LB[0], UB[0])]) num_of_individuals = populationSize num_of_tour_particips = 2 tournament_prob = 0.9 crossover_param = 2 mutation_param = 5 used_utils = NSGA2Utils(problem, num_of_individuals, num_of_tour_particips, tournament_prob, crossover_param, mutation_param) new_children_listOfIndividuals = used_utils.create_children(newish_population) numChildren = len(new_children_listOfIndividuals) #convert children a make them into a list of unevaluated arrays #doing this is painful #set up a loop and repeat until max generations for GenCounter in range(0, MaxGenerations): #step 1: combine parents and children into one population (which is technically done in runNSGA_generation) #STEP 1A: Convert the children from a list of individuals (which store evaluation information) #to a list of arrays (the way Gnowee store them) just containing their features GnoweeChildList = [] for childNum in range(0, numChildren): VarValue = new_children_listOfIndividuals[childNum].features[0] GnoweeChildList.append(VarValue)