File size: 14,836 Bytes
2072243 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | # plot_convergence.py β Analysis and Visualisation Script
This document provides a comprehensive technical reference for plot_convergence.py. This script serves as the primary analytics engine, transforming JSON telemetry logs produced by your execution runner (run_mvp.py) into publication-quality research figures.
Reads accuracy_log.json produced by run_mvp.py and generates three publication-quality figures:
Figure 1 β convergence_plot.png (2 panels)
Panel 1: Global accuracy over rounds β haflq vs baseline
Panel 2: Aggregated weight delta Frobenius norm (β£β£ΞWβ£β£Fβ) β haflq vs baseline
Figure 2 β extended_metrics_plot.png (4 panels)
Panel 1: Per-round communication cost β haflq vs baseline
Panel 2: Cumulative communication cost β with bandwidth-saved fill
Panel 3: Parameters discarded per round due to edge transport limits
Panel 4: Accuracy per MB of communication (efficiency ratio)
Figure 3 β loss_throughput_metrics.png (3 panels)
Panel 1: Global convergence losses β Training vs. Validation curves
Panel 2: Per-client loss variance β Visualizing non-IID data distribution trends
Panel 3: On-device token throughput β Hardware processing speed (tokens/sec)
Every number in every panel comes directly from accuracy_log.json. Nothing is fabricated or randomly generated at the visualization layer.
## Usage
Bash
python plot_convergence.py
python plot_convergence.py --input path/to/accuracy_log.json
python plot_convergence.py --input path/to/log.json --outdir results/plots
## Dependencies
Bash
pip install matplotlib numpy
## Architectural Overview
The script abstracts the visualization layer from the training loop. It parses empirical telemetry data, applies multi-version schema normalization, isolates system metrics, and generates high-density figures matching academic publication standards.
Plaintext
ββββββββββββββββββββββ
β run_mvp.py β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββββββββ
β accuracy_log.json β
ββββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββ
β plot_convergence.py β
βββββ¬βββββββββββ¬βββββββββββ¬β
β β β
Generates Fig 1 β β β Generates Fig 3
βΌ β βΌ
βββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββββ
βconvergence_plot.png β β β loss_throughput_metrics.png β
βββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββββ
β 2-Panel Diagnostic β β β 3-Panel Compute & Loss Matrix β
βββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββββ
βΌ Generates Fig 2
βββββββββββββββββββββββββββββββββββββ
β extended_metrics_plot.png β
βββββββββββββββββββββββββββββββββββββ
β 4-Panel Network Efficiency Matrix β
βββββββββββββββββββββββββββββββββββββ
Core Design Goals
Mathematical Invariance: No synthetic, fabricated, or smoothed values are introduced at the plotting layer. Every pixel mapped corresponds strictly to logged telemetry.
Schema Decoupling: Includes structural fallback handlers capable of digesting multi-method cross-comparisons or legacy, single-history array structures without throwing errors.
Production-Grade Aesthetics: Uses a unified hex-color spectrum, proportional axis text offsets, automated tick-overcrowding decimation, and text annotations aligned directly to critical data elements.
## Telemetry Schema Specifications
The script expects a structured JSON telemetry payload. It dynamically supports both the production multi-experiment layout and the legacy single-method format.
Target Multi-Experiment Schema (Preferred)
This structure maps cross-comparative studies simultaneously (e.g., evaluating your proposed haflq framework directly against standard baseline parameters).
JSON
{
"timestamp": "2026-06-23T13:00:00Z",
"dataset": "Banking77",
"num_rounds": 20,
"num_clients": 10,
"experiments": {
"haflq": [
{
"round": 1,
"global_accuracy": 0.4521,
"total_comm_mb": 8.42,
"cumulative_comm_mb": 8.42,
"total_discarded_mb": 0.02,
"avg_client_accuracy": 0.4110,
"update_norm": 4.1251,
"train_loss": 2.2145,
"val_loss": 2.5102,
"token_throughput": 1441.2,
"client_1_loss": 2.2510,
"client_2_loss": 2.2104,
"client_3_loss": 2.1215
},
{
"round": 2,
"global_accuracy": 0.6285,
"total_comm_mb": 6.11,
"cumulative_comm_mb": 14.53,
"total_discarded_mb": 0.01,
"avg_client_accuracy": 0.5942,
"update_norm": 4.0912,
"train_loss": 1.8841,
"val_loss": 2.1154,
"token_throughput": 1445.6,
"client_1_loss": 1.9214,
"client_2_loss": 1.8541,
"client_3_loss": 1.8102
}
],
"baseline": [
{
"round": 1,
"global_accuracy": 0.4102,
"total_comm_mb": 12.50,
"cumulative_comm_mb": 12.50,
"total_discarded_mb": 2.15,
"avg_client_accuracy": 0.3854,
"update_norm": 4.1520,
"train_loss": 2.3841,
"val_loss": 2.6145,
"token_throughput": 1515.4,
"client_1_loss": 2.4412,
"client_2_loss": 2.3514,
"client_3_loss": 2.3145
}
]
}
}
## Legacy Single-Method Schema Support
If the core executor dumps a flat history list representing a single execution pass, the script detects it, logs a structural notice, and auto-wraps the telemetry payload into the standard namespace as haflq.
JSON
{
"num_rounds": 20,
"history": [
{
"round": 1,
"global_accuracy": 0.4521,
"total_comm_mb": 8.42
}
]
}
## Visualization Architecture
Figure 1: Convergence Diagnostics (convergence_plot.png)
Dimensions: 14Γ5.5 inches (Dual-Panel Landscape arrangement).
Target Domain: Standard machine learning training dynamics and model state stabilization metrics.
Panel Metric Rendered Input JSON Keys Analytical Value
Panel 1 Global Test Accuracy Convergence global_accuracy Multi-line progression plotting validation accuracy across training iterations. Includes a static horizontal baseline target at 89.13%, serving as a benchmark against top-tier academic reference parameters.
Panel 2 Aggregated Weight Delta Norm update_norm Tracks the geometric Frobenius Norm $
Figure 2: Extended Communication Matrix (extended_metrics_plot.png)
Dimensions: 15Γ11 inches (2Γ2 Grid Quad-Panel matrix layout).
Target Domain: Systems-level networking efficiency and network-constrained edge resource profiling.
Plaintext
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β [0,0] Per-Round Communication β [0,1] Cumulative Communication β
β β β
β β’ Tracks individual round costs β β’ Plots total network transfer β
β β’ Monitors adaptive compression β β’ Shards network bandwidth saved β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β [1,0] Parameter Discard Profile β [1,1] Efficiency Ratio Matrix β
β β β
β β’ Measures drops due to limits β β’ Evaluates Accuracy gained per MB β
β β’ Proves edge budget compliance β β’ The primary optimization target β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Panel [0,0] β Per-Round Communication Cost: Plots discrete byte volumes uploaded per epoch. It charts how parameter freezing and quantization steps lower infrastructure costs as training stabilizes.
Panel [0,1] β Cumulative Communication Cost: A continuous step aggregation of overall edge data transfer. If both haflq and baseline modes are present, it renders an alpha-blended teal filling block (#43a2ca) across the curves, computing a vector offset to place an automated arrow annotation detailing the exact volume of Megabytes saved.
Panel [1,0] β Parameters Discarded per Round: Implements an interlaced bar graph matrix visualizing the volume of model layers dropped due to hardware bandwidth limits. Low values in this panel validate the model's adaptive budget alignment.
Panel [1,1] β Communication Efficiency Ratio: Tracks the system's ability to achieve high model utility with a minimal network payload, evaluated via vector conditional logic:
Efficiency=Current Round Transport Burden (MB)Global Accuracy Componentβ
Figure 3: Compute & Loss Telemetry Matrix (loss_throughput_metrics.png)
Dimensions: 18Γ5.5 inches (1Γ3 Panel Landscape arrangement).
Target Domain: Hardware runtime compute speed and cross-entropy error boundary optimization.
Panel Metric Rendered Input JSON Keys Analytical Value
Panel 1 Global Convergence Loss train_loss, val_loss Juxtaposes global training loss against central evaluation validation loss. Used to monitor training convergence speed and detect overfitting thresholds.
Panel 2 Per-Client Loss Variance client_x_loss Overlays explicit loss trajectories of isolated edge nodes. Highlights system robustness under complex, highly non-IID data distributions.
Panel 3 On-Device Token Throughput token_throughput Evaluates hardware compute efficiency measured in tokens/sec. Proves that advanced quantization layers do not degrade processing speed.
Production Layout Engine & Stylesheet
The script overrides Matplotlib defaults to enforce professional typographical hierarchies and clean geometric layouts:
Python
# Color Palette Token Definitions
COLOR = {
"haflq": "#0f62fe", # Deep Carbon Blue (Primary Target Model)
"baseline": "#ff1744", # Vivid Crimson (Baseline Benchmarks)
"fill": "#43a2ca", # Teal Fill (Shaded Efficiency Spaces)
"grid": "#e0e0e0", # Light Grey (Axis Subdivisions)
"mean": "#d73027", # Soft Red (Horizontal Reference Marks)
}
## Automation Subsystems
Overcrowding Decimation: Axis ticks scale dynamically using a MultipleLocator step calculation: max(1, len(rounds) // 10). This guarantees crisp, uncrowded horizontal label readouts whether running short 10-round validation sweeps or full-scale 200-round operations.
Safe Floating-Point Division: To prevent mathematical evaluation faults during early rounds where data transport counters are absolute zero, division logic is safely isolated using vector conditional logic:
Python
with np.errstate(divide="ignore", invalid="ignore"):
efficiency = np.where(total_comm_mb > 0, global_accuracy / total_comm_mb, 0.0)
## Execution Guide & Command Line Interface
The script uses an independent parser loop, allowing execution from varying workspace directories without risking file-path breaks.
Command Line Arguments
Plaintext
options:
-h, --help show this help message and exit
--input INPUT Path to accuracy_log.json source file
(Default: experiments/results/accuracy_log.json)
--outdir OUTDIR Directory target path for generated image files
(Default: experiments/results)
Execution Recipes
1. Standard Run (Default Workspace Organization)
Bash
python plot_convergence.py
2. Evaluating Custom Stored Metrics
Bash
python plot_convergence.py --input storage/logs/banking77_run.json
3. Custom Output Directory Targeting (For Presentation Assets)
Bash
python plot_convergence.py \
--input experiments/results/accuracy_log.json \
--outdir assets/presentation_deck/
Clean System Outputs
Upon validation and parsing, the engine outputs explicit generation notifications to stdout:
Plaintext
Loaded log: 2 method(s), 20 rounds each.
Generating Figure 1 β convergence plot...
Saved: experiments/results/convergence_plot.png
Generating Figure 2 β extended metrics plot...
Saved: experiments/results/extended_metrics_plot.png
Generating Figure 3 β loss throughput metrics plot...
Saved: experiments/results/loss_throughput_metrics.png
All plots saved successfully.
experiments/results/convergence_plot.png
experiments/results/extended_metrics_plot.png
experiments/results/loss_throughput_metrics.png |