spatial_graph_algorithms.compare
Helpers for comparative simulation, denoising, reconstruction, and benchmark-gym
studies. Runners return a ComparisonResult with built-in summary, ranking,
delta, plotting, and I/O helpers.
API Reference
spatial_graph_algorithms.compare.ComparisonResult
dataclass
Results of a multi-method reconstruction comparison study.
Wraps the raw tidy DataFrame produced by :func:run_comparison and
exposes convenience methods for summarising, ranking, and plotting
without boilerplate pandas.
The raw DataFrame is always accessible via :attr:df.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
One row per |
required |
Examples:
>>> from spatial_graph_algorithms.compare import parameter_grid, run_comparison
>>> graphs = parameter_grid(cases=[{"n": 50, "mode": "knn", "k": 4}])
>>> recons = parameter_grid(cases=[{"method": "mds"}])
>>> result = run_comparison(graph_specs=graphs, reconstruction_specs=recons, seeds=[1])
>>> isinstance(result.df, pd.DataFrame)
True
Source code in src/spatial_graph_algorithms/compare/__init__.py
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 | |
Methods:
summary(*, by=None, metrics=None)
Return mean metrics grouped by method and graph condition.
Only rows with status == "ok" are included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
list of str
|
Columns to group by. Default is |
None
|
metrics
|
list of str
|
Metric columns to aggregate. Default is |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Mean of each metric for each group. Groups with no successful rows are absent. |
Examples:
>>> result.summary()
cpd knn
graph_label method
mode=knn__k=4 landmark_mds 0.8821 0.7341
mds 0.7512 0.6103
Source code in src/spatial_graph_algorithms/compare/__init__.py
best(*, metric='cpd', by=None, higher_is_better=True)
Return the best-performing method per group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
str
|
Metric column to rank by. Default is |
'cpd'
|
by
|
list of str
|
Grouping columns. Default is |
None
|
higher_is_better
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per unique |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Source code in src/spatial_graph_algorithms/compare/__init__.py
delta(*, metrics=None, baseline='none', denoise_col='denoise_label', by=None)
Return metric deltas relative to a baseline denoising condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
list of str
|
Metric columns to compare. Default is |
None
|
baseline
|
str
|
Baseline value in denoise_col. Default is |
'none'
|
denoise_col
|
str
|
Column identifying the denoising condition. Default is
|
'denoise_label'
|
by
|
list of str
|
Columns that identify matched rows. Default is
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Successful non-baseline rows with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required columns are missing. |
Examples:
Source code in src/spatial_graph_algorithms/compare/__init__.py
plot(*, metric='cpd', by='method', hue='graph_label', ax=None)
Bar chart of a quality metric grouped by method and condition.
Means are computed over all successful rows (status == "ok").
Error bars show one standard deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
str
|
Metric column to plot. Default is |
'cpd'
|
by
|
str
|
Column that defines the x-axis categories. Default is
|
'method'
|
hue
|
str
|
Column that defines the colour grouping. Default is
|
'graph_label'
|
ax
|
Axes
|
Axes to draw on. A new figure is created when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Source code in src/spatial_graph_algorithms/compare/__init__.py
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 | |
save(path)
Save results to a CSV or Parquet file.
The format is inferred from the file extension (.parquet → Parquet,
anything else → CSV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination path. Parent directories are created automatically. |
required |
Examples:
Source code in src/spatial_graph_algorithms/compare/__init__.py
load(path)
classmethod
Load results previously saved with :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to a CSV or Parquet file created by :meth: |
required |
Returns:
| Type | Description |
|---|---|
ComparisonResult
|
|
Examples:
Source code in src/spatial_graph_algorithms/compare/__init__.py
spatial_graph_algorithms.compare.parameter_grid(*, base=None, vary=None, cases=None, groups=None, where=None, label_keys=None, drop_none=False)
Build a list of parameter dictionaries for comparison studies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
mapping
|
Parameters shared by every cartesian product case. |
None
|
vary
|
mapping
|
Parameter values to expand using :func: |
None
|
cases
|
iterable of mapping
|
Explicit hand-picked cases. Useful for non-cartesian comparisons. |
None
|
groups
|
iterable of mapping
|
Multiple grid definitions. Each group can contain |
None
|
where
|
callable
|
Predicate used to keep or discard expanded specs. |
None
|
label_keys
|
iterable of str
|
Keys used to auto-generate |
None
|
drop_none
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
list of dict
|
Parameter specs. Each spec has a readable |
Examples:
>>> from spatial_graph_algorithms.compare import parameter_grid
>>> parameter_grid(base={"n": 100}, vary={"mode": ["knn"], "k": [4, 8]})
[{'_label': 'mode=knn__k=4', 'n': 100, 'mode': 'knn', 'k': 4}, ...]
Source code in src/spatial_graph_algorithms/compare/__init__.py
spatial_graph_algorithms.compare.dry_run_comparison(*, graph_specs, reconstruction_specs, seeds)
Preview comparison combinations without generating graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_specs
|
iterable of mapping
|
Graph-generation specs, usually returned by :func: |
required |
reconstruction_specs
|
iterable of mapping
|
Reconstruction specs, usually returned by :func: |
required |
seeds
|
iterable of int
|
Top-level seeds to combine with each graph and reconstruction spec. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per planned |
Source code in src/spatial_graph_algorithms/compare/__init__.py
spatial_graph_algorithms.compare.run_comparison(*, graph_specs, reconstruction_specs, seeds, dim=None, k_neighbors=15, compute_distortion=False, verbose=True)
Run a simulation/reconstruction comparison and return a :class:ComparisonResult.
Each graph spec is generated once per seed. All reconstruction specs are then applied to that graph, so generation cost is not repeated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_specs
|
iterable of mapping
|
Specs passed to :func: |
required |
reconstruction_specs
|
iterable of mapping
|
Specs passed to :func: |
required |
seeds
|
iterable of int
|
Top-level seeds. Each graph spec is generated once per seed, then all reconstruction specs are run against that graph. |
required |
dim
|
int
|
Reconstruction dimensionality. Defaults to the graph spec |
None
|
k_neighbors
|
int
|
Number of neighbours for reconstruction quality KNN evaluation. |
15
|
compute_distortion
|
bool
|
Whether to compute the O(n²) distortion metric. |
False
|
verbose
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ComparisonResult
|
One row per |
Examples:
>>> from spatial_graph_algorithms.compare import parameter_grid, run_comparison
>>> graphs = parameter_grid(cases=[{"n": 50, "mode": "knn", "k": 4}])
>>> recons = parameter_grid(cases=[{"method": "mds"}])
>>> result = run_comparison(
... graph_specs=graphs, reconstruction_specs=recons, seeds=[1], verbose=False
... )
>>> result.df["status"].iloc[0]
'ok'
Source code in src/spatial_graph_algorithms/compare/__init__.py
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 | |
spatial_graph_algorithms.compare.run_denoise_comparison(*, graph_specs, denoise_specs, seeds, k_neighbors=15, compute_distortion=False, verbose=True)
Run a simulated denoising benchmark and return tidy quality metrics.
Each graph spec is generated once per seed, then every denoising spec is
scored and filtered on that graph. Ground-truth false-edge labels from
simulation are evaluated with :func:spatial_graph_algorithms.metrics.evaluate_denoising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_specs
|
iterable of mapping
|
Specs passed to :func: |
required |
denoise_specs
|
iterable of mapping
|
Denoising specs. Each spec must include |
required |
seeds
|
iterable of int
|
Top-level seeds for graph generation and stochastic scorers. |
required |
k_neighbors
|
int
|
Number of neighbours used when graph-level metrics are computed. |
15
|
compute_distortion
|
bool
|
Whether to compute O(n²) distortion for generated graphs. |
False
|
verbose
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ComparisonResult
|
One row per |
Examples:
>>> graphs = parameter_grid(cases=[{"n": 50, "false_edge_fraction": 0.1}])
>>> denoisers = parameter_grid(cases=[{"method": "jaccard", "fraction_to_remove": 0.05}])
>>> result = run_denoise_comparison(
... graph_specs=graphs, denoise_specs=denoisers, seeds=[0], verbose=False
... )
>>> "f1" in result.df.columns
True
Source code in src/spatial_graph_algorithms/compare/__init__.py
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 | |
spatial_graph_algorithms.compare.run_pipeline_comparison(*, graph_specs, reconstruction_specs, denoise_specs, seeds, include_raw_baseline=True, dim=None, k_neighbors=15, compute_distortion=False, verbose=True)
Run denoise-to-reconstruction comparisons on simulated graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_specs
|
iterable of mapping
|
Specs passed to :func: |
required |
reconstruction_specs
|
iterable of mapping
|
Specs passed to :func: |
required |
denoise_specs
|
iterable of mapping
|
Denoising specs applied before reconstruction. |
required |
seeds
|
iterable of int
|
Top-level seeds for graph generation, denoising, and reconstruction. |
required |
include_raw_baseline
|
bool
|
If |
True
|
dim
|
int
|
Reconstruction dimensionality. Defaults to graph spec |
None
|
k_neighbors
|
int
|
Number of neighbours for reconstruction quality KNN evaluation. |
15
|
compute_distortion
|
bool
|
Whether to compute the O(n²) distortion metric. |
False
|
verbose
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ComparisonResult
|
One row per graph, denoising condition, seed, and reconstruction spec. |
Examples:
>>> graphs = parameter_grid(cases=[{"n": 50, "false_edge_fraction": 0.1}])
>>> denoisers = parameter_grid(cases=[{"method": "jaccard", "fraction_to_remove": 0.05}])
>>> recons = parameter_grid(cases=[{"method": "mds"}])
>>> result = run_pipeline_comparison(
... graph_specs=graphs, reconstruction_specs=recons,
... denoise_specs=denoisers, seeds=[0], verbose=False
... )
>>> set(result.df["denoise_label"]) == {"none", denoisers[0]["_label"]}
True
Source code in src/spatial_graph_algorithms/compare/__init__.py
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 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
spatial_graph_algorithms.compare.benchmark_io.save_benchmark_graph(sg, path, *, metadata=None)
Save a benchmark graph as inspectable array, table, and JSON files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sg
|
SpatialGraph
|
Graph instance to save. |
required |
path
|
str or Path
|
Destination directory. It is created when missing. |
required |
metadata
|
dict
|
Extra graph-level metadata written to |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Examples:
>>> from tempfile import TemporaryDirectory
>>> from spatial_graph_algorithms.simulate import generate
>>> from spatial_graph_algorithms.compare.benchmark_io import save_benchmark_graph
>>> with TemporaryDirectory() as tmp:
... save_benchmark_graph(generate(n=20, seed=0), tmp)
Source code in src/spatial_graph_algorithms/compare/benchmark_io.py
spatial_graph_algorithms.compare.benchmark_io.load_benchmark_graph(path)
Load a benchmark graph saved by :func:save_benchmark_graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Benchmark graph directory. |
required |
Returns:
| Type | Description |
|---|---|
SpatialGraph
|
Materialized graph with adjacency, positions, and metadata restored. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the directory or required adjacency file does not exist. |
Examples:
>>> from tempfile import TemporaryDirectory
>>> from spatial_graph_algorithms.simulate import generate
>>> from spatial_graph_algorithms.compare.benchmark_io import (
... load_benchmark_graph, save_benchmark_graph,
... )
>>> with TemporaryDirectory() as tmp:
... save_benchmark_graph(generate(n=20, seed=0), tmp)
... sg = load_benchmark_graph(tmp)
>>> sg.n_nodes
20
Source code in src/spatial_graph_algorithms/compare/benchmark_io.py
spatial_graph_algorithms.compare.benchmark_io.graph_difficulty_metadata(sg)
Compute false-edge burden metadata for a benchmark graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sg
|
SpatialGraph
|
Graph with optional |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Edge counts and false-edge ratios. Values are |
Examples:
>>> from spatial_graph_algorithms.simulate import generate
>>> from spatial_graph_algorithms.compare.benchmark_io import graph_difficulty_metadata
>>> meta = graph_difficulty_metadata(generate(n=50, false_edge_fraction=0.1, seed=0))
>>> "n_false_edges" in meta
True
Source code in src/spatial_graph_algorithms/compare/benchmark_io.py
spatial_graph_algorithms.compare.gym.BenchmarkSuite
dataclass
Describe a materialized benchmark suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Stable suite name. |
required |
root
|
Path
|
Directory containing the manifest and graph files. |
required |
manifest
|
dict
|
Parsed manifest payload. |
required |
Examples:
>>> suite = BenchmarkSuite(name="demo", root=Path("."), manifest={"name": "demo"})
>>> suite.name
'demo'
Source code in src/spatial_graph_algorithms/compare/gym.py
Attributes
description
property
Return the suite description from the manifest.
rationale
property
Return the suite rationale from the manifest.
graph_paths
property
Return materialized graph directories declared by the manifest.
tasks
property
Return task definitions keyed by task name.
spatial_graph_algorithms.compare.gym.list_suites(*, benchmark_root='data/benchmark')
List benchmark suites with manifests under benchmark_root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark_root
|
str or Path
|
Directory containing suite subdirectories. Default is
|
'data/benchmark'
|
Returns:
| Type | Description |
|---|---|
list of str
|
Suite names sorted alphabetically. |
Examples:
Source code in src/spatial_graph_algorithms/compare/gym.py
spatial_graph_algorithms.compare.gym.load_suite(suite, *, benchmark_root='data/benchmark')
Load a benchmark suite manifest by name or path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
suite
|
str or Path
|
Suite name under benchmark_root, suite directory, or manifest file. |
required |
benchmark_root
|
str or Path
|
Directory searched when suite is a name. Default is
|
'data/benchmark'
|
Returns:
| Type | Description |
|---|---|
BenchmarkSuite
|
Parsed suite definition. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no manifest can be found. |
ValueError
|
If the manifest does not contain a |
Examples:
>>> from tempfile import TemporaryDirectory
>>> with TemporaryDirectory() as tmp:
... root = Path(tmp) / "demo"
... root.mkdir()
... _ = (root / "manifest.json").write_text('{"name": "demo"}')
... suite = load_suite(root)
>>> suite.name
'demo'
Source code in src/spatial_graph_algorithms/compare/gym.py
spatial_graph_algorithms.compare.gym.run_suite(suite, *, task, benchmark_root='data/benchmark', k_neighbors=15, compute_distortion=False, checkpoint_dir=None, resume=True, verbose=True)
Run one benchmark task over a materialized suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
suite
|
str, Path, or BenchmarkSuite
|
Suite name, manifest path, suite directory, or loaded suite. |
required |
task
|
('denoise', 'reconstruction', 'pipeline')
|
Benchmark task to run. |
"denoise"
|
benchmark_root
|
str or Path
|
Suite root used when suite is a name. Default is
|
'data/benchmark'
|
k_neighbors
|
int
|
Number of neighbours for KNN reconstruction quality. |
15
|
compute_distortion
|
bool
|
Whether to compute O(n²) distortion during reconstruction tasks. |
False
|
checkpoint_dir
|
str or Path
|
Directory for a crash-safe JSONL checkpoint. When given, every finished
row is appended to |
None
|
resume
|
bool
|
When |
True
|
verbose
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ComparisonResult
|
Tidy benchmark results. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the task is unsupported or the suite has no materialized graphs. |
Examples:
Source code in src/spatial_graph_algorithms/compare/gym.py
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 | |
spatial_graph_algorithms.compare.datasets.list_experimental_datasets()
List built-in experimental benchmark dataset names.
Returns:
| Type | Description |
|---|---|
list of str
|
Dataset names sorted alphabetically. |
Examples:
Source code in src/spatial_graph_algorithms/compare/datasets.py
spatial_graph_algorithms.compare.datasets.load_experimental_dataset(name, *, data_root='data')
Load an experimental graph and attach available ground-truth positions.
Nodes absent from original_positions.csv receive NaN coordinates.
:func:spatial_graph_algorithms.metrics.evaluate automatically excludes
those rows from CPD/KNN computations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
One of :func: |
required |
data_root
|
str or Path
|
Directory containing experimental dataset subdirectories. Default is
|
'data'
|
Returns:
| Type | Description |
|---|---|
SpatialGraph
|
Loaded graph with partial |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is unknown. |
FileNotFoundError
|
If required dataset files are missing. |
Examples:
Source code in src/spatial_graph_algorithms/compare/datasets.py
spatial_graph_algorithms.compare.report.status_counts(result)
Count result rows by status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ComparisonResult
|
Result table to summarise. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
Examples:
>>> import pandas as pd
>>> from spatial_graph_algorithms.compare import ComparisonResult
>>> status_counts(ComparisonResult(pd.DataFrame({"status": ["ok", "ok"]})))["n_rows"].iloc[0]
2
Source code in src/spatial_graph_algorithms/compare/report.py
spatial_graph_algorithms.compare.report.failed_rows(result)
Return non-successful rows with identifying columns and errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ComparisonResult
|
Result table to inspect. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Failed rows restricted to stable identification and error columns. |
Examples:
>>> import pandas as pd
>>> from spatial_graph_algorithms.compare import ComparisonResult
>>> failed_rows(ComparisonResult(pd.DataFrame({"status": ["ok"]}))).empty
True
Source code in src/spatial_graph_algorithms/compare/report.py
spatial_graph_algorithms.compare.report.gym_leaderboard(result, *, task, suite=None, primary_metric=None, group_by=None)
Aggregate and rank benchmark gym results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ComparisonResult
|
Raw benchmark result. |
required |
task
|
('denoise', 'reconstruction', 'pipeline')
|
Task schema to use for method columns and default metrics. |
"denoise"
|
suite
|
BenchmarkSuite
|
Suite manifest used to read task-level primary and secondary metrics. |
None
|
primary_metric
|
str
|
Metric used for ranking. Overrides the suite manifest and defaults. |
None
|
group_by
|
list of str
|
Extra grouping columns. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Ranked aggregate table with mean/std metric columns and row counts. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If task is unknown or the primary metric is unavailable. |
Examples:
>>> import pandas as pd
>>> from spatial_graph_algorithms.compare import ComparisonResult
>>> df = pd.DataFrame({"status": ["ok"], "method": ["mds"], "cpd": [0.8]})
>>> gym_leaderboard(ComparisonResult(df), task="reconstruction")["rank"].iloc[0]
1
Source code in src/spatial_graph_algorithms/compare/report.py
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 | |
spatial_graph_algorithms.compare.report.gym_plots(result, *, task, suite=None)
Create a small set of labelled benchmark report plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ComparisonResult
|
Benchmark result to plot. |
required |
task
|
('denoise', 'reconstruction', 'pipeline')
|
Task schema. |
"denoise"
|
suite
|
BenchmarkSuite
|
Suite manifest used for metric defaults. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Figure]
|
Mapping from stable plot name to figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If task is unknown. |
Examples:
>>> import pandas as pd
>>> from spatial_graph_algorithms.compare import ComparisonResult
>>> df = pd.DataFrame({"status": ["ok"], "method": ["mds"], "cpd": [0.8]})
>>> plots = gym_plots(ComparisonResult(df), task="reconstruction")
>>> "quality_bar" in plots
True
Source code in src/spatial_graph_algorithms/compare/report.py
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 | |
spatial_graph_algorithms.compare.report.gym_report(results, *, outdir, suite=None, title=None)
Write a Markdown benchmark report with CSV tables and PNG plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
mapping
|
Mapping from task name to :class: |
required |
outdir
|
str or Path
|
Destination directory. It is created when missing. |
required |
suite
|
BenchmarkSuite
|
Suite metadata used for report description and manifest metrics. |
None
|
title
|
str
|
Report title. Defaults to the suite name when available. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written |
Raises:
| Type | Description |
|---|---|
ValueError
|
If results contains an unsupported task name. |
Examples:
>>> import pandas as pd
>>> from tempfile import TemporaryDirectory
>>> from spatial_graph_algorithms.compare import ComparisonResult
>>> with TemporaryDirectory() as tmp:
... result = ComparisonResult(pd.DataFrame({
... "status": ["ok"], "method": ["mds"], "cpd": [0.8],
... }))
... path = gym_report({"reconstruction": result}, outdir=tmp)
>>> path.name
'report.md'
Source code in src/spatial_graph_algorithms/compare/report.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 | |