refactored performance plot data storage

This commit is contained in:
2025-11-30 22:32:17 -08:00
parent 7c87458b66
commit f296fd2803
6 changed files with 15 additions and 28 deletions

View File

@@ -25,8 +25,8 @@ function obj = run(obj, domain, partitioning, t)
S(partitionMask) = sensorValues;
% Find agent's performance
C = S.* F; % try gradient on this directly
obj.performance = [obj.performance sum(C(~isnan(C)))];
C = S.* F;
obj.performance = [obj.performance, sum(C(~isnan(C)))];
% Compute gradient on agent's performance
[gradSensorPerformanceX, gradSensorPerformanceY] = gradient(S, domain.objective.discretizationStep); % grad S_n

View File

@@ -13,7 +13,7 @@ classdef miSim
adjacency = NaN; % Adjacency matrix representing communications network graph
sensorPerformanceMinimum = 1e-6; % minimum sensor performance to allow assignment of a point in the domain to a partition
partitioning = NaN;
performance = NaN; % current cumulative sensor performance
performance = 0; % cumulative sensor performance
fPerf; % performance plot figure
end

View File

@@ -24,18 +24,4 @@ function obj = partition(obj)
[m, n, ~] = size(agentInds);
[jj, kk] = ndgrid(1:m, 1:n);
obj.partitioning = agentInds(sub2ind(size(agentInds), jj, kk, idx));
% Get individual agent sensor performance
nowIdx = [0; obj.partitioningTimes] == obj.t;
if isnan(obj.t)
nowIdx = 1;
end
for ii = 1:size(obj.agents, 1)
idx = obj.partitioning == ii;
agentPerformance = squeeze(agentPerformances(:, :, ii));
obj.perf(ii, nowIdx) = sum(agentPerformance(idx) .* obj.objective.values(idx));
end
% Current total performance
obj.perf(end, nowIdx) = sum(obj.perf(1:(end - 1), nowIdx));
end

View File

@@ -15,12 +15,14 @@ function obj = plotPerformance(obj)
% Plot current cumulative performance
hold(obj.fPerf.Children(1), 'on');
o = plot(obj.fPerf.Children(1), obj.perf(end, :));
o.XData = NaN(size(o.XData)); % correct time will be set at runtime
hold(obj.fPerf.Children(1), 'off');
% Plot current agent performance
for ii = 1:(size(obj.perf, 1) - 1)
hold(obj.fPerf.Children(1), 'on');
o = [o; plot(obj.fPerf.Children(1), obj.perf(ii, :))];
o(end).XData = NaN(size(o(end).XData)); % correct time will be set at runtime
hold(obj.fPerf.Children(1), 'off');
end

View File

@@ -28,6 +28,9 @@ function [obj] = run(obj)
obj.agents{jj} = obj.agents{jj}.run(obj.domain, obj.partitioning, obj.t);
end
% Update total performance
obj.performance = [obj.performance, sum(cellfun(@(x) x.performance(end), obj.agents))];
% Update adjacency matrix
obj = obj.updateAdjacency();

View File

@@ -39,16 +39,12 @@ function [obj] = updatePlots(obj, updatePartitions)
drawnow;
% Update performance plot
if updatePartitions
% find index corresponding to the current time
nowIdx = [0; obj.partitioningTimes] == obj.t;
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
% Re-normalize performance plot
normalizingFactor = 1/max(obj.performance(end));
obj.performancePlot(1).YData(1:length(obj.performance)) = obj.performance * normalizingFactor;
obj.performancePlot(1).XData(find(isnan(obj.performancePlot(1).XData), 1, 'first')) = obj.t;
for ii = 2:(size(obj.agents, 1) + 1)
obj.performancePlot(ii).YData(1:length(obj.performance)) = obj.agents{ii - 1}.performance * normalizingFactor;
obj.performancePlot(ii).XData(find(isnan(obj.performancePlot(ii).XData), 1, 'first')) = obj.t;
end
end