From e77b05bc0ff470c9631747aede49c30f444c3ef6 Mon Sep 17 00:00:00 2001 From: Kevin D Date: Mon, 16 Mar 2026 19:22:31 -0700 Subject: [PATCH] plots 3 and 4 --- plot1.m => plot_1.m | 29 ++-- plot_3.m | 133 ++++++++++++++++++ ...d.xml => Dt-U7DFYhio-3hILJY9YWPnda6sd.xml} | 0 ...p.xml => Dt-U7DFYhio-3hILJY9YWPnda6sp.xml} | 2 +- .../e-EiR3xDuOjis31Xf2_ZV1uoriEd.xml | 6 + .../e-EiR3xDuOjis31Xf2_ZV1uoriEp.xml | 2 + test/results.m | 23 +-- 7 files changed, 166 insertions(+), 29 deletions(-) rename plot1.m => plot_1.m (91%) create mode 100644 plot_3.m rename resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/{JC_d3KqCGA6aeT3-SLjDi7YqGlkd.xml => Dt-U7DFYhio-3hILJY9YWPnda6sd.xml} (100%) rename resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/{JC_d3KqCGA6aeT3-SLjDi7YqGlkp.xml => Dt-U7DFYhio-3hILJY9YWPnda6sp.xml} (50%) create mode 100644 resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEd.xml create mode 100644 resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEp.xml diff --git a/plot1.m b/plot_1.m similarity index 91% rename from plot1.m rename to plot_1.m index a08e2f1..1e70e65 100644 --- a/plot1.m +++ b/plot_1.m @@ -1,6 +1,6 @@ clear; % Load data -dataPath = fullfile('.', 'sandbox', 'plot1_3'); +dataPath = fullfile('.', 'sandbox', 'plot1'); simHists = dir(dataPath); simHists = simHists(3:end); simInits = simHists(endsWith({simHists.name}, 'miSimInits.mat')); simHists = simHists(endsWith({simHists.name}, 'miSimHist.mat')); @@ -99,7 +99,7 @@ ylabel("Final coverage (normalized)"); title("Final performance of parameterizations"); legend(["$AI\alpha$"; "$AI\beta$"; "$AII\alpha$"; "$BI\beta$"], "Interpreter", "latex", "Location", "northwest"); grid("on"); -ylim([0, 1]); +ylim([0, 1/2]); %% f2 = figure; @@ -120,6 +120,14 @@ for ii = 1:nRuns 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 meanPairDist = 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(commsRadius, 'r--', "Label", "Communications Radius", "LabelHorizontalAlignment", "left", "HandleVisibility", "off"); - -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"); \ No newline at end of file +ylim([0, commsRadius + 5]); \ No newline at end of file diff --git a/plot_3.m b/plot_3.m new file mode 100644 index 0000000..a904290 --- /dev/null +++ b/plot_3.m @@ -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"); \ No newline at end of file diff --git a/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/JC_d3KqCGA6aeT3-SLjDi7YqGlkd.xml b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/Dt-U7DFYhio-3hILJY9YWPnda6sd.xml similarity index 100% rename from resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/JC_d3KqCGA6aeT3-SLjDi7YqGlkd.xml rename to resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/Dt-U7DFYhio-3hILJY9YWPnda6sd.xml diff --git a/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/JC_d3KqCGA6aeT3-SLjDi7YqGlkp.xml b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/Dt-U7DFYhio-3hILJY9YWPnda6sp.xml similarity index 50% rename from resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/JC_d3KqCGA6aeT3-SLjDi7YqGlkp.xml rename to resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/Dt-U7DFYhio-3hILJY9YWPnda6sp.xml index 9e808dc..ad26ca2 100644 --- a/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/JC_d3KqCGA6aeT3-SLjDi7YqGlkp.xml +++ b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/Dt-U7DFYhio-3hILJY9YWPnda6sp.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEd.xml b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEd.xml new file mode 100644 index 0000000..99772b4 --- /dev/null +++ b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEd.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEp.xml b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEp.xml new file mode 100644 index 0000000..6c72faf --- /dev/null +++ b/resources/project/qaw0eS1zuuY1ar9TdPn1GMfrjbQ/e-EiR3xDuOjis31Xf2_ZV1uoriEp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/results.m b/test/results.m index 396c9d5..7da16d3 100644 --- a/test/results.m +++ b/test/results.m @@ -59,21 +59,21 @@ classdef results < matlab.unittest.TestCase function c = makeConfigs() rng(results.seed); abMin = 6; % alpha*beta >= 6 ensures membership(0) = tanh(3) >= 0.995 - alphaDist = rand(1, 2) .* [75, 40]; - betaDist = abMin ./ alphaDist + rand(1, 2) .* (20 - abMin ./ alphaDist); + alphaDist = rand(1, 2) .* [75, 45]; + betaDist = abMin ./ alphaDist + rand(1, 2) .* [1, 1/8] .* (20 - abMin ./ alphaDist); alphaTilt = 10 + rand(1, 2) .* [20, 20]; betaTilt = abMin ./ alphaTilt + rand(1, 2) .* (50 - abMin ./ alphaTilt); sensors = struct('alphaDist', num2cell(alphaDist), 'alphaTilt', num2cell(alphaTilt), 'betaDist', num2cell(betaDist), 'betaTilt', num2cell(betaTilt)); - % sensor1 = sigmoidSensor; - % sensor2 = sigmoidSensor; - % 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); - % sensor1.plotParameters; - % sensor2.plotParameters; + sensor1 = sigmoidSensor; + sensor2 = sigmoidSensor; + 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); + sensor1.plotParameters; + sensor2.plotParameters; 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_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 @@ -105,7 +105,7 @@ classdef results < matlab.unittest.TestCase for ii = 1:numDist sig = [200, 140; 140, 280]; if ~mod(ii, 2) - sig = rot90(sig, 2); + sig = rot90(sig,2); end sig = reshape(sig, [1, 2, 2]); objectiveSigma = cat(1, objectiveSigma, sig); @@ -267,10 +267,13 @@ classdef results < matlab.unittest.TestCase end function AIIbeta_plots_3_4(tc) % test-specific parameters + tc.makePlots = true; + tc.makeVideo = true; maxIters = 400; configs = results.makeConfigs(); c = configs.A_2_alpha; + c.doubleIntegrator = true; % make a2alpha into a2beta % Set up fixed-size domain minAlt = tc.domainSize(3)/10 + rand * 1/10 * tc.domainSize(3);