Plots here now
This commit is contained in:
@@ -0,0 +1,564 @@
|
||||
%% MPI reduction parallelization analysis from MpiReductionResults
|
||||
% A) Helper BER-over-SIR plots for first and last block_update.
|
||||
% B) Required SIR at FEC threshold over block_update.
|
||||
|
||||
clear; clc;
|
||||
|
||||
%% 1) Gather data
|
||||
|
||||
studyName = "block_update_sweep";
|
||||
pathLengthToPlot = 1000;
|
||||
selectedPamLevels = 6; % set [] to use all PAM levels in the query result
|
||||
selectedAlgorithms = []; % set [] to use all algorithms in the query result
|
||||
|
||||
useBoundedLines = true;
|
||||
usePolyfit = true;
|
||||
polyfitOrderMax = 4;
|
||||
boundaryPolyfitOrderMax = 4;
|
||||
fecBerThreshold = 3.8e-3;
|
||||
maxBerForPlot = 0.1;
|
||||
scatterKeepFraction = 0.2;
|
||||
boundMode = "fitStd"; % "fitStd" or "directStd"
|
||||
algorithmMarkers = {'o','square','diamond','^','v','>','<','pentagram'};
|
||||
|
||||
db = DBHandler( ...
|
||||
"dataBase", "labor", ...
|
||||
"type", "mysql", ...
|
||||
"server", "192.168.178.192", ...
|
||||
"user", "silas", ...
|
||||
"password", "silas");
|
||||
db.refresh();
|
||||
|
||||
fp = QueryFilter();
|
||||
fp.where('Runs', 'interference_path_length', 'EQUALS', pathLengthToPlot);
|
||||
fp.where('Runs', 'fiber_length', 'EQUALS', 0);
|
||||
fp.where('Runs', 'db_mode', 'EQUALS', '"no_db"');
|
||||
fp.where('MpiReductionResults', 'study_name', 'EQUALS', char(studyName));
|
||||
if isscalar(selectedPamLevels) && ~isempty(selectedPamLevels)
|
||||
fp.where('Runs', 'pam_level', 'EQUALS', selectedPamLevels);
|
||||
end
|
||||
|
||||
selectedFields = { ...
|
||||
'Runs.run_id', ...
|
||||
'Runs.sir', ...
|
||||
'Runs.pam_level', ...
|
||||
'Runs.symbolrate', ...
|
||||
'Runs.interference_path_length', ...
|
||||
'Runs.power_mpi_interference', ...
|
||||
'MpiReductionResults.occurrence_idx', ...
|
||||
'MpiReductionResults.storage_name', ...
|
||||
'MpiReductionResults.algorithm', ...
|
||||
'MpiReductionResults.algorithm_variant', ...
|
||||
'MpiReductionResults.eq_class', ...
|
||||
'MpiReductionResults.block_update', ...
|
||||
'MpiReductionResults.BER', ...
|
||||
'MpiReductionResults.BER_precoded', ...
|
||||
'MpiReductionResults.SNR', ...
|
||||
'MpiReductionResults.GMI', ...
|
||||
'MpiReductionResults.AIR'};
|
||||
selectedFields = selectedFields(:);
|
||||
|
||||
[rawData, query] = db.queryDB(fp, selectedFields);
|
||||
disp(query);
|
||||
fprintf("Fetched %d MPI reduction rows.\n", height(rawData));
|
||||
|
||||
%% 2) Clean data and calculate required SIR
|
||||
|
||||
data = rawData;
|
||||
numericFields = ["run_id", "sir", "pam_level", "symbolrate", ...
|
||||
"interference_path_length", "occurrence_idx", "block_update", ...
|
||||
"power_mpi_interference", "BER", "BER_precoded", "SNR", "GMI", "AIR"];
|
||||
for fieldIdx = 1:numel(numericFields)
|
||||
fieldName = numericFields(fieldIdx);
|
||||
if ismember(fieldName, string(data.Properties.VariableNames))
|
||||
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
|
||||
end
|
||||
end
|
||||
|
||||
stringFields = ["storage_name", "algorithm", "algorithm_variant", "eq_class"];
|
||||
for fieldIdx = 1:numel(stringFields)
|
||||
fieldName = stringFields(fieldIdx);
|
||||
if ismember(fieldName, string(data.Properties.VariableNames))
|
||||
data.(char(fieldName)) = stringColumn(data.(char(fieldName)));
|
||||
end
|
||||
end
|
||||
|
||||
data = data(isfinite(data.BER) & data.BER > 0 & data.BER < maxBerForPlot, :);
|
||||
data.sir_exact = -7 - data.power_mpi_interference;
|
||||
if isempty(data)
|
||||
warning("PLOT_mpi_reduction_db_parallelization_vs_sir:NoRows", ...
|
||||
"No rows remain after initial BER/path/study filtering.");
|
||||
return
|
||||
end
|
||||
|
||||
if isempty(selectedPamLevels)
|
||||
selectedPamLevels = unique(data.pam_level(isfinite(data.pam_level))).';
|
||||
else
|
||||
data = data(ismember(data.pam_level, selectedPamLevels), :);
|
||||
end
|
||||
|
||||
if isempty(selectedAlgorithms)
|
||||
selectedAlgorithms = unique(data.algorithm, "stable").';
|
||||
else
|
||||
selectedAlgorithms = string(selectedAlgorithms);
|
||||
data = data(ismember(data.algorithm, selectedAlgorithms), :);
|
||||
end
|
||||
|
||||
if isempty(data)
|
||||
warning("PLOT_mpi_reduction_db_parallelization_vs_sir:NoSelectedRows", ...
|
||||
"No rows remain after selectedPamLevels/selectedAlgorithms filtering.");
|
||||
return
|
||||
end
|
||||
|
||||
data.clean_keep = true(height(data), 1);
|
||||
groupId = findgroups(data.pam_level, data.algorithm, data.block_update, data.sir);
|
||||
for curGroup = unique(groupId(isfinite(groupId))).'
|
||||
rowMask = groupId == curGroup;
|
||||
berValues = data.BER(rowMask);
|
||||
if nnz(rowMask) > 3
|
||||
data.clean_keep(rowMask) = ~isoutlier(berValues);
|
||||
end
|
||||
end
|
||||
cleanData = data(data.clean_keep, :);
|
||||
|
||||
groupVars = ["pam_level", "algorithm", "block_update", "sir"];
|
||||
summaryTable = groupsummary(cleanData, groupVars, ...
|
||||
{"mean", "min", "max"}, "BER");
|
||||
sirExactTable = groupsummary(cleanData, groupVars, "median", "sir_exact");
|
||||
summaryTable = sortrows(summaryTable, groupVars);
|
||||
sirExactTable = sortrows(sirExactTable, groupVars);
|
||||
summaryTable.sir_exact = sirExactTable.median_sir_exact;
|
||||
summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars);
|
||||
|
||||
blockUpdates = unique(cleanData.block_update(isfinite(cleanData.block_update))).';
|
||||
blockUpdates = sort(blockUpdates);
|
||||
helperBlockUpdates = unique(blockUpdates([1, end]), "stable");
|
||||
|
||||
requiredSirRows = table();
|
||||
for pamIdx = 1:numel(selectedPamLevels)
|
||||
pamLevel = selectedPamLevels(pamIdx);
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
algorithmName = selectedAlgorithms(algIdx);
|
||||
for blockIdx = 1:numel(blockUpdates)
|
||||
blockUpdate = blockUpdates(blockIdx);
|
||||
curveMask = summaryTable.pam_level == pamLevel & ...
|
||||
summaryTable.algorithm == algorithmName & ...
|
||||
summaryTable.block_update == blockUpdate;
|
||||
|
||||
sirValues = summaryTable.sir_exact(curveMask).';
|
||||
meanBer = summaryTable.mean_BER(curveMask).';
|
||||
[~, ~, requiredSir, fitOrder] = fitBerAtFec( ...
|
||||
sirValues, meanBer, polyfitOrderMax, fecBerThreshold);
|
||||
|
||||
newRow = table(pamLevel, algorithmName, blockUpdate, ...
|
||||
requiredSir, fitOrder, nnz(isfinite(sirValues) & isfinite(meanBer)), ...
|
||||
'VariableNames', ["pam_level", "algorithm", "block_update", ...
|
||||
"required_sir", "fit_order", "n_points"]);
|
||||
requiredSirRows = [requiredSirRows; newRow]; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fprintf("Cleaned to %d rows across %d PAM/algorithm/block/SIR groups.\n", ...
|
||||
height(cleanData), height(summaryTable));
|
||||
disp(groupcounts(cleanData, ["pam_level", "algorithm", "block_update"]));
|
||||
disp(requiredSirRows);
|
||||
|
||||
%% 3A) Helper BER-over-SIR plots for first and last block updates
|
||||
|
||||
% tiledlayout(numel(selectedPamLevels), numel(helperBlockUpdates), ...
|
||||
% "TileSpacing", "compact");
|
||||
|
||||
for pamIdx = 1:numel(selectedPamLevels)
|
||||
pamLevel = selectedPamLevels(pamIdx);
|
||||
for helperIdx = 1:numel(helperBlockUpdates)
|
||||
figure(); clf;
|
||||
blockUpdate = helperBlockUpdates(helperIdx);
|
||||
nexttile; hold on;
|
||||
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
algorithmName = selectedAlgorithms(algIdx);
|
||||
algColor = algorithmColor(algorithmName);
|
||||
marker = algorithmMarker(algorithmName, algorithmMarkers);
|
||||
displayName = algorithmDisplayName(algorithmName);
|
||||
|
||||
rawMask = cleanData.pam_level == pamLevel & ...
|
||||
cleanData.algorithm == algorithmName & ...
|
||||
cleanData.block_update == blockUpdate;
|
||||
curveMask = summaryTable.pam_level == pamLevel & ...
|
||||
summaryTable.algorithm == algorithmName & ...
|
||||
summaryTable.block_update == blockUpdate;
|
||||
|
||||
if ~any(curveMask)
|
||||
continue
|
||||
end
|
||||
|
||||
scatterKeepFraction = 1;
|
||||
scatterRows = downsampleRows(cleanData(rawMask, :), scatterKeepFraction);
|
||||
scatter(scatterRows.sir_exact, scatterRows.BER, ...
|
||||
26, ...
|
||||
"Marker", ".", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"MarkerFaceColor", algColor, ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
sirValues = summaryTable.sir_exact(curveMask).';
|
||||
meanBer = summaryTable.mean_BER(curveMask).';
|
||||
boundCenterBer = summaryTable.std_center_BER(curveMask).';
|
||||
boundLowerBer = summaryTable.std_lower_BER(curveMask).';
|
||||
boundUpperBer = summaryTable.std_upper_BER(curveMask).';
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & meanBer > 0;
|
||||
|
||||
if useBoundedLines && exist("boundedline", "file") && any(valid)
|
||||
[xBand, centerBand, yBounds] = berStdBounds( ...
|
||||
sirValues, boundCenterBer, boundLowerBer, boundUpperBer, ...
|
||||
boundMode, boundaryPolyfitOrderMax);
|
||||
|
||||
[hl, hp] = boundedline(xBand, centerBand, yBounds, ...
|
||||
'alpha', 'transparency', 0.1, ...
|
||||
'cmap', algColor, ...
|
||||
'nan', 'fill', ...
|
||||
'orientation', 'vert');
|
||||
set(hl, "LineStyle", "none", 'LineWidth', 1, "Marker", "none", ...
|
||||
"HandleVisibility", "off", "DisplayName", char(displayName));
|
||||
set(hp, "LineStyle", "-", "HandleVisibility", "off", "Marker", "none");
|
||||
end
|
||||
|
||||
plot(sirValues(valid), meanBer(valid), ...
|
||||
"LineStyle", "-", ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 3, ...
|
||||
"LineWidth", 1, ...
|
||||
"Color", algColor, ...
|
||||
"MarkerFaceColor", "w", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"DisplayName", char(displayName), 'HandleVisibility', 'on');
|
||||
|
||||
if usePolyfit
|
||||
fitMask = valid & meanBer > 0;
|
||||
if nnz(fitMask) >= 2
|
||||
fitOrder = min(polyfitOrderMax, nnz(fitMask) - 1);
|
||||
fitCoeff = polyfit(sirValues(fitMask), log10(meanBer(fitMask)), fitOrder);
|
||||
xFit = linspace(min(sirValues(fitMask)), max(sirValues(fitMask)), 300);
|
||||
yFit = 10 .^ polyval(fitCoeff, xFit);
|
||||
|
||||
% plot(xFit, yFit, ...
|
||||
% "LineStyle", "--", ...
|
||||
% "LineWidth", 1.1, ...
|
||||
% "Color", algColor, ...
|
||||
% "HandleVisibility", "off");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
yline(2.2e-4, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
yline(fecBerThreshold, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
yline(2e-2, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
|
||||
title(sprintf("PAM %.0f, block update %.0f", pamLevel, blockUpdate));
|
||||
xlabel("SIR (dB)");
|
||||
ylabel("BER");
|
||||
set(gca, "YScale", "log");
|
||||
ylim([9e-5, 0.05]);
|
||||
xlim([15, 35]);
|
||||
grid on;
|
||||
box on;
|
||||
legend("Location", "northeast", "Interpreter", "none");
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, "setmarkers", false);
|
||||
end
|
||||
% mat2tikz_improved(sprintf("C:/Users/Silas/Documents/6971e0b65b380ca6d71c837f/04_Experimental_Evaluation/tikz/mpi/ber_vs_sir_blockupdate_v2_%d.tikz",blockUpdate));
|
||||
end
|
||||
end
|
||||
|
||||
%% 3B) Required SIR over block update
|
||||
|
||||
figure(); clf;
|
||||
tiledlayout(numel(selectedPamLevels), 1, "TileSpacing", "compact");
|
||||
|
||||
for pamIdx = 1:numel(selectedPamLevels)
|
||||
pamLevel = selectedPamLevels(pamIdx);
|
||||
nexttile; hold on;
|
||||
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
algorithmName = selectedAlgorithms(algIdx);
|
||||
algColor = algorithmColor(algorithmName);
|
||||
marker = algorithmMarker(algorithmName, algorithmMarkers);
|
||||
displayName = algorithmDisplayName(algorithmName);
|
||||
rowMask = requiredSirRows.pam_level == pamLevel & ...
|
||||
requiredSirRows.algorithm == algorithmName;
|
||||
|
||||
x = requiredSirRows.block_update(rowMask).';
|
||||
y = requiredSirRows.required_sir(rowMask).';
|
||||
[x, sortIdx] = sort(x);
|
||||
y = y(sortIdx);
|
||||
valid = isfinite(x) & isfinite(y);
|
||||
|
||||
if ~any(valid)
|
||||
continue
|
||||
end
|
||||
|
||||
plot(x(valid), y(valid), ...
|
||||
"LineWidth", 1.4, ...
|
||||
"LineStyle", "-", ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 5, ...
|
||||
"Color", algColor, ...
|
||||
"MarkerFaceColor", "w", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"DisplayName", char(displayName));
|
||||
end
|
||||
|
||||
set(gca, "XScale", "log");
|
||||
xticks(blockUpdates);
|
||||
xticklabels(string(blockUpdates));
|
||||
xlim([x(1) x(end)]);
|
||||
grid on;
|
||||
box on;
|
||||
xlabel("Parallelization / block update");
|
||||
ylabel(sprintf("Required SIR at BER = %.1e (dB)", fecBerThreshold));
|
||||
title(sprintf("PAM %.0f, path %.0f m", pamLevel, pathLengthToPlot));
|
||||
legend("Location","southeast", "Interpreter", "none");
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", false, "setcolors", false, "setmarkers", false);
|
||||
end
|
||||
end
|
||||
|
||||
%% Local helpers
|
||||
|
||||
function values = numericColumn(values)
|
||||
if iscell(values)
|
||||
values = string(values);
|
||||
end
|
||||
if isstring(values) || ischar(values)
|
||||
values = str2double(values);
|
||||
end
|
||||
values = double(values);
|
||||
end
|
||||
|
||||
function values = stringColumn(values)
|
||||
if iscell(values)
|
||||
values = string(values);
|
||||
elseif ischar(values)
|
||||
values = string(values);
|
||||
end
|
||||
values = strip(string(values));
|
||||
end
|
||||
|
||||
function rows = downsampleRows(rows, keepFraction)
|
||||
if keepFraction >= 1 || height(rows) <= 1
|
||||
return
|
||||
end
|
||||
|
||||
keepEvery = max(1, round(1 / keepFraction));
|
||||
keepIdx = 1:keepEvery:height(rows);
|
||||
rows = rows(keepIdx, :);
|
||||
end
|
||||
|
||||
function summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars)
|
||||
nGroups = height(summaryTable);
|
||||
stdCenter = NaN(nGroups, 1);
|
||||
stdLower = NaN(nGroups, 1);
|
||||
stdUpper = NaN(nGroups, 1);
|
||||
|
||||
for groupIdx = 1:nGroups
|
||||
rowMask = true(height(cleanData), 1);
|
||||
for varIdx = 1:numel(groupVars)
|
||||
varName = groupVars(varIdx);
|
||||
rowMask = rowMask & cleanData.(char(varName)) == summaryTable.(char(varName))(groupIdx);
|
||||
end
|
||||
|
||||
[stdCenter(groupIdx), stdLower(groupIdx), stdUpper(groupIdx)] = ...
|
||||
logBerMeanStdInterval(cleanData.BER(rowMask));
|
||||
end
|
||||
|
||||
summaryTable.std_center_BER = stdCenter;
|
||||
summaryTable.std_lower_BER = stdLower;
|
||||
summaryTable.std_upper_BER = stdUpper;
|
||||
end
|
||||
|
||||
function [centerBer, lowerBer, upperBer] = logBerMeanStdInterval(berValues)
|
||||
berValues = berValues(isfinite(berValues) & berValues > 0);
|
||||
if isempty(berValues)
|
||||
centerBer = NaN;
|
||||
lowerBer = NaN;
|
||||
upperBer = NaN;
|
||||
return
|
||||
end
|
||||
|
||||
logBer = log10(berValues(:));
|
||||
centerLog = mean(logBer, "omitnan");
|
||||
stdLog = std(logBer, 0, "omitnan");
|
||||
|
||||
centerBer = 10 .^ centerLog;
|
||||
lowerBer = 10 .^ (centerLog - stdLog);
|
||||
upperBer = 10 .^ (centerLog + stdLog);
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = berStdBounds(sirValues, centerBer, lowerBer, upperBer, boundMode, maxOrder)
|
||||
if boundMode == "directStd"
|
||||
[xBand, centerBand, yBounds] = directBerBounds(sirValues, centerBer, lowerBer, upperBer);
|
||||
return
|
||||
end
|
||||
|
||||
[xBand, centerBand, yBounds] = fittedBerBounds(sirValues, centerBer, lowerBer, upperBer, maxOrder);
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = directBerBounds(sirValues, centerBer, lowerBer, upperBer)
|
||||
valid = isfinite(sirValues) & isfinite(centerBer) & isfinite(lowerBer) & ...
|
||||
isfinite(upperBer) & centerBer > 0 & lowerBer > 0 & upperBer > 0;
|
||||
|
||||
xBand = sirValues(valid).';
|
||||
centerBand = centerBer(valid).';
|
||||
lowerBand = lowerBer(valid).';
|
||||
upperBand = upperBer(valid).';
|
||||
|
||||
[xBand, orderIdx] = sort(xBand(:));
|
||||
centerBand = centerBand(orderIdx);
|
||||
lowerBand = lowerBand(orderIdx);
|
||||
upperBand = upperBand(orderIdx);
|
||||
|
||||
lowerTmp = min(lowerBand, upperBand);
|
||||
upperBand = max(lowerBand, upperBand);
|
||||
lowerBand = lowerTmp;
|
||||
|
||||
centerBand = min(max(centerBand, lowerBand), upperBand);
|
||||
yBounds = [max(centerBand - lowerBand, 0), max(upperBand - centerBand, 0)];
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = fittedBerBounds(sirValues, meanBer, minBer, maxBer, maxOrder)
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & isfinite(minBer) & ...
|
||||
isfinite(maxBer) & meanBer > 0 & minBer > 0 & maxBer > 0;
|
||||
|
||||
x = sirValues(valid);
|
||||
yMean = meanBer(valid);
|
||||
yMin = minBer(valid);
|
||||
yMax = maxBer(valid);
|
||||
|
||||
if numel(x) < 2
|
||||
xBand = x(:);
|
||||
centerBand = yMean(:);
|
||||
yBounds = [max(yMean(:) - yMin(:), 0), max(yMax(:) - yMean(:), 0)];
|
||||
return
|
||||
end
|
||||
|
||||
[x, orderIdx] = sort(x(:));
|
||||
yMean = yMean(orderIdx);
|
||||
yMin = yMin(orderIdx);
|
||||
yMax = yMax(orderIdx);
|
||||
|
||||
xBand = linspace(min(x), max(x), 300).';
|
||||
fitOrder = min(maxOrder, numel(unique(x)) - 1);
|
||||
|
||||
if fitOrder < 1
|
||||
centerBand = interp1(x, yMean, xBand, "linear", "extrap");
|
||||
lowerBand = interp1(x, yMin, xBand, "linear", "extrap");
|
||||
upperBand = interp1(x, yMax, xBand, "linear", "extrap");
|
||||
else
|
||||
centerBand = fitLogBer(x, yMean, xBand, fitOrder);
|
||||
lowerBand = fitLogBer(x, yMin, xBand, fitOrder);
|
||||
upperBand = fitLogBer(x, yMax, xBand, fitOrder);
|
||||
end
|
||||
|
||||
lowerTmp = min(lowerBand, upperBand);
|
||||
upperBand = max(lowerBand, upperBand);
|
||||
lowerBand = lowerTmp;
|
||||
|
||||
centerBand = min(max(centerBand, lowerBand), upperBand);
|
||||
yBounds = [max(centerBand - lowerBand, 0), max(upperBand - centerBand, 0)];
|
||||
end
|
||||
|
||||
function yFit = fitLogBer(x, y, xFit, fitOrder)
|
||||
coeff = polyfit(x, log10(y), fitOrder);
|
||||
yFit = 10 .^ polyval(coeff, xFit);
|
||||
end
|
||||
|
||||
function label = algorithmDisplayName(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
case "plain_ffe"
|
||||
label = "FFE only";
|
||||
case "a2_tracked_levels"
|
||||
label = "ACT";
|
||||
case "a2_residual"
|
||||
label = "L-DCA";
|
||||
case "a1_moving_average"
|
||||
label = "DCA";
|
||||
case "dc_tracking"
|
||||
label = "DCT";
|
||||
otherwise
|
||||
label = algorithmName;
|
||||
end
|
||||
end
|
||||
|
||||
function color = algorithmColor(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
case "plain_ffe"
|
||||
color = [0.3467 0.5360 0.6907];
|
||||
case "a2_tracked_levels"
|
||||
color = [0.9153 0.2816 0.2878];
|
||||
case "a2_residual"
|
||||
color = [0.4416 0.7490 0.4322];
|
||||
case "a1_moving_average"
|
||||
color = [1.0000 0.5984 0.2000];
|
||||
case "dc_tracking"
|
||||
color = [0.6769 0.4447 0.7114];
|
||||
otherwise
|
||||
color = [0 0 0];
|
||||
end
|
||||
end
|
||||
|
||||
function marker = algorithmMarker(algorithmName, algorithmMarkers)
|
||||
algorithmOrder = ["plain_ffe", "a2_tracked_levels", "a2_residual", ...
|
||||
"a1_moving_average", "dc_tracking"];
|
||||
markerIdx = find(algorithmOrder == string(algorithmName), 1);
|
||||
if isempty(markerIdx)
|
||||
markerIdx = 1;
|
||||
end
|
||||
marker = algorithmMarkers{mod(markerIdx - 1, numel(algorithmMarkers)) + 1};
|
||||
end
|
||||
|
||||
function [xFit, yFit, requiredSir, fitOrder] = fitBerAtFec( ...
|
||||
sirValues, meanBer, polyfitOrderMax, fecBerThreshold)
|
||||
|
||||
xFit = NaN;
|
||||
yFit = NaN;
|
||||
requiredSir = NaN;
|
||||
fitOrder = NaN;
|
||||
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & meanBer > 0;
|
||||
if nnz(valid) < 2
|
||||
return
|
||||
end
|
||||
|
||||
sirValues = sirValues(valid);
|
||||
meanBer = meanBer(valid);
|
||||
[sirValues, sortIdx] = sort(sirValues);
|
||||
meanBer = meanBer(sortIdx);
|
||||
|
||||
fitOrder = min(polyfitOrderMax, nnz(valid) - 1);
|
||||
fitCoeff = polyfit(sirValues, log10(meanBer), fitOrder);
|
||||
xFit = linspace(min(sirValues), max(sirValues), 300);
|
||||
yFit = 10 .^ polyval(fitCoeff, xFit);
|
||||
|
||||
thresholdMask = isfinite(yFit) & yFit <= fecBerThreshold;
|
||||
if ~any(thresholdMask)
|
||||
return
|
||||
end
|
||||
|
||||
firstThresholdIdx = find(thresholdMask, 1, "first");
|
||||
if firstThresholdIdx == 1
|
||||
requiredSir = xFit(firstThresholdIdx);
|
||||
return
|
||||
end
|
||||
|
||||
xPair = xFit(firstThresholdIdx - 1:firstThresholdIdx);
|
||||
yPair = log10(yFit(firstThresholdIdx - 1:firstThresholdIdx));
|
||||
if all(isfinite(yPair)) && diff(yPair) ~= 0
|
||||
requiredSir = interp1(yPair, xPair, log10(fecBerThreshold), ...
|
||||
"linear", "extrap");
|
||||
else
|
||||
requiredSir = xFit(firstThresholdIdx);
|
||||
end
|
||||
end
|
||||
Binary file not shown.
@@ -1,389 +0,0 @@
|
||||
%% Analyze
|
||||
% === DSP settings ===
|
||||
dsp_options = struct();
|
||||
dsp_options.mode = "run_id";
|
||||
dsp_options.recipe = @mpi_recipe_dev;
|
||||
dsp_options.append_to_db = false;
|
||||
dsp_options.start_occurence = 1;
|
||||
dsp_options.max_occurences = 15;
|
||||
dsp_options.debug_plots = false;
|
||||
|
||||
dsp_options.database_type = "mysql";
|
||||
|
||||
dsp_options.dataBase = "labor";
|
||||
dsp_options.storage_path = "W:\labdata\ECOC Silas\ecoc_2025";
|
||||
|
||||
dsp_options.server = "192.168.178.192";
|
||||
dsp_options.port = 3306;
|
||||
dsp_options.user = "silas";
|
||||
dsp_options.password = "silas";
|
||||
|
||||
db = DBHandler("dataBase", [dsp_options.dataBase],...
|
||||
"type", dsp_options.database_type,...
|
||||
"server", dsp_options.server,...
|
||||
"user", dsp_options.user, "password", dsp_options.password);
|
||||
|
||||
%%
|
||||
|
||||
fp = QueryFilter();
|
||||
fp.where('Runs','run_id','GREATER_EQUAL',3153);
|
||||
fp.where('Runs', 'symbolrate', 'EQUALS', 112e9); % 72 96 112
|
||||
fp.where('Runs', 'fiber_length', 'EQUALS', 0);
|
||||
fp.where('Runs', 'interference_path_length', 'EQUALS', 1000);
|
||||
% fp.where('Runs', 'sir', 'LESS_EQUAL', 50);
|
||||
fp.where('Runs', 'db_mode', 'EQUALS', '"no_db"');
|
||||
% fp.where('Runs', 'is_mpi', 'EQUALS', 1);
|
||||
fp.where('Runs', 'pam_level', 'EQUALS', 4);
|
||||
% fp.where('Runs', 'v_bias', 'EQUALS', 2.65);
|
||||
|
||||
[dataTable,~] = db.queryDB(fp, db.getTableFieldNames('Runs'));
|
||||
|
||||
% [~, uniqueSirRows] = unique(dataTable.sir, "stable");
|
||||
% dataTable = dataTable(uniqueSirRows, :);
|
||||
|
||||
[~, sortIdx] = sort(dataTable.sir, 'descend');
|
||||
dataTable = dataTable(sortIdx, :);
|
||||
% dataTable = dataTable(1, :);
|
||||
run_ids = dataTable.run_id;
|
||||
%%
|
||||
|
||||
wh_ = load("C:\Users\Silas\Documents\MATLAB\imdd_simulation\projects\Diss\MPI_revisit\parallelization_analysis\wh_block_update_pam4_combined.mat");
|
||||
wh = wh_.wh;
|
||||
|
||||
% wh_ = load("C:\Users\Silas\Documents\MATLAB\imdd_simulation\projects\Diss\MPI_revisit\parallelization_analysis\wh_block_update_pam4_short_blocks.mat");
|
||||
% wh2 = wh_.wh;
|
||||
%
|
||||
% wh = mergeDataStorages(wh1,wh2);
|
||||
|
||||
%%
|
||||
|
||||
|
||||
storageNames = fieldnames(wh.sto);
|
||||
storageNames = storageNames([1,2,3,5]);
|
||||
ber_by_storage = struct();
|
||||
ber_mat_by_storage = struct();
|
||||
|
||||
sir_values = dataTable.sir(:).';
|
||||
block_updates = wh.parameter.block_update.values;
|
||||
storage_parameter_names = cellstr(wh.fn);
|
||||
block_axis = find(strcmp(storage_parameter_names,"block_update"),1);
|
||||
|
||||
if exist('linspecer','file')
|
||||
curve_colors = linspecer(max(numel(storageNames),1));
|
||||
else
|
||||
curve_colors = lines(max(numel(storageNames),1));
|
||||
end
|
||||
|
||||
useBoundedLines = true;
|
||||
usePolyfit = true;
|
||||
polyfitOrderMax = 4;
|
||||
fec_ber_threshold = 3.8e-3;%3.8e-3;
|
||||
fit_coeff_by_storage = struct();
|
||||
required_sir_fec_by_storage = struct();
|
||||
for storage_idx = 1:numel(storageNames)
|
||||
storageName = storageNames{storage_idx};
|
||||
fit_coeff_by_storage.(storageName) = cell(1,numel(block_updates));
|
||||
required_sir_fec_by_storage.(storageName) = nan(1,numel(block_updates));
|
||||
end
|
||||
|
||||
for block_idx = 1:numel(block_updates)
|
||||
block_update = block_updates(block_idx);
|
||||
|
||||
figure(3000 + block_idx); clf; hold on
|
||||
for storage_idx = 1:numel(storageNames)
|
||||
storageName = storageNames{storage_idx};
|
||||
curve_color = curve_colors(storage_idx,:);
|
||||
result = wh.sto.(storageName);
|
||||
|
||||
if ~isempty(block_axis) && size(result,block_axis) == numel(block_updates)
|
||||
result_subs = repmat({':'},1,ndims(result));
|
||||
result_subs{block_axis} = block_idx;
|
||||
result_for_block = result(result_subs{:});
|
||||
result_for_block = result_for_block(:).';
|
||||
else
|
||||
result_for_block = result(:).';
|
||||
end
|
||||
|
||||
% Each stored entry is a package cell containing one or more occurrences.
|
||||
ber_all = cell(1,numel(result_for_block));
|
||||
for result_idx = 1:numel(result_for_block)
|
||||
packageCell = result_for_block{result_idx};
|
||||
if isempty(packageCell)
|
||||
ber_all{result_idx} = NaN;
|
||||
continue
|
||||
end
|
||||
|
||||
ber_values = nan(1,numel(packageCell));
|
||||
for package_idx = 1:numel(packageCell)
|
||||
if isstruct(packageCell{package_idx}) && isfield(packageCell{package_idx},"metrics")
|
||||
ber_values(package_idx) = packageCell{package_idx}.metrics.BER;
|
||||
end
|
||||
end
|
||||
ber_all{result_idx} = ber_values;
|
||||
end
|
||||
|
||||
maxPackages = max(cellfun(@numel,ber_all));
|
||||
ber_mat = nan(maxPackages,numel(ber_all));
|
||||
for k = 1:numel(ber_all)
|
||||
ber_mat(1:numel(ber_all{k}),k) = ber_all{k};
|
||||
end
|
||||
|
||||
% Match the BER-over-SIR plot cleanup: remove high BER points and outliers per SIR.
|
||||
for col = 1:size(ber_mat,2)
|
||||
colData = ber_mat(:,col);
|
||||
colData(~isfinite(colData) | colData >= 0.1) = NaN;
|
||||
validColData = colData(isfinite(colData));
|
||||
if isempty(validColData)
|
||||
ber_mat(:,col) = NaN;
|
||||
continue
|
||||
end
|
||||
outliers = isoutlier(validColData);
|
||||
validColData(outliers) = NaN;
|
||||
colData(isfinite(colData)) = validColData;
|
||||
ber_mat(:,col) = colData;
|
||||
end
|
||||
|
||||
ber = mean(ber_mat,1,"omitnan");
|
||||
ber_min = nan(1,numel(ber));
|
||||
ber_max = nan(1,numel(ber));
|
||||
for k = 1:numel(ber)
|
||||
ber_here = ber_mat(:,k);
|
||||
ber_here = ber_here(isfinite(ber_here));
|
||||
if isempty(ber_here)
|
||||
continue
|
||||
end
|
||||
ber_min(k) = min(ber_here);
|
||||
ber_max(k) = max(ber_here);
|
||||
end
|
||||
|
||||
x = sir_values;
|
||||
if numel(x) ~= numel(ber)
|
||||
x = 1:numel(ber);
|
||||
end
|
||||
|
||||
ber_by_storage.(storageName){block_idx} = ber;
|
||||
ber_mat_by_storage.(storageName){block_idx} = ber_mat;
|
||||
|
||||
for k = 1:numel(x)
|
||||
scatter(repmat(x(k),maxPackages,1),ber_mat(:,k), ...
|
||||
30, ...
|
||||
'Marker','.', ...
|
||||
'MarkerEdgeColor',curve_color, ...
|
||||
'MarkerFaceColor',curve_color, ...
|
||||
'HandleVisibility','off');
|
||||
end
|
||||
|
||||
valid = isfinite(x) & isfinite(ber);
|
||||
if ~any(valid)
|
||||
continue
|
||||
end
|
||||
|
||||
% if useBoundedLines && exist("boundedline","file")
|
||||
% y_lower = max(ber - ber_min,0);
|
||||
% y_upper = max(ber_max - ber,0);
|
||||
% y_bounds = [y_lower(:), y_upper(:)];
|
||||
%
|
||||
% [hl, hp] = boundedline(x(valid).',ber(valid).',y_bounds(valid,:), ...
|
||||
% 'alpha', 'transparency', 0.08, ...
|
||||
% 'cmap', curve_color, ...
|
||||
% 'nan', 'fill', ...
|
||||
% 'orientation', 'vert');
|
||||
% set(hl, ...
|
||||
% 'LineStyle','none', ...
|
||||
% 'Marker','none', ...
|
||||
% 'HandleVisibility','off');
|
||||
% set(hp, ...
|
||||
% 'HandleVisibility','off', ...
|
||||
% 'LineStyle','none');
|
||||
% end
|
||||
|
||||
scatter(x(valid),ber(valid), ...
|
||||
20, ...
|
||||
'Marker','o', ...
|
||||
'MarkerEdgeColor',curve_color, ...
|
||||
'MarkerFaceColor',curve_color, ...
|
||||
'LineWidth',1, ...
|
||||
'DisplayName',storageName);
|
||||
|
||||
fit_mask = valid & ber > 0;
|
||||
if usePolyfit && nnz(fit_mask) >= 2
|
||||
fit_order = min(polyfitOrderMax,nnz(fit_mask)-1);
|
||||
fit_coeff = polyfit(x(fit_mask),log10(ber(fit_mask)),fit_order);
|
||||
x_fit = linspace(min(x(fit_mask)),max(x(fit_mask)),300);
|
||||
y_fit = 10.^polyval(fit_coeff,x_fit);
|
||||
fit_coeff_by_storage.(storageName){block_idx} = fit_coeff;
|
||||
|
||||
sir_req = NaN;
|
||||
threshold_mask = isfinite(y_fit) & y_fit <= fec_ber_threshold;
|
||||
if any(threshold_mask)
|
||||
first_threshold_idx = find(threshold_mask,1,"first");
|
||||
if first_threshold_idx == 1
|
||||
sir_req = x_fit(first_threshold_idx);
|
||||
else
|
||||
x_pair = x_fit(first_threshold_idx-1:first_threshold_idx);
|
||||
y_pair = log10(y_fit(first_threshold_idx-1:first_threshold_idx));
|
||||
if all(isfinite(y_pair)) && diff(y_pair) ~= 0
|
||||
sir_req = interp1(y_pair,x_pair,log10(fec_ber_threshold), ...
|
||||
"linear","extrap");
|
||||
else
|
||||
sir_req = x_fit(first_threshold_idx);
|
||||
end
|
||||
end
|
||||
end
|
||||
required_sir_fec_by_storage.(storageName)(block_idx) = sir_req;
|
||||
|
||||
plot(x_fit,y_fit, ...
|
||||
'LineWidth',1.1, ...
|
||||
'LineStyle','--', ...
|
||||
'Color',curve_color, ...
|
||||
'HandleVisibility','off');
|
||||
end
|
||||
end
|
||||
|
||||
title(sprintf("BER over SIR, block update = %g",block_update));
|
||||
xlabel("SIR (dB)");
|
||||
ylabel("BER");
|
||||
|
||||
yline(2.2e-4, 'LineWidth', 1, 'LineStyle', '--', 'HandleVisibility', 'off');
|
||||
yline(3.8e-3, 'LineWidth', 1, 'LineStyle', '--', 'HandleVisibility', 'off');
|
||||
yline(2e-2, 'LineWidth', 1, 'LineStyle', '--', 'HandleVisibility', 'off');
|
||||
ylim([9e-5, 0.1]);
|
||||
|
||||
set(gca, "YScale", "log");
|
||||
xlim([15,45]);
|
||||
grid on;
|
||||
box on;
|
||||
legend("Location", "best", "Interpreter", "none");
|
||||
end
|
||||
|
||||
%% Required SIR to reach FEC over parallelization
|
||||
|
||||
figure(5000); clf; hold on
|
||||
for storage_idx = 1:numel(storageNames)
|
||||
storageName = storageNames{storage_idx};
|
||||
curve_color = curve_colors(storage_idx,:);
|
||||
required_sir = required_sir_fec_by_storage.(storageName);
|
||||
valid = isfinite(block_updates) & isfinite(required_sir);
|
||||
|
||||
if ~any(valid)
|
||||
continue
|
||||
end
|
||||
|
||||
plot(block_updates(valid),required_sir(valid), ...
|
||||
'LineWidth',1.4, ...
|
||||
'LineStyle','-', ...
|
||||
'Marker','o', ...
|
||||
'MarkerSize',5, ...
|
||||
'Color',curve_color, ...
|
||||
'DisplayName',storageName);
|
||||
end
|
||||
|
||||
set(gca,'XScale','log');
|
||||
xticks(block_updates);
|
||||
xticklabels(string(block_updates));
|
||||
grid on
|
||||
box on
|
||||
xlabel("Parallelization / block update");
|
||||
ylabel(sprintf("Required SIR at BER = %.1e (dB)",fec_ber_threshold));
|
||||
title("Required SIR to reach FEC over parallelization");
|
||||
legend("Location","best","Interpreter","none");
|
||||
|
||||
|
||||
%%
|
||||
|
||||
|
||||
function whMerged = mergeDataStorages(varargin)
|
||||
% mergeDataStorages merges compatible DataStorage objects by physical indices.
|
||||
% Existing duplicate entries are concatenated when both values are package cells.
|
||||
|
||||
whList = varargin;
|
||||
templateWh = whList{1};
|
||||
paramNames = cellstr(templateWh.fn);
|
||||
|
||||
mergedParams = struct();
|
||||
for param_idx = 1:numel(paramNames)
|
||||
paramName = paramNames{param_idx};
|
||||
values = templateWh.parameter.(paramName).values(:).';
|
||||
|
||||
for wh_idx = 2:numel(whList)
|
||||
curWh = whList{wh_idx};
|
||||
if ~isequal(sort(cellstr(curWh.fn)),sort(paramNames))
|
||||
error("mergeDataStorages:ParameterMismatch", ...
|
||||
"All warehouses must use the same parameter names.");
|
||||
end
|
||||
if ~isfield(curWh.parameter,paramName)
|
||||
error("mergeDataStorages:ParameterMismatch", ...
|
||||
"Warehouse %d does not contain parameter '%s'.",wh_idx,paramName);
|
||||
end
|
||||
|
||||
newValues = curWh.parameter.(paramName).values(:).';
|
||||
for value_idx = 1:numel(newValues)
|
||||
if ~ismember(newValues(value_idx),values)
|
||||
values(end+1) = newValues(value_idx); %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if strcmp(paramName,"block_update") && isnumeric(values)
|
||||
values = sort(values);
|
||||
end
|
||||
|
||||
mergedParams.(paramName) = values;
|
||||
end
|
||||
|
||||
whMerged = DataStorage(mergedParams);
|
||||
|
||||
for wh_idx = 1:numel(whList)
|
||||
curWh = whList{wh_idx};
|
||||
curStorageNames = fieldnames(curWh.sto);
|
||||
|
||||
for storage_idx = 1:numel(curStorageNames)
|
||||
storageName = curStorageNames{storage_idx};
|
||||
if ~isfield(whMerged.sto,storageName)
|
||||
whMerged.addStorage(storageName);
|
||||
end
|
||||
|
||||
for lin_idx = 1:numel(curWh.sto.(storageName))
|
||||
storedValue = curWh.sto.(storageName){lin_idx};
|
||||
if isempty(storedValue)
|
||||
continue
|
||||
end
|
||||
|
||||
[physValues,physNames] = curWh.getPhysIndicesByLinIndex(lin_idx);
|
||||
physNames = cellfun(@char,physNames,'UniformOutput',false);
|
||||
targetSubscripts = cell(1,numel(whMerged.fn));
|
||||
|
||||
for param_idx = 1:numel(whMerged.fn)
|
||||
paramName = char(whMerged.fn(param_idx));
|
||||
sourceParamIdx = find(strcmp(physNames,paramName),1);
|
||||
if isempty(sourceParamIdx)
|
||||
error("mergeDataStorages:ParameterMismatch", ...
|
||||
"Storage entry is missing parameter '%s'.",paramName);
|
||||
end
|
||||
targetSubscripts{param_idx} = whMerged.getIndexByPhys(paramName,physValues{sourceParamIdx});
|
||||
end
|
||||
|
||||
if isscalar(targetSubscripts)
|
||||
targetLinIdx = targetSubscripts{1};
|
||||
else
|
||||
targetLinIdx = sub2ind(whMerged.getStorageSize(),targetSubscripts{:});
|
||||
end
|
||||
|
||||
existingValue = whMerged.sto.(storageName){targetLinIdx};
|
||||
whMerged.sto.(storageName){targetLinIdx} = mergeStoredValue(existingValue,storedValue);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function out = mergeStoredValue(existingValue,newValue)
|
||||
if isempty(existingValue)
|
||||
out = newValue;
|
||||
elseif iscell(existingValue) && iscell(newValue)
|
||||
out = [existingValue(:); newValue(:)].';
|
||||
else
|
||||
out = newValue;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user