is all the evaluation metric in here is used correctly? clc; clear; close all; % Set…
- User
is all the evaluation metric in here is used correctly?
clc; clear; close all;
% Set problem parameters NPop = 200; % Population size T = 200; % Number of iterations dim = 30; % Number of decision variables lb = zeros(1, dim); % Lower bound ub = ones(1, dim); % Upper bound num_runs = 2; % Number of runs for statistical evaluation
% Storage for metrics metrics_storage = struct('GD', zeros(num_runs, 1), ... 'IGD', zeros(num_runs, 1), ... 'Spacing', zeros(num_runs, 1), ... 'Spread', zeros(num_runs, 1), ... 'HV', zeros(num_runs, 1));
%% Run NSGA-II Multiple Times for run = 1:num_runs fprintf('Run #%d/%d\n', run, num_runs);
% Run NSGA-II [paretoFront, paretoSet] = NSGA2(NPop, T, lb, ub, dim);
% Get True Pareto Front true_pareto = get_true_pareto(); % Calculate metrics [metrics_storage.GD(run), ... metrics_storage.IGD(run), ... metrics_storage.Spacing(run), ... metrics_storage.Spread(run), ... metrics_storage.HV(run)] = calculate_metrics(paretoFront, true_pareto);end
% Calculate statistics metric_names = fieldnames(metrics_storage); for i = 1:length(metric_names) metric_values = metrics_storage.(metric_names{i}); fprintf('\n%s Statistics:\n', metric_names{i}); fprintf(' Best = %.4f\n', min(metric_values)); fprintf(' Worst = %.4f\n', max(metric_values)); fprintf(' Mean = %.4f\n', mean(metric_values)); fprintf(' Median = %.4f\n', median(metric_values)); fprintf(' Std Dev = %.4f\n', std(metric_values)); end
% Visualize results figure; boxplot([metrics_storage.GD, metrics_storage.IGD, ... metrics_storage.Spacing, metrics_storage.Spread, ... metrics_storage.HV], ... 'Labels', {'GD', 'IGD', 'Spacing', 'Spread', 'HV'}); title('Performance Metrics Distribution'); ylabel('Metric Value'); %}
%% Plot Results % Plot Pareto Front figure; plot(paretoFront(:,1), paretoFront(:,2), 'ro', 'MarkerSize', 6, 'MarkerFaceColor', 'r'); hold on; plot(true_pareto(:,1), true_pareto(:,2), 'b--', 'LineWidth', 1.5); xlabel('f1'); ylabel('f2'); title('Pareto Front for zdt2 using NSGA-II'); legend('Obtained Pareto Front', 'True Pareto Front'); grid on; hold off;
% Plot the results figure; plot(paretoFront(:,1), paretoFront(:,2), 'ro', 'DisplayName', 'NSGA-II'); xlabel('f1'); ylabel('f2'); title('NSGA-II Pareto Front for zdt2'); legend('show'); grid on;
function [paretoFront, paretoSet] = NSGA2(NPop, T, lb, ub, dim) % Initialize population pop = initialization(NPop, dim, ub, lb); fitness = evaluate_population(pop, @zdt2);
for gen = 1:T % Non-dominated sorting [fronts, ranks] = non_dominated_sort(fitness); % Create mating pool using binary tournament selection mating_pool = tournament_selection(pop, ranks, NPop); % Generate offspring using SBX crossover and polynomial mutation offspring = simulated_binary_crossover(mating_pool, dim, 20, 0.9); offspring = polynomial_mutation(offspring, 1/dim, 20); % Evaluate offspring offspring_fitness = evaluate_population(offspring, @zdt2); % Combine population and offspring comb_pop = [pop; offspring]; comb_fitness = [fitness; offspring_fitness]; % Non-dominated sorting on combined population [fronts, ~] = non_dominated_sort(comb_fitness); % Create new population [pop, fitness] = select_new_population(comb_pop, comb_fitness, fronts, NPop); % Display generation progress disp(['Generation #', num2str(gen), ' completed.']); end % Return last population as Pareto front paretoFront = fitness; paretoSet = pop; - Assistant
To evaluate whether the metrics in your script are used correctly, I'll walk through common evaluation metrics used for multi-objective optimization algorithms, such as NSGA-II, and see if they align with typical applications: