plots 3 and 4

This commit is contained in:
2026-03-16 19:22:31 -07:00
parent 6b74347411
commit e77b05bc0f
7 changed files with 166 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
clear; clear;
% Load data % Load data
dataPath = fullfile('.', 'sandbox', 'plot1_3'); dataPath = fullfile('.', 'sandbox', 'plot1');
simHists = dir(dataPath); simHists = simHists(3:end); simHists = dir(dataPath); simHists = simHists(3:end);
simInits = simHists(endsWith({simHists.name}, 'miSimInits.mat')); simInits = simHists(endsWith({simHists.name}, 'miSimInits.mat'));
simHists = simHists(endsWith({simHists.name}, 'miSimHist.mat')); simHists = simHists(endsWith({simHists.name}, 'miSimHist.mat'));
@@ -99,7 +99,7 @@ ylabel("Final coverage (normalized)");
title("Final performance of parameterizations"); title("Final performance of parameterizations");
legend(["$AI\alpha$"; "$AI\beta$"; "$AII\alpha$"; "$BI\beta$"], "Interpreter", "latex", "Location", "northwest"); legend(["$AI\alpha$"; "$AI\beta$"; "$AII\alpha$"; "$BI\beta$"], "Interpreter", "latex", "Location", "northwest");
grid("on"); grid("on");
ylim([0, 1]); ylim([0, 1/2]);
%% %%
f2 = figure; f2 = figure;
@@ -120,6 +120,14 @@ for ii = 1:nRuns
end end
end end
% Cap pairwise distances at communications range
for ii = 1:nRuns
nPairs = nchoosek(n(ii), 2);
for pp = 1:nPairs
pairDist{pp, ii} = min(pairDist{pp, ii}, commsRadius);
end
end
% Compute mean, min, max pairwise distance across all pairs and timesteps per run % Compute mean, min, max pairwise distance across all pairs and timesteps per run
meanPairDist = NaN(nRuns, 1); meanPairDist = NaN(nRuns, 1);
minPairDist = NaN(nRuns, 1); minPairDist = NaN(nRuns, 1);
@@ -164,19 +172,4 @@ grid(x2, "on");
yline(collisionRadius, 'r--', "Label", "Collision Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off"); yline(collisionRadius, 'r--', "Label", "Collision Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off");
yline(commsRadius, 'r--', "Label", "Communications Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off"); yline(commsRadius, 'r--', "Label", "Communications Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off");
ylim([0, commsRadius + 5]);
ylim([0, inf]);
f3 = figure;
x3 = axes;
assert(size(a2beta.init.objectivePos, 1) == 1)
assert(a2beta.hist.useDoubleIntegrator);
assert(a2beta.hist.agent(1).sensor.alphaDist == sensors(2))
plot(a2beta.hist.perf./a2beta.init.objectiveIntegral);
hold("on");
for ii = 1:length(a2beta.hist.agent)
plot(a2beta.hist.agent(ii).perf./a2beta.init.objectiveIntegral);
end
grid("on");
xlabel("Performance");

133
plot_3.m Normal file
View File

@@ -0,0 +1,133 @@
clear;
% Load data
dataPath = fullfile('.', 'sandbox', 'plot3');
simHists = dir(dataPath); simHists = simHists(3:end);
simInits = simHists(endsWith({simHists.name}, 'miSimInits.mat'));
simHists = simHists(endsWith({simHists.name}, 'miSimHist.mat'));
assert(length(simHists) == length(simInits), "input data availability mismatch");
assert(isscalar(simHists));
init = fullfile(simInits(1).folder, simInits(1).name);
hist = fullfile(simHists(1).folder, simHists(1).name);
init = load(init);
hist = load(hist);
hist = hist.out;
f3 = figure;
x3 = axes;
assert(size(init.objectivePos, 1) == 1)
assert(hist.useDoubleIntegrator);
plot(hist.perf./init.objectiveIntegral);
hold("on");
for ii = 1:length(hist.agent)
plot(hist.agent(ii).perf./init.objectiveIntegral);
end
grid("on");
ylabel("Performance (normalized)");
xlabel("Timestep");
legend(["Cumulative"; "Agent 1"; "Agent 2"; "Agent 3"; "Agent 4"], "Location", "northwest");
title("$AII\beta$ Performance", "Interpreter", "latex");
f4 = figure;
x4 = axes;
% Compute pairwise distances between agents over time
nAgents = length(hist.agent);
commsRadius = hist.agent(1).commsRadius;
collisionRadius = hist.agent(1).collisionRadius;
nPairs = nchoosek(nAgents, 2);
T = size(hist.agent(1).pos, 1);
pairDistMat = NaN(T, nPairs);
pp = 0;
for jj = 1:nAgents-1
for kk = jj+1:nAgents
pp = pp + 1;
pairDistMat(:, pp) = vecnorm(hist.agent(jj).pos - hist.agent(kk).pos, 2, 2);
end
end
% Cap at communications range
% pairDistMat = min(pairDistMat, commsRadius);
% Plot all pairwise distances over time
hold(x4, 'on');
hLeft = gobjects(nPairs, 1);
for pp = 1:nPairs
hLeft(pp) = plot(x4, pairDistMat(:, pp), 'LineWidth', 1);
end
yline(x4, collisionRadius, 'r--', "Label", "Collision Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off");
yline(x4, commsRadius, 'r--', "Label", "Communications Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off");
hold(x4, 'off');
xlabel(x4, "Timestep");
ylabel(x4, "Pairwise distance");
title(x4, "$AII\beta$ Pairwise Agent Distances and Barrier Function Values", "Interpreter", "latex");
grid(x4, "on");
ylim(x4, [0, commsRadius + 5]);
% Build legend labels
pairLabels = strings(nPairs, 1);
pp = 0;
for jj = 1:nAgents-1
for kk = jj+1:nAgents
pp = pp + 1;
pairLabels(pp) = sprintf("Agents %d-%d Distance", jj, kk);
end
end
% Left legend created after right-axis plots (see below)
% Plot all barrier function values on right Y-axis
nObs = init.numObstacles;
nAA = nchoosek(nAgents, 2);
nAO = nAgents * nObs;
nAD = nAgents * 6;
nComms = size(hist.barriers, 1) - nAA - nAO - nAD;
yyaxis(x4, 'right');
hold(x4, 'on');
% Color palettes: pairs share colors across collision/comms,
% agents share colors across obstacle/domain
pairColors = lines(nAA);
agentColors = lines(nAgents);
% Row offsets in hist.barriers
colStart = 1;
obsStart = colStart + nAA;
domStart = obsStart + nAO;
comStart = domStart + nAD;
% Collision + Comms barriers grouped per pair (same color)
hRight = gobjects(0, 1);
rightLabels = strings(0, 1);
for pp = 1:nAA
hRight(end+1) = plot(x4, hist.barriers(colStart + pp - 1, :), '--', 'LineWidth', 1, 'Color', pairColors(pp, :));
rightLabels(end+1) = sprintf('h_{col} %d', pp);
end
for pp = 1:nComms
hRight(end+1) = plot(x4, hist.barriers(comStart + pp - 1, :), '-', 'LineWidth', 1.5, 'Color', pairColors(pp, :));
rightLabels(end+1) = sprintf('h_{com} %d', pp);
end
% Obstacle barriers colored by agent
idx = obsStart;
for aa = 1:nAgents
for oo = 1:nObs
hRight(end+1) = plot(x4, hist.barriers(idx, :), ':', 'LineWidth', 1, 'Color', agentColors(aa, :));
rightLabels(end+1) = sprintf('h_{obs} a%d-o%d', aa, oo);
idx = idx + 1;
end
end
hold(x4, 'off');
ylabel(x4, "Barrier function $h$", "Interpreter", "latex");
% Clamp both Y-axes to start at 0
yyaxis(x4, 'left'); ylim(x4, [0, 25]);
yyaxis(x4, 'right'); ylim(x4, [0, inf]);
x4.YAxis(2).Color = 'k';
% Combined legend
legend([hLeft(:); hRight(:)], [pairLabels(:); rightLabels(:)], "Location", "eastoutside");

View File

@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Info location="plot1.m" type="File"/> <Info location="plot_1.m" type="File"/>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="plot_3.m" type="File"/>

View File

