refactored performance plot data storage
This commit is contained in:
@@ -25,8 +25,8 @@ function obj = run(obj, domain, partitioning, t)
|
|||||||
S(partitionMask) = sensorValues;
|
S(partitionMask) = sensorValues;
|
||||||
|
|
||||||
% Find agent's performance
|
% Find agent's performance
|
||||||
C = S.* F; % try gradient on this directly
|
C = S.* F;
|
||||||
obj.performance = [obj.performance sum(C(~isnan(C)))];
|
obj.performance = [obj.performance, sum(C(~isnan(C)))];
|
||||||
|
|
||||||
% Compute gradient on agent's performance
|
% Compute gradient on agent's performance
|
||||||
[gradSensorPerformanceX, gradSensorPerformanceY] = gradient(S, domain.objective.discretizationStep); % grad S_n
|
[gradSensorPerformanceX, gradSensorPerformanceY] = gradient(S, domain.objective.discretizationStep); % grad S_n
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ classdef miSim
|
|||||||
adjacency = NaN; % Adjacency matrix representing communications network graph
|
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
|
sensorPerformanceMinimum = 1e-6; % minimum sensor performance to allow assignment of a point in the domain to a partition
|
||||||
partitioning = NaN;
|
partitioning = NaN;
|
||||||
performance = NaN; % current cumulative sensor performance
|
performance = 0; % cumulative sensor performance
|
||||||
|
|
||||||
fPerf; % performance plot figure
|
fPerf; % performance plot figure
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,18 +24,4 @@ function obj = partition(obj)
|
|||||||
[m, n, ~] = size(agentInds);
|
[m, n, ~] = size(agentInds);
|
||||||
[jj, kk] = ndgrid(1:m, 1:n);
|
[jj, kk] = ndgrid(1:m, 1:n);
|
||||||
obj.partitioning = agentInds(sub2ind(size(agentInds), jj, kk, idx));
|
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
|
end
|
||||||
@@ -15,12 +15,14 @@ function obj = plotPerformance(obj)
|
|||||||
% Plot current cumulative performance
|
% Plot current cumulative performance
|
||||||
hold(obj.fPerf.Children(1), 'on');
|
hold(obj.fPerf.Children(1), 'on');
|
||||||
o = plot(obj.fPerf.Children(1), obj.perf(end, :));
|
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');
|
hold(obj.fPerf.Children(1), 'off');
|
||||||
|
|
||||||
% Plot current agent performance
|
% Plot current agent performance
|
||||||
for ii = 1:(size(obj.perf, 1) - 1)
|
for ii = 1:(size(obj.perf, 1) - 1)
|
||||||
hold(obj.fPerf.Children(1), 'on');
|
hold(obj.fPerf.Children(1), 'on');
|
||||||
o = [o; plot(obj.fPerf.Children(1), obj.perf(ii, :))];
|
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');
|
hold(obj.fPerf.Children(1), 'off');
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ function [obj] = run(obj)
|
|||||||
obj.agents{jj} = obj.agents{jj}.run(obj.domain, obj.partitioning, obj.t);
|
obj.agents{jj} = obj.agents{jj}.run(obj.domain, obj.partitioning, obj.t);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% Update total performance
|
||||||
|
obj.performance = [obj.performance, sum(cellfun(@(x) x.performance(end), obj.agents))];
|
||||||
|
|
||||||
% Update adjacency matrix
|
% Update adjacency matrix
|
||||||
obj = obj.updateAdjacency();
|
obj = obj.updateAdjacency();
|
||||||
|
|
||||||
|
|||||||
@@ -39,16 +39,12 @@ function [obj] = updatePlots(obj, updatePartitions)
|
|||||||
drawnow;
|
drawnow;
|
||||||
|
|
||||||
% Update performance plot
|
% Update performance plot
|
||||||
if updatePartitions
|
% Re-normalize performance plot
|
||||||
% find index corresponding to the current time
|
normalizingFactor = 1/max(obj.performance(end));
|
||||||
nowIdx = [0; obj.partitioningTimes] == obj.t;
|
obj.performancePlot(1).YData(1:length(obj.performance)) = obj.performance * normalizingFactor;
|
||||||
nowIdx = find(nowIdx);
|
obj.performancePlot(1).XData(find(isnan(obj.performancePlot(1).XData), 1, 'first')) = obj.t;
|
||||||
|
for ii = 2:(size(obj.agents, 1) + 1)
|
||||||
% Re-normalize performance plot
|
obj.performancePlot(ii).YData(1:length(obj.performance)) = obj.agents{ii - 1}.performance * normalizingFactor;
|
||||||
normalizingFactor = 1/max(obj.perf(end, 1:nowIdx));
|
obj.performancePlot(ii).XData(find(isnan(obj.performancePlot(ii).XData), 1, 'first')) = obj.t;
|
||||||
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
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user