plot1 for multiple trials

This commit is contained in:
2026-03-17 12:21:14 -07:00
parent e77b05bc0f
commit 8c3b853895
2 changed files with 59 additions and 47 deletions

View File

@@ -43,7 +43,7 @@ for ii = 1:length(simHists)
if length(alphaDist2) > 1 if length(alphaDist2) > 1
alphaDist2 = alphaDist2(1); alphaDist2 = alphaDist2(1);
end end
if doubleIntegrator(ii) && unique(alphaDist(:, ii)) == alphaDist2 && numObjective(ii) == 1 if doubleIntegrator(ii) && all(alphaDist(1:n(ii), ii) == alphaDist2) && numObjective(ii) == 1
a2betaIdx = ii; a2betaIdx = ii;
a2beta = struct("init", init, "hist", hist.out); a2beta = struct("init", init, "hist", hist.out);
end end
@@ -52,47 +52,57 @@ end
commsRadius = unique(commsRadius); assert(isscalar(commsRadius)); commsRadius = unique(commsRadius); assert(isscalar(commsRadius));
collisionRadius = unique(collisionRadius); assert(isscalar(collisionRadius)); collisionRadius = unique(collisionRadius); assert(isscalar(collisionRadius));
sensors = flip(unique(alphaDist(1, :))); sensors = flip(unique(alphaDist(1, :)));
n_unique = sort(unique(n));
nGroups = length(n_unique);
config = []; % Build config label for each run
for ii = 1:length(simHists) config = strings(nRuns, 1);
% number of agents baseConfig = strings(nRuns, 1);
s = num2str(n(ii)); for ii = 1:nRuns
s = "";
% number of objectives
if numObjective(ii) == 1 if numObjective(ii) == 1
s = strcat(s, "_A"); s = s + "A";
elseif numObjective(ii) == 2 elseif numObjective(ii) == 2
s = strcat(s, "_B"); s = s + "B";
end end
% sensor pararmeter set
if alphaDist(1, ii) == sensors(1) if alphaDist(1, ii) == sensors(1)
s = strcat(s, "_I"); s = s + "_I";
elseif alphaDist(1, ii) == sensors(2) elseif alphaDist(1, ii) == sensors(2)
s = strcat(s, "_II"); s = s + "_II";
end end
% agent dynamics
if ~doubleIntegrator(ii) if ~doubleIntegrator(ii)
s = strcat(s, '_alpha'); s = s + "_alpha";
elseif doubleIntegrator(ii) else
s = strcat(s, '_beta'); s = s + "_beta";
end end
config = [config; s]; baseConfig(ii) = s;
config(ii) = n(ii) + "_" + s;
end end
configOrder = unique(baseConfig(n == n_unique(1)), 'stable');
nConfigsPerN = length(configOrder);
%% %%
close all; close all;
f1 = figure; f1 = figure;
x1 = axes; x1 = axes;
n_unique = sort(unique(n)); C_mean = NaN(nGroups, nConfigsPerN);
C = []; C_var = NaN(nGroups, nConfigsPerN);
for ii = 1:length(n_unique) for ii = 1:nGroups
nIdx = n == n_unique(ii); for jj = 1:nConfigsPerN
C = [C; [Cfinal(nIdx)]']; mask = (n == n_unique(ii)) & (baseConfig == configOrder(jj));
C_mean(ii, jj) = mean(Cfinal(mask));
C_var(ii, jj) = var(Cfinal(mask));
end
end end
bar(C);
hBar = bar(x1, C_mean);
hold(x1, 'on');
for jj = 1:nConfigsPerN
xPos = hBar(jj).XEndPoints;
errorbar(x1, xPos, C_mean(:, jj), C_var(:, jj), 'k.', 'LineWidth', 1, 'HandleVisibility', 'off');
end
hold(x1, 'off');
set(x1, 'XTickLabel', string(n_unique)); set(x1, 'XTickLabel', string(n_unique));
xlabel("Number of agents"); xlabel("Number of agents");
ylabel("Final coverage (normalized)"); ylabel("Final coverage (normalized)");
@@ -105,10 +115,8 @@ ylim([0, 1/2]);
f2 = figure; f2 = figure;
x2 = axes; x2 = axes;
% Compute pairwise distances between agents in each column of positions
% cell array
% Compute pairwise distances between agents % Compute pairwise distances between agents
maxPairs = nchoosek(6, 2); % 15 pairs for max 6 agents maxPairs = nchoosek(6, 2);
pairDist = cell(maxPairs, nRuns); pairDist = cell(maxPairs, nRuns);
for ii = 1:nRuns for ii = 1:nRuns
pp = 0; pp = 0;
@@ -140,25 +148,25 @@ for ii = 1:nRuns
maxPairDist(ii) = max(D); maxPairDist(ii) = max(D);
end end
% Group pairwise distance stats by n-value (same layout as bar plot) % Group pairwise distance stats by (n, config), aggregating across reps
nConfigs = nRuns / length(n_unique); meanD = NaN(nGroups, nConfigsPerN);
meanD = NaN(length(n_unique), nConfigs); minD = NaN(nGroups, nConfigsPerN);
minD = NaN(length(n_unique), nConfigs); maxD = NaN(nGroups, nConfigsPerN);
maxD = NaN(length(n_unique), nConfigs); for ii = 1:nGroups
for ii = 1:length(n_unique) for jj = 1:nConfigsPerN
idx = find(n == n_unique(ii)); mask = (n == n_unique(ii)) & (baseConfig == configOrder(jj));
meanD(ii, :) = meanPairDist(idx)'; meanD(ii, jj) = mean(meanPairDist(mask));
minD(ii, :) = minPairDist(idx)'; minD(ii, jj) = min(minPairDist(mask));
maxD(ii, :) = maxPairDist(idx)'; maxD(ii, jj) = max(maxPairDist(mask));
end
end end
% Plot whiskers (min to max) with mean markers % Plot whiskers (min to max) with mean markers
nGroups = length(n_unique);
barWidth = 0.8; barWidth = 0.8;
groupWidth = barWidth / nConfigs; groupWidth = barWidth / nConfigsPerN;
hold(x2, 'on'); hold(x2, 'on');
for jj = 1:nConfigs for jj = 1:nConfigsPerN
xPos = (1:nGroups) + (jj - (nConfigs + 1) / 2) * groupWidth; xPos = (1:nGroups) + (jj - (nConfigsPerN + 1) / 2) * groupWidth;
errorbar(x2, xPos, meanD(:, jj), meanD(:, jj) - minD(:, jj), maxD(:, jj) - meanD(:, jj), ... errorbar(x2, xPos, meanD(:, jj), meanD(:, jj) - minD(:, jj), maxD(:, jj) - meanD(:, jj), ...
'o', 'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 10); 'o', 'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 10);
end end

View File

@@ -11,7 +11,7 @@ classdef results < matlab.unittest.TestCase
%% Diagnostic Parameters %% Diagnostic Parameters
% No effect on simulation dynamics % No effect on simulation dynamics
makeVideo = false; % disable video writing for big performance increase makeVideo = false; % disable video writing for big performance increase
makePlots = true; % disable plotting for big performance increase (also disables video) makePlots = false; % disable plotting for big performance increase (also disables video)
plotCommsGeometry = false; % disable plotting communications geometries plotCommsGeometry = false; % disable plotting communications geometries
%% Scenario Reinitialization %% Scenario Reinitialization
@@ -49,9 +49,13 @@ classdef results < matlab.unittest.TestCase
config = results.makeConfigs(); config = results.makeConfigs();
end end
methods (TestClassSetup) properties (MethodSetupParameter)
function setSeed(tc) trials = struct('r1', 1, 'r2', 2, 'r3', 3, 'r4', 4, 'r5', 5);
rng(tc.seed); end
methods (TestMethodSetup)
function setSeed(tc, trials)
rng(tc.seed + trials);
end end
end end