From 5898ecce07b3081e0c5c5c7c7875b700c8d82898 Mon Sep 17 00:00:00 2001 From: Kevin D Date: Mon, 24 Nov 2025 22:27:40 -0800 Subject: [PATCH] added performance plot legend, rolling normalization --- @miSim/plotPerformance.m | 8 ++++++++ @miSim/updatePlots.m | 16 +++++++++------- test/test_miSim.m | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/@miSim/plotPerformance.m b/@miSim/plotPerformance.m index 2e293ca..5a9c635 100644 --- a/@miSim/plotPerformance.m +++ b/@miSim/plotPerformance.m @@ -24,5 +24,13 @@ function obj = plotPerformance(obj) hold(obj.fPerf.Children(1), 'off'); end + % Add legend + agentStrings = repmat("Agent %d", size(obj.perf, 1) - 1, 1); + for ii = 1:size(agentStrings, 1) + agentStrings(ii) = sprintf(agentStrings(ii), ii); + end + agentStrings = ["Total"; agentStrings]; + legend(obj.fPerf.Children(1), agentStrings, 'Location', 'northwest'); + obj.performancePlot = o; end \ No newline at end of file diff --git a/@miSim/updatePlots.m b/@miSim/updatePlots.m index f7631c3..0c64610 100644 --- a/@miSim/updatePlots.m +++ b/@miSim/updatePlots.m @@ -40,13 +40,15 @@ function [obj] = updatePlots(obj, updatePartitions) % Update performance plot if updatePartitions + % find index corresponding to the current time nowIdx = [0; obj.partitioningTimes] == obj.t; - % set(obj.performancePlot(1), 'YData', obj.perf(end, 1:find(nowIdx))); - obj.performancePlot(1).YData(nowIdx) = obj.perf(end, nowIdx); - for ii = 2:size(obj.performancePlot, 1) - obj.performancePlot(ii).YData(nowIdx) = obj.perf(ii, nowIdx); - end - drawnow; - end + nowIdx = find(nowIdx); + % Re-normalize performance plot + normalizingFactor = 1/max(obj.perf(end, 1:nowIdx)); + obj.performancePlot(1).YData(1:nowIdx) = obj.perf(end, 1:nowIdx) * normalizingFactor; + for ii = 2:size(obj.performancePlot, 1) + obj.performancePlot(ii).YData(1:nowIdx) = obj.perf(ii - 1, 1:nowIdx) * normalizingFactor; + end + end end \ No newline at end of file diff --git a/test/test_miSim.m b/test/test_miSim.m index 813a602..8a53890 100644 --- a/test/test_miSim.m +++ b/test/test_miSim.m @@ -104,7 +104,7 @@ classdef test_miSim < matlab.unittest.TestCase if ii == 1 while agentsCrowdObjective(tc.domain.objective, candidatePos, mean(tc.domain.dimensions) / 2) candidatePos = tc.domain.random(); - candidatePos(3) = 2 + rand * 2; % place agents at decent altitudes for sensing + candidatePos(3) = 2 + rand * 1.5; % place agents at decent altitudes for sensing end else candidatePos = tc.agents{randi(ii - 1)}.pos + sign(randn([1, 3])) .* (rand(1, 3) .* tc.comRange/sqrt(2));