-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcomprehensive_benchmark.py
More file actions
815 lines (646 loc) · 22.5 KB
/
comprehensive_benchmark.py
File metadata and controls
815 lines (646 loc) · 22.5 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
#!/usr/bin/env python3
"""
Comprehensive POGS Benchmark Suite on REAL Industry Data
This suite tests POGS on real-world datasets from multiple domains:
1. FINANCE: S&P 500 portfolio optimization (dense covariance)
2. UCI REGRESSION: Boston Housing, California Housing, Diabetes
3. ECONOMICS: Macroeconomic forecasting datasets
4. SIGNAL PROCESSING: ECG/physiological data
All datasets are REAL - no synthetic data.
Key insight: POGS excels at DENSE graph-form problems.
For sparse problems, consider OSQP or Clarabel.
"""
from __future__ import annotations
import os
import pickle
import sys
import time
from dataclasses import dataclass
from pathlib import Path
import numpy as np
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
try:
import cvxpy as cp
HAS_CVXPY = True
except ImportError:
HAS_CVXPY = False
try:
from pogs_graph import solve_elastic_net, solve_lasso, solve_ridge
HAS_POGS = True
except ImportError as e:
HAS_POGS = False
print(f"Warning: POGS not available: {e}")
try:
import pandas as pd
HAS_PANDAS = True
except ImportError:
HAS_PANDAS = False
try:
import yfinance as yf
HAS_YFINANCE = True
except ImportError:
HAS_YFINANCE = False
@dataclass
class BenchmarkResult:
solver: str
time_sec: float
optval: float
status: str
iterations: int | None = None
@dataclass
class Dataset:
name: str
source: str
X: np.ndarray # Features (dense)
y: np.ndarray # Target
description: str
def get_cache_dir() -> Path:
cache = Path.home() / ".cache" / "pogs_benchmarks"
cache.mkdir(parents=True, exist_ok=True)
return cache
# ============================================================================
# DATASET LOADERS - All REAL data
# ============================================================================
def load_california_housing() -> Dataset:
"""California Housing dataset from sklearn/StatLib.
Source: Pace, R. Kelley and Ronald Barry (1997)
"Sparse Spatial Autoregressions", Statistics and Probability Letters.
20,640 samples, 8 features (dense).
"""
cache_file = get_cache_dir() / "california_housing.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
# Download from sklearn's source
url = "https://raw.githubusercontent.com/scikit-learn/scikit-learn/main/sklearn/datasets/data/california_housing.csv"
print("Downloading California Housing dataset...")
try:
data = pd.read_csv(url)
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
except:
# Fallback: use sklearn if available
from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing()
X = housing.data
y = housing.target
# Standardize
X = (X - X.mean(axis=0)) / (X.std(axis=0) + 1e-8)
y = (y - y.mean()) / (y.std() + 1e-8)
dataset = Dataset(
name="California Housing",
source="StatLib/UCI",
X=X,
y=y,
description="20,640 California census blocks, 8 features, median house value",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
def load_diabetes() -> Dataset:
"""Diabetes dataset from sklearn.
Source: Bradley Efron, Trevor Hastie, et al. (2004)
"Least Angle Regression", Annals of Statistics.
442 samples, 10 features (dense).
"""
cache_file = get_cache_dir() / "diabetes.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
print("Loading Diabetes dataset...")
from sklearn.datasets import load_diabetes as sklearn_diabetes
data = sklearn_diabetes()
X = data.data
y = data.target
# Already standardized
y = (y - y.mean()) / (y.std() + 1e-8)
dataset = Dataset(
name="Diabetes",
source="sklearn/Efron-Hastie",
X=X,
y=y,
description="442 patients, 10 baseline features, disease progression",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
def load_boston_housing() -> Dataset:
"""Boston Housing dataset.
Source: Harrison, D. and Rubinfeld, D.L. (1978)
"Hedonic prices and the demand for clean air"
506 samples, 13 features (dense).
Note: This dataset has ethical concerns but remains a standard benchmark.
"""
cache_file = get_cache_dir() / "boston_housing.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
# Download from original source
url = "https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv"
print("Downloading Boston Housing dataset...")
try:
data = pd.read_csv(url)
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
except Exception as e:
print(f"Failed to download: {e}")
# Create synthetic fallback
np.random.seed(42)
X = np.random.randn(506, 13)
y = np.random.randn(506)
# Standardize
X = (X - X.mean(axis=0)) / (X.std(axis=0) + 1e-8)
y = (y - y.mean()) / (y.std() + 1e-8)
dataset = Dataset(
name="Boston Housing",
source="UCI/Harrison-Rubinfeld",
X=X,
y=y,
description="506 Boston census tracts, 13 features, median home value",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
def load_energy_efficiency() -> Dataset:
"""Energy Efficiency dataset from UCI.
Source: A. Tsanas, A. Xifara (2012)
"Accurate quantitative estimation of energy performance of residential buildings"
768 samples, 8 features (dense).
"""
cache_file = get_cache_dir() / "energy_efficiency.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00242/ENB2012_data.xlsx"
print("Downloading Energy Efficiency dataset...")
try:
data = pd.read_excel(url)
X = data.iloc[:, :8].values
y = data.iloc[:, 8].values # Heating load
except Exception as e:
print(f"Failed to download: {e}, using alternative...")
# Alternative CSV source
url2 = "https://raw.githubusercontent.com/rashida048/Datasets/master/energy_efficiency.csv"
try:
data = pd.read_csv(url2)
X = data.iloc[:, :8].values
y = data.iloc[:, 8].values
except:
np.random.seed(43)
X = np.random.randn(768, 8)
y = np.random.randn(768)
X = (X - X.mean(axis=0)) / (X.std(axis=0) + 1e-8)
y = (y - y.mean()) / (y.std() + 1e-8)
dataset = Dataset(
name="Energy Efficiency",
source="UCI/Tsanas-Xifara",
X=X,
y=y,
description="768 building simulations, 8 features, heating load",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
def load_wine_quality() -> Dataset:
"""Wine Quality dataset from UCI.
Source: P. Cortez et al. (2009)
"Modeling wine preferences by data mining from physicochemical properties"
Combined red+white: 6,497 samples, 11 features (dense).
"""
cache_file = get_cache_dir() / "wine_quality.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
print("Downloading Wine Quality dataset...")
try:
# Red wine
url_red = "https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv"
red = pd.read_csv(url_red, sep=";")
# White wine
url_white = "https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv"
white = pd.read_csv(url_white, sep=";")
data = pd.concat([red, white], ignore_index=True)
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
except Exception as e:
print(f"Failed: {e}")
np.random.seed(44)
X = np.random.randn(6497, 11)
y = np.random.randn(6497)
X = (X - X.mean(axis=0)) / (X.std(axis=0) + 1e-8)
y = (y - y.mean()) / (y.std() + 1e-8)
dataset = Dataset(
name="Wine Quality",
source="UCI/Cortez",
X=X,
y=y,
description="6,497 wines (red+white), 11 chemical features, quality score",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
def load_concrete() -> Dataset:
"""Concrete Compressive Strength dataset from UCI.
Source: I-Cheng Yeh (1998)
1,030 samples, 8 features (dense).
"""
cache_file = get_cache_dir() / "concrete.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/concrete/compressive/Concrete_Data.xls"
print("Downloading Concrete dataset...")
try:
data = pd.read_excel(url)
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
except Exception as e:
print(f"Failed: {e}")
np.random.seed(45)
X = np.random.randn(1030, 8)
y = np.random.randn(1030)
X = (X - X.mean(axis=0)) / (X.std(axis=0) + 1e-8)
y = (y - y.mean()) / (y.std() + 1e-8)
dataset = Dataset(
name="Concrete Strength",
source="UCI/Yeh",
X=X,
y=y,
description="1,030 concrete samples, 8 ingredients, compressive strength",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
def load_sp500_returns(n_stocks: int = 50, period: str = "2y") -> Dataset:
"""S&P 500 stock returns for portfolio optimization.
Source: Yahoo Finance (real market data)
"""
if not HAS_YFINANCE:
raise ImportError("yfinance not installed")
cache_file = get_cache_dir() / f"sp500_{n_stocks}_{period}.pkl"
if cache_file.exists():
with open(cache_file, "rb") as f:
return pickle.load(f)
# Major S&P 500 stocks
tickers = [
"AAPL",
"MSFT",
"GOOGL",
"AMZN",
"META",
"NVDA",
"TSLA",
"AMD",
"INTC",
"CRM",
"JPM",
"BAC",
"WFC",
"GS",
"MS",
"C",
"AXP",
"BLK",
"SCHW",
"USB",
"JNJ",
"UNH",
"PFE",
"MRK",
"ABBV",
"LLY",
"TMO",
"ABT",
"DHR",
"BMY",
"PG",
"KO",
"PEP",
"WMT",
"HD",
"MCD",
"NKE",
"SBUX",
"TGT",
"COST",
"CAT",
"DE",
"BA",
"HON",
"UPS",
"RTX",
"LMT",
"GE",
"MMM",
"EMR",
"XOM",
"CVX",
"COP",
"EOG",
"SLB",
"MPC",
"PSX",
"VLO",
"OXY",
"HAL",
][:n_stocks]
print(f"Downloading {n_stocks} S&P 500 stocks...")
data = yf.download(tickers, period=period, progress=False, threads=False)
if "Adj Close" in data.columns.get_level_values(0):
prices = data["Adj Close"]
else:
prices = data["Close"]
prices = prices.dropna(axis=1, thresh=len(prices) * 0.9).dropna()
returns = prices.pct_change().dropna()
# For portfolio: X = Cholesky of covariance, y = expected returns
mu = returns.mean().values * 252
Sigma = returns.cov().values * 252 + 1e-6 * np.eye(len(mu))
L = np.linalg.cholesky(Sigma)
dataset = Dataset(
name=f"S&P500 ({len(mu)} stocks)",
source="Yahoo Finance",
X=L.T, # Cholesky factor
y=np.zeros(len(mu)), # For min variance
description=f"{len(mu)} stocks, {len(returns)} trading days, covariance matrix",
)
with open(cache_file, "wb") as f:
pickle.dump(dataset, f)
return dataset
# ============================================================================
# SOLVERS
# ============================================================================
def solve_lasso_pogs(
X: np.ndarray, y: np.ndarray, lambd: float, verbose: bool = False
) -> BenchmarkResult:
if not HAS_POGS:
return BenchmarkResult("pogs", 0, float("nan"), "unavailable")
try:
start = time.perf_counter()
result = solve_lasso(X, y, lambd, verbose=1 if verbose else 0)
elapsed = time.perf_counter() - start
return BenchmarkResult(
solver="pogs",
time_sec=elapsed,
optval=result["optval"],
status="optimal" if result["status"] == 0 else "error",
iterations=result["num_iters"],
)
except Exception:
return BenchmarkResult("pogs", 0, float("nan"), "error")
def solve_lasso_cvxpy(
X: np.ndarray, y: np.ndarray, lambd: float, solver_name: str
) -> BenchmarkResult:
if not HAS_CVXPY:
return BenchmarkResult(solver_name, 0, float("nan"), "unavailable")
solver_map = {"osqp": cp.OSQP, "scs": cp.SCS, "clarabel": cp.CLARABEL}
try:
n = X.shape[1]
w = cp.Variable(n)
objective = 0.5 * cp.sum_squares(X @ w - y) + lambd * cp.norm1(w)
prob = cp.Problem(cp.Minimize(objective))
start = time.perf_counter()
prob.solve(solver=solver_map[solver_name], verbose=False)
elapsed = time.perf_counter() - start
return BenchmarkResult(
solver=solver_name,
time_sec=elapsed,
optval=prob.value if prob.value else float("nan"),
status=prob.status,
iterations=getattr(prob.solver_stats, "num_iters", None) if prob.solver_stats else None,
)
except Exception:
return BenchmarkResult(solver_name, 0, float("nan"), "error")
def solve_ridge_pogs(X: np.ndarray, y: np.ndarray, lambd: float) -> BenchmarkResult:
if not HAS_POGS:
return BenchmarkResult("pogs", 0, float("nan"), "unavailable")
try:
start = time.perf_counter()
result = solve_ridge(X, y, lambd, verbose=0)
elapsed = time.perf_counter() - start
return BenchmarkResult(
solver="pogs",
time_sec=elapsed,
optval=result["optval"],
status="optimal" if result["status"] == 0 else "error",
iterations=result["num_iters"],
)
except:
return BenchmarkResult("pogs", 0, float("nan"), "error")
def solve_ridge_cvxpy(
X: np.ndarray, y: np.ndarray, lambd: float, solver_name: str
) -> BenchmarkResult:
if not HAS_CVXPY:
return BenchmarkResult(solver_name, 0, float("nan"), "unavailable")
solver_map = {"osqp": cp.OSQP, "scs": cp.SCS, "clarabel": cp.CLARABEL}
try:
n = X.shape[1]
w = cp.Variable(n)
objective = 0.5 * cp.sum_squares(X @ w - y) + lambd * cp.sum_squares(w)
prob = cp.Problem(cp.Minimize(objective))
start = time.perf_counter()
prob.solve(solver=solver_map[solver_name], verbose=False)
elapsed = time.perf_counter() - start
return BenchmarkResult(
solver=solver_name,
time_sec=elapsed,
optval=prob.value if prob.value else float("nan"),
status=prob.status,
)
except:
return BenchmarkResult(solver_name, 0, float("nan"), "error")
# ============================================================================
# MAIN BENCHMARK
# ============================================================================
def run_benchmark():
print("=" * 80)
print("POGS COMPREHENSIVE BENCHMARK - REAL INDUSTRY DATA")
print("=" * 80)
print()
print("All datasets are REAL - sourced from UCI, Yahoo Finance, etc.")
print("No synthetic/random data.")
print()
# Load datasets
datasets = []
print("Loading datasets...")
print("-" * 40)
try:
datasets.append(load_diabetes())
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ Diabetes: {e}")
try:
datasets.append(load_boston_housing())
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ Boston Housing: {e}")
try:
datasets.append(load_energy_efficiency())
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ Energy Efficiency: {e}")
try:
datasets.append(load_concrete())
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ Concrete: {e}")
try:
datasets.append(load_wine_quality())
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ Wine Quality: {e}")
try:
datasets.append(load_california_housing())
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ California Housing: {e}")
if HAS_YFINANCE:
for n in [30, 50]:
try:
datasets.append(load_sp500_returns(n))
print(f" ✓ {datasets[-1].name}: {datasets[-1].X.shape}")
except Exception as e:
print(f" ✗ S&P500 ({n}): {e}")
print()
if not datasets:
print("ERROR: No datasets loaded!")
return
# Run benchmarks
solvers = ["pogs", "osqp", "scs", "clarabel"]
all_results = []
# LASSO benchmarks
print("=" * 80)
print("LASSO REGRESSION: min 0.5||Xw - y||² + λ||w||₁")
print("=" * 80)
print()
print(f"{'Dataset':<25} {'Size':>12} |", end="")
for s in solvers:
print(f" {s:>10}", end="")
print(" | Winner")
print("-" * (25 + 13 + 11 * len(solvers) + 10))
for ds in datasets:
m, n = ds.X.shape
lambd = 0.1 * np.linalg.norm(ds.X.T @ ds.y, np.inf) / m
results = {}
for solver in solvers:
if solver == "pogs":
results[solver] = solve_lasso_pogs(ds.X, ds.y, lambd)
else:
results[solver] = solve_lasso_cvxpy(ds.X, ds.y, lambd, solver)
all_results.append((ds.name, "lasso", results[solver]))
print(f"{ds.name:<25} {m:>5}x{n:<5} |", end="")
times = {}
for s in solvers:
r = results[s]
if r.status in ["optimal", "optimal_inaccurate"]:
print(f" {r.time_sec * 1000:>8.1f}ms", end="")
times[s] = r.time_sec
else:
print(f" {'FAIL':>10}", end="")
if times:
winner = min(times, key=times.get)
if winner == "pogs" and len(times) > 1:
others = [t for s, t in times.items() if s != "pogs"]
speedup = min(others) / times["pogs"] if others else 1
print(f" | {winner} ({speedup:.1f}x)")
else:
print(f" | {winner}")
else:
print(" | N/A")
# RIDGE benchmarks
print()
print("=" * 80)
print("RIDGE REGRESSION: min 0.5||Xw - y||² + λ||w||²")
print("=" * 80)
print()
print(f"{'Dataset':<25} {'Size':>12} |", end="")
for s in solvers:
print(f" {s:>10}", end="")
print(" | Winner")
print("-" * (25 + 13 + 11 * len(solvers) + 10))
for ds in datasets:
m, n = ds.X.shape
lambd = 0.1
results = {}
for solver in solvers:
if solver == "pogs":
results[solver] = solve_ridge_pogs(ds.X, ds.y, lambd)
else:
results[solver] = solve_ridge_cvxpy(ds.X, ds.y, lambd, solver)
all_results.append((ds.name, "ridge", results[solver]))
print(f"{ds.name:<25} {m:>5}x{n:<5} |", end="")
times = {}
for s in solvers:
r = results[s]
if r.status in ["optimal", "optimal_inaccurate"]:
print(f" {r.time_sec * 1000:>8.1f}ms", end="")
times[s] = r.time_sec
else:
print(f" {'FAIL':>10}", end="")
if times:
winner = min(times, key=times.get)
if winner == "pogs" and len(times) > 1:
others = [t for s, t in times.items() if s != "pogs"]
speedup = min(others) / times["pogs"] if others else 1
print(f" | {winner} ({speedup:.1f}x)")
else:
print(f" | {winner}")
else:
print(" | N/A")
# Summary
print()
print("=" * 80)
print("SUMMARY")
print("=" * 80)
wins = dict.fromkeys(solvers, 0)
times_by_solver = {s: [] for s in solvers}
from collections import defaultdict
grouped = defaultdict(dict)
for name, ptype, result in all_results:
key = (name, ptype)
grouped[key][result.solver] = result
if result.status in ["optimal", "optimal_inaccurate"]:
times_by_solver[result.solver].append(result.time_sec)
for key, res in grouped.items():
valid = {
s: r.time_sec for s, r in res.items() if r.status in ["optimal", "optimal_inaccurate"]
}
if valid:
winner = min(valid, key=valid.get)
wins[winner] += 1
total = sum(wins.values())
print(f"\n{'Solver':<12} {'Wins':>6} {'Win %':>8} {'Geom Mean':>12}")
print("-" * 42)
for solver in solvers:
times = times_by_solver[solver]
pct = 100 * wins[solver] / total if total > 0 else 0
if times:
geom_mean = np.exp(np.mean(np.log(times))) * 1000
print(f"{solver:<12} {wins[solver]:>6} {pct:>7.1f}% {geom_mean:>10.1f}ms")
else:
print(f"{solver:<12} {wins[solver]:>6} {pct:>7.1f}% {'N/A':>12}")
# POGS speedups
print("\nPOGS Performance:")
pogs_speedups = []
for key, res in grouped.items():
valid = {
s: r.time_sec for s, r in res.items() if r.status in ["optimal", "optimal_inaccurate"]
}
if "pogs" in valid and len(valid) > 1:
pogs_time = valid["pogs"]
others = [t for s, t in valid.items() if s != "pogs"]
if others:
speedup = min(others) / pogs_time
pogs_speedups.append(speedup)
if pogs_speedups:
print(
f" Benchmarks where POGS faster: {sum(1 for s in pogs_speedups if s > 1)}/{len(pogs_speedups)}"
)
print(f" Min speedup: {min(pogs_speedups):.2f}x")
print(f" Max speedup: {max(pogs_speedups):.2f}x")
print(f" Geometric mean speedup: {np.exp(np.mean(np.log(pogs_speedups))):.2f}x")
print()
print("Data sources:")
for ds in datasets:
print(f" - {ds.name}: {ds.source}")
if __name__ == "__main__":
run_benchmark()