mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(100), termination_criterion=StoppingByEvaluations(max=max_evaluations) ) algorithm.observable.register(observer=ProgressBarObserver(max=max_evaluations)) algorithm.run() front = algorithm.get_result() label = algorithm.get_name() + "." + problem.get_name() # Plot front plot_front = Plot(plot_title='Pareto front approximation', reference_front=problem.reference_front, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Plot interactive front plot_front = InteractivePlot(plot_title='Pareto front approximation', reference_front=problem.reference_front, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print('Algorithm (continuous problem): ' + algorithm.get_name()) print('Problem: ' + problem.get_name()) print('Computing time: ' + str(algorithm.total_computing_time))
reference_point=reference_point)) algorithm.run() front = algorithm.get_result() # Plot front plot_front = Plot(title='Pareto front approximation. Problem: ' + problem.get_name(), reference_front=problem.reference_front, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Plot interactive front plot_front = InteractivePlot( title='Pareto front approximation. Problem: ' + problem.get_name(), reference_front=problem.reference_front, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print('Algorithm (continuous problem): ' + algorithm.get_name()) print('Problem: ' + problem.get_name()) print('Computing time: ' + str(algorithm.total_computing_time))
def train(self): problem = Ejemplo(X=self.Xtrain, Y=self.Ytrain, kernel=self.kernel, gamma=self.gamma, degree=self.degree, C=self.C, coef0=self.coef0) #problem.reference_front = read_solutions(filename='resources/reference_front/ZDT1.pf') max_evaluations = self.maxEvaluations algorithm = NSGAII( problem=problem, population_size=self.popsize, offspring_population_size=self.popsize, mutation=BitFlipMutation(probability=1.0 / np.shape(self.Xtrain)[0]), crossover=SPXCrossover(probability=1.0), termination_criterion=StoppingByEvaluations(max=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) #algorithm.observable.register(observer=VisualizerObserver(reference_front=problem.reference_front)) algorithm.run() front = algorithm.get_result() # Plot front plot_front = Plot(plot_title='Pareto front approximation', reference_front=None, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Plot interactive front plot_front = InteractivePlot(plot_title='Pareto front approximation', axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print('Algorithm (continuous problem): ' + algorithm.get_name()) # Get normalized matrix of results normed_matrix = normalize( list(map(lambda result: result.objectives, front))) # Get the sum of each objective results and select the best (min) scores = list(map(lambda item: sum(item), normed_matrix)) solution = front[scores.index(min(scores))] self.instances = solution.variables[0] self.attributes = solution.variables[1] # Generate masks # Crop by characteristics and instances X = self.Xtrain[self.instances, :] X = X[:, self.attributes] Y = self.Ytrain[self.instances] self.model = SVC(gamma=self.gamma, C=self.C, degree=self.degree, kernel=self.kernel) self.model.fit(X=X, y=Y) # write your code here return self.model
aggregative_function=Tschebycheff( dimension=problem.number_of_objectives), neighbor_size=20, neighbourhood_selection_probability=0.9, max_number_of_replaced_solutions=2, weight_files_path='resources/MOEAD_weights', termination_criterion=StoppingByEvaluations(max=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) algorithm.observable.register(observer=VisualizerObserver( reference_front=problem.reference_front, display_frequency=1000)) algorithm.run() front = algorithm.get_result() # Plot interactive front plot_front = InteractivePlot(plot_title='Pareto front approximation', reference_front=problem.reference_front, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print('Algorithm (continuous problem): ' + algorithm.get_name()) print('Problem: ' + problem.get_name()) print('Computing time: ' + str(algorithm.total_computing_time))
def train(self): problem = SVM_Problem(X=self.Xtrain, Y=self.Ytrain) #problem.reference_front = read_solutions(filename='resources/reference_front/ZDT1.pf') max_evaluations = self.maxEvaluations algorithm = NSGAII( problem=problem, population_size=self.popsize, offspring_population_size=self.popsize, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), termination_criterion=StoppingByEvaluations(max=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) #algorithm.observable.register(observer=VisualizerObserver(reference_front=problem.reference_front)) algorithm.run() front = algorithm.get_result() # Plot front plot_front = Plot(plot_title='Pareto front approximation', reference_front=None, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Plot interactive front plot_front = InteractivePlot(plot_title='Pareto front approximation', axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label, filename=algorithm.get_name()) # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print('Algorithm (continuous problem): ' + algorithm.get_name()) print( "-----------------------------------------------------------------------------" ) print('Problem: ' + problem.get_name()) print('Computing time: ' + str(algorithm.total_computing_time)) # Get normalized matrix of results normed_matrix = normalize( list(map(lambda result: result.objectives, front))) # Get the sum of each objective results and select the best (min) scores = list(map(lambda item: sum(item), normed_matrix)) solution = front[scores.index(min(scores))] # Get our variables self.gamma = solution.variables[0] self.C = solution.variables[1] self.coef0 = solution.variables[2] self.degree = solution.variables[3] self.kernel = solution.variables[4] self.instances = solution.masks[0] self.attributes = solution.masks[1] # Select pick a random array with length of the variable X = self.Xtrain[self.instances, :] X = X[:, self.attributes] Y = self.Ytrain[self.instances] print(*front, sep=", ") # Contruct model self.model = SVM(Xtrain=X, Ytrain=Y, kernel=self.kernel, C=self.C, degree=self.degree, coef0=self.coef0, gamma=self.gamma, seed=self.seed).train() print('Objectives: ', *solution.objectives, sep=", ") # write your code here return self.model