@@ -59,21 +59,21 @@ classdef results < matlab.unittest.TestCase
function c = makeConfigs() function c = makeConfigs()
rng(results.seed); rng(results.seed);
abMin = 6; % alpha*beta >= 6 ensures membership(0) = tanh(3) >= 0.995 abMin = 6; % alpha*beta >= 6 ensures membership(0) = tanh(3) >= 0.995
alphaDist = rand(1, 2) .* [75, 40]; alphaDist = rand(1, 2) .* [75, 45];
betaDist = abMin ./ alphaDist + rand(1, 2) .* (20 - abMin ./ alphaDist); betaDist = abMin ./ alphaDist + rand(1, 2) .* [1, 1/8] .* (20 - abMin ./ alphaDist);
alphaTilt = 10 + rand(1, 2) .* [20, 20]; alphaTilt = 10 + rand(1, 2) .* [20, 20];
betaTilt = abMin ./ alphaTilt + rand(1, 2) .* (50 - abMin ./ alphaTilt); betaTilt = abMin ./ alphaTilt + rand(1, 2) .* (50 - abMin ./ alphaTilt);
sensors = struct('alphaDist', num2cell(alphaDist), 'alphaTilt', num2cell(alphaTilt), 'betaDist', num2cell(betaDist), 'betaTilt', num2cell(betaTilt)); sensors = struct('alphaDist', num2cell(alphaDist), 'alphaTilt', num2cell(alphaTilt), 'betaDist', num2cell(betaDist), 'betaTilt', num2cell(betaTilt));
% sensor1 = sigmoidSensor; sensor1 = sigmoidSensor;
% sensor2 = sigmoidSensor; sensor2 = sigmoidSensor;
% sensor1 = sensor1.initialize(sensors(1).alphaDist, sensors(1).betaDist, sensors(1).alphaTilt, sensors(1).betaTilt); sensor1 = sensor1.initialize(sensors(1).alphaDist, sensors(1).betaDist, sensors(1).alphaTilt, sensors(1).betaTilt);
% sensor2 = sensor2.initialize(sensors(2).alphaDist, sensors(2).betaDist, sensors(2).alphaTilt, sensors(2).betaTilt); sensor2 = sensor2.initialize(sensors(2).alphaDist, sensors(2).betaDist, sensors(2).alphaTilt, sensors(2).betaTilt);
% sensor1.plotParameters; sensor1.plotParameters;
% sensor2.plotParameters; sensor2.plotParameters;
c = struct('A_1_alpha', struct('objectivePos', [3, 1] / 4 .* results.domainSize(1:2), 'sensor', sensors(1), 'doubleIntegrator', false), ... c = struct('A_1_alpha', struct('objectivePos', [3, 1] / 4 .* results.domainSize(1:2), 'sensor', sensors(1), 'doubleIntegrator', false), ...
'A_1_beta', struct('objectivePos', [3, 1] / 4 .* results.domainSize(1:2), 'sensor', sensors(1), 'doubleIntegrator', true), ... 'A_1_beta', struct('objectivePos', [3, 1] / 4 .* results.domainSize(1:2), 'sensor', sensors(1), 'doubleIntegrator', true), ...
'A_2_alpha', struct('objectivePos', [3, 1] / 4 .* results.domainSize(1:2), 'sensor', sensors(2), 'doubleIntegrator', false), ... 'A_2_alpha', struct('objectivePos', [3, 1] / 4 .* results.domainSize(1:2), 'sensor', sensors(2), 'doubleIntegrator', false), ...
'B_1_beta', struct('objectivePos', [[3, 1] / 4 .* results.domainSize(1:2); [3, 1] / 4 .* results.domainSize(1:2) + 12.5 .* [-1, 1] ./ sqrt(2)], 'sensor', sensors(1), 'doubleIntegrator', true)); 'B_1_beta', struct('objectivePos', [[3, 1] / 4 .* results.domainSize(1:2); [3, 1] / 4 .* results.domainSize(1:2) + 25 .* [-1, 1] ./ sqrt(2)], 'sensor', sensors(1), 'doubleIntegrator', true));
end end
end end
@@ -267,10 +267,13 @@ classdef results < matlab.unittest.TestCase
end end
function AIIbeta_plots_3_4(tc) function AIIbeta_plots_3_4(tc)
% test-specific parameters % test-specific parameters
tc.makePlots = true;
tc.makeVideo = true;
maxIters = 400; maxIters = 400;
configs = results.makeConfigs(); configs = results.makeConfigs();
c = configs.A_2_alpha; c = configs.A_2_alpha;
c.doubleIntegrator = true; % make a2alpha into a2beta
% Set up fixed-size domain % Set up fixed-size domain
minAlt = tc.domainSize(3)/10 + rand * 1/10 * tc.domainSize(3); minAlt = tc.domainSize(3)/10 + rand * 1/10 * tc.domainSize(3);