Add files using upload-large-folder tool
Browse files- .gitattributes +11 -57
- 1024x1024/dataset.ipynb +3 -0
- 128x128/dataset.ipynb +0 -0
- 128x128_samples/calibration/data-00000.parquet +3 -0
- 128x128_samples/test/data-00000.parquet +3 -0
- 128x128_samples/train/data-00000.parquet +3 -0
- 128x128_samples/validation/data-00000.parquet +3 -0
- 2048x2048/dataset.ipynb +3 -0
- 256x256/dataset.ipynb +3 -0
- 256x256_samples/calibration/data-00000.parquet +3 -0
- 256x256_samples/test/data-00000.parquet +3 -0
- 256x256_samples/train/data-00000.parquet +3 -0
- 256x256_samples/validation/data-00000.parquet +3 -0
- 4096x4096/dataset.ipynb +3 -0
- 512x512/dataset.ipynb +3 -0
- 64x64/dataset.ipynb +0 -0
- 64x64/train/data-00001.parquet +3 -0
- 64x64/train/data-00002.parquet +3 -0
- 64x64/train/data-00003.parquet +3 -0
- 64x64/train/data-00004.parquet +3 -0
- 64x64/train/data-00007.parquet +3 -0
- 64x64/train/data-00011.parquet +3 -0
- 64x64/train/data-00014.parquet +3 -0
- 64x64/train/data-00019.parquet +3 -0
- 64x64/train/data-00024.parquet +3 -0
- 64x64/train/data-00039.parquet +3 -0
- 64x64/train/data-00043.parquet +3 -0
- 64x64_samples/calibration/data-00000.parquet +3 -0
- 64x64_samples/test/data-00000.parquet +3 -0
- 64x64_samples/train/data-00000.parquet +3 -0
- 64x64_samples/validation/data-00000.parquet +3 -0
- CHANGELOG.md +17 -0
- CITATION.cff +26 -0
- DATASET_LICENSE.md +19 -0
- DATASHEET.md +191 -0
- LICENSE +21 -0
- README.md +0 -0
- assets/banner.png +3 -0
- assets/download.png +3 -0
- assets/hold_out_mask.png +3 -0
- assets/sample.png +3 -0
- calibration/calibrate.json +0 -0
- calibration/max_elevation_map.png +3 -0
- calibration/ptp_elevation_map.png +3 -0
- croissant.json +452 -0
- notebooks/astar_inference_timing.ipynb +505 -0
- notebooks/costmodel.ipynb +1200 -0
- notebooks/demo.ipynb +361 -0
- notebooks/obstacles.ipynb +435 -0
- notebooks/solve.ipynb +684 -0
.gitattributes
CHANGED
|
@@ -1,60 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.avro filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.lz4 filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.mds filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.
|
| 23 |
-
*.
|
| 24 |
-
*.
|
|
|
|
|
|
|
| 25 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 28 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 36 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 37 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 38 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 39 |
-
# Audio files - uncompressed
|
| 40 |
-
*.pcm filter=lfs diff=lfs merge=lfs -text
|
| 41 |
-
*.sam filter=lfs diff=lfs merge=lfs -text
|
| 42 |
-
*.raw filter=lfs diff=lfs merge=lfs -text
|
| 43 |
-
# Audio files - compressed
|
| 44 |
-
*.aac filter=lfs diff=lfs merge=lfs -text
|
| 45 |
-
*.flac filter=lfs diff=lfs merge=lfs -text
|
| 46 |
-
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 47 |
-
*.ogg filter=lfs diff=lfs merge=lfs -text
|
| 48 |
-
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 49 |
-
# Image files - uncompressed
|
| 50 |
-
*.bmp filter=lfs diff=lfs merge=lfs -text
|
| 51 |
-
*.gif filter=lfs diff=lfs merge=lfs -text
|
| 52 |
-
*.png filter=lfs diff=lfs merge=lfs -text
|
| 53 |
-
*.tiff filter=lfs diff=lfs merge=lfs -text
|
| 54 |
-
# Image files - compressed
|
| 55 |
-
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 56 |
-
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 57 |
-
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 58 |
-
# Video files - compressed
|
| 59 |
-
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
-
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
# Hugging Face LFS — managed by `passage export`. Edit by regenerating with --force-gitattributes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.npy.zst filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 8 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 9 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
256x256/dataset.ipynb filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
2048x2048/dataset.ipynb filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
4096x4096/dataset.ipynb filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
512x512/dataset.ipynb filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
1024x1024/dataset.ipynb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1024x1024/dataset.ipynb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6e215650d9e8ba4826fe81ab7a50f532832b608213a02965a29ef680b2cf8f50
|
| 3 |
+
size 25106480
|
128x128/dataset.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
128x128_samples/calibration/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75d329f076d749b5b468c7a69d8e9725c7d576b29e92d837259c6b8afed0c0d6
|
| 3 |
+
size 4387435
|
128x128_samples/test/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c111f3a7bb1207da77864c68fb3f6858f9588552cae82e35e8b54a2cc64c998a
|
| 3 |
+
size 4882875
|
128x128_samples/train/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:adfd7756580df68705034160c45343b5678e379b9d38c88598b1a04ea58e00b3
|
| 3 |
+
size 4647544
|
128x128_samples/validation/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fc6df21092cb8ed1a014d38ce66e0b00829e1948bbc450e02c88b80c2d3b24f
|
| 3 |
+
size 4221782
|
2048x2048/dataset.ipynb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f97c38619bd24e7e54fc64fa83c499501404053081c5a76c8db16f6f60dc1687
|
| 3 |
+
size 23181539
|
256x256/dataset.ipynb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99fe9dccbce8a9bae640e9886b77a957a7cf058a953acca27febfc0a5e245031
|
| 3 |
+
size 18419272
|
256x256_samples/calibration/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8be604ceabe8f649339c0d24ff2d2bbd4a1099073f2d9c8fd7d1a23c846cec47
|
| 3 |
+
size 14654757
|
256x256_samples/test/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9eb4d85bf1b42a83215362daf0b198500a0fdbb5ab380321260a9df47d16ff75
|
| 3 |
+
size 16033785
|
256x256_samples/train/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:963b3141e75c82e75385beebd720d557946f2d287c94e231b0c852ab41ecb0a5
|
| 3 |
+
size 14356660
|
256x256_samples/validation/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7467fa3c4ab3be11eea39b9dbafb81e905244187b56628cb78fdc637d348b638
|
| 3 |
+
size 15008854
|
4096x4096/dataset.ipynb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fa33ca415026055e2ce28e32a92737bfaab2de8a098edd0cd720559282db8db
|
| 3 |
+
size 20276890
|
512x512/dataset.ipynb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b8786f7b1d957ee7e468eb694ba8ddfa2a57d4cb6763de7a1d06a1b266e6efb1
|
| 3 |
+
size 24362766
|
64x64/dataset.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
64x64/train/data-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c685f373a9b8ff1bb3e69807db6d0f4c58fc8a0b282500bf8967f1c2492944c7
|
| 3 |
+
size 157789130
|
64x64/train/data-00002.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a9431fc2366a2656d92bbc42e4934cfb357e7ca687a5503fb781733b09065d48
|
| 3 |
+
size 158705668
|
64x64/train/data-00003.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8b8a85ba8d8f4419f470d85c59c8fe72c3e6bb50142b93160c4d25d9ab3ea29
|
| 3 |
+
size 159006606
|
64x64/train/data-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f43c3ad4542fafe216aa836476ac9ec58333573ce775dff4d121553aff35b57c
|
| 3 |
+
size 158509016
|
64x64/train/data-00007.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:56ddb747bcfd09997bfa2c3848ebf90ed7bc81281653eabf97bc41b938b4be60
|
| 3 |
+
size 158187630
|
64x64/train/data-00011.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1870f83872d7bb68792efaf2a86edcea5f1b7aaf363dcd279d566e6181e0dc5c
|
| 3 |
+
size 158385064
|
64x64/train/data-00014.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2a4c55b95c1ef1ee751e47e2974038bc5207b98aae03a9f76d199b6e52e05f7b
|
| 3 |
+
size 157815831
|
64x64/train/data-00019.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aaf66fbdd11aef7df887e2277e092b1b17de7b12a25f117b5e5c78aafb4fdaff
|
| 3 |
+
size 157704328
|
64x64/train/data-00024.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c51d69d546bf8a4d658fa7c631c1a9c0ebd1650452b887fe973e3a24e2f3e3ff
|
| 3 |
+
size 158089171
|
64x64/train/data-00039.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40b84b7d18290ff7514a02ad2515189007e929c5d5bdd0313a65ae42b74c3191
|
| 3 |
+
size 158153853
|
64x64/train/data-00043.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc346b4cfe76ee22f6e528c4a322ceac2acaa7120aee211a5853c349edbc67c2
|
| 3 |
+
size 157898612
|
64x64_samples/calibration/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:180cc0a0546b083f3ee38ea98866956fb246259fcd896f360e620286081d1c3b
|
| 3 |
+
size 1478003
|
64x64_samples/test/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b820a51627578357c25a932a697c60b00a2ab3d3c43c7cb3d9f95946e1c4e10
|
| 3 |
+
size 1592634
|
64x64_samples/train/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75563398275d5d6d234db931bbf718c6f7fdda8ebba975aa0b1c774586ded51f
|
| 3 |
+
size 1464420
|
64x64_samples/validation/data-00000.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a88a84c65d927eb00f536310503d2097294c98b119779c836ee0316e25f7edcb
|
| 3 |
+
size 1442910
|
CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog
|
| 2 |
+
|
| 3 |
+
## Unreleased
|
| 4 |
+
|
| 5 |
+
### Added
|
| 6 |
+
|
| 7 |
+
- Deterministic per-sample generation seeding via `generation.seed`, with recorded `generation_seed` and `sample_seed` provenance in sample metadata.
|
| 8 |
+
- Repository release metadata files: `CITATION.cff`, `DATASHEET.md`, `croissant.json`, and `Makefile`.
|
| 9 |
+
- `make manifest` workflow for writing `outputs/export/manifest.sha256` from a prepared export tree.
|
| 10 |
+
- `DATASET_LICENSE.md` to document the dataset-side JAXA AW3D30 obligations separately from the MIT code license.
|
| 11 |
+
|
| 12 |
+
### Changed
|
| 13 |
+
|
| 14 |
+
- Corrected public documentation to reflect the default 14,130-sample benchmark size and the current reproducibility contract.
|
| 15 |
+
- Exposed deterministic-generation provenance in the export schema used for Hugging Face parquet preparation.
|
| 16 |
+
- Restored `config/config.yaml` to the 14,130-sample paper benchmark and aligned preview-image defaults with the sample export settings.
|
| 17 |
+
- Made `passage export` stage release metadata files into the export tree, with anonymous submission copies available via `--anonymous`.
|
CITATION.cff
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cff-version: 1.2.0
|
| 2 |
+
title: PASSAGE
|
| 3 |
+
message: If you use PASSAGE, please cite the anonymous submission mirror and the accompanying dataset metadata.
|
| 4 |
+
type: software
|
| 5 |
+
authors:
|
| 6 |
+
- family-names: Anonymous
|
| 7 |
+
given-names: Authors
|
| 8 |
+
version: 0.1.0
|
| 9 |
+
date-released: 2026-03-30
|
| 10 |
+
license: MIT
|
| 11 |
+
repository-code: https://huggingface.co/datasets/thalesgroup/passage
|
| 12 |
+
url: https://huggingface.co/datasets/thalesgroup/passage
|
| 13 |
+
keywords:
|
| 14 |
+
- pathfinding
|
| 15 |
+
- terrain-routing
|
| 16 |
+
- benchmark
|
| 17 |
+
- digital-elevation-model
|
| 18 |
+
- dataset
|
| 19 |
+
preferred-citation:
|
| 20 |
+
type: article
|
| 21 |
+
title: "PASSAGE anonymous submission mirror"
|
| 22 |
+
authors:
|
| 23 |
+
- family-names: Anonymous
|
| 24 |
+
given-names: Authors
|
| 25 |
+
year: 2026
|
| 26 |
+
url: https://huggingface.co/datasets/thalesgroup/passage
|
DATASET_LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PASSAGE Dataset Terms
|
| 2 |
+
|
| 3 |
+
PASSAGE ships two distinct licensing surfaces:
|
| 4 |
+
|
| 5 |
+
- The generator code in this repository is released under the MIT license in `LICENSE`.
|
| 6 |
+
- The exported dataset artifacts inherit obligations from the upstream JAXA ALOS AW3D30 elevation product used to derive the terrain channel.
|
| 7 |
+
|
| 8 |
+
For dataset artifacts distributed on Hugging Face and in release bundles:
|
| 9 |
+
|
| 10 |
+
- Preserve attribution to JAXA ALOS World 3D - 30m (AW3D30) and any other provenance notices carried in the metadata.
|
| 11 |
+
- Do not represent the derived elevation-backed artifacts as public domain.
|
| 12 |
+
- Comply with the upstream AW3D30 usage terms for any redistribution or downstream reuse of the derived terrain data.
|
| 13 |
+
- Treat PASSAGE as a research benchmark, not a safety-of-life product. The dataset and generated paths do not certify operational deployment.
|
| 14 |
+
|
| 15 |
+
When in doubt:
|
| 16 |
+
|
| 17 |
+
- Use `LICENSE` for code questions.
|
| 18 |
+
- Use this file plus `DATASHEET.md` for dataset-distribution questions.
|
| 19 |
+
- Preserve both files when mirroring the release tree.
|
DATASHEET.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PASSAGE Datasheet
|
| 2 |
+
|
| 3 |
+
This Datasheet follows the Gebru et al. [*Datasheets for Datasets*](https://arxiv.org/abs/1803.09010) template and is mirrored in the companion Croissant metadata file (`croissant.json`, conforming to MLCommons Croissant 1.1 and Croissant RAI 1.0). It accompanies the NeurIPS 2026 Evaluations & Datasets Track submission of the PASSAGE benchmark.
|
| 4 |
+
|
| 5 |
+
## Motivation
|
| 6 |
+
|
| 7 |
+
### For what purpose was the dataset created?
|
| 8 |
+
|
| 9 |
+
PASSAGE was created to close a reproducibility gap in *constrained path planning on real terrain*: existing benchmarks either synthesize grids that strip geographic structure, rely on ad-hoc GIS workflows without machine-learning-ready splits, or evaluate embodied perception rather than cost-aware long-horizon routing. PASSAGE provides a real-terrain, multi-resolution benchmark with an enumerable Operational Design Domain (ODD), configurable terrain cost models, procedural obstacles, and exact A* ground-truth labels — packaged as ML-ready Parquet shards with a manifest-checked release tree.
|
| 10 |
+
|
| 11 |
+
### Who created this dataset and on behalf of which entity?
|
| 12 |
+
|
| 13 |
+
The dataset is released for double-blind review as an anonymous submission artifact. Attribution is intentionally withheld in this mirror and restored at camera-ready.
|
| 14 |
+
|
| 15 |
+
### Who funded the creation of the dataset?
|
| 16 |
+
|
| 17 |
+
Anonymous institutional research funding. No external grant is associated with this release.
|
| 18 |
+
|
| 19 |
+
## Composition
|
| 20 |
+
|
| 21 |
+
### What do the instances represent?
|
| 22 |
+
|
| 23 |
+
Each instance is a single path-planning problem on a terrain crop: a three-channel input tensor (elevation, start/goal markers, obstacle mask) at a chosen resolution `N`, plus path annotations (ordered `(row, col)` waypoint lists under each configured cost model), a binary `N×N` path mask per cost model, and structured metadata (source tile, crop bounds, resolution, cost model, weight, obstacle configuration, split, solver backend, path cost, path length, solver wall-clock, seeds).
|
| 24 |
+
|
| 25 |
+
### How many instances are there?
|
| 26 |
+
|
| 27 |
+
The default release emits **14,130 samples** across seven resolutions (64, 128, 256, 512, 1024, 2048, 4096). Per-resolution, per-split counts are recorded in `outputs/paper/results/dataset_statistics.csv` and reported in Table 2 of the paper.
|
| 28 |
+
|
| 29 |
+
### Does the dataset contain all possible instances or is it a sample?
|
| 30 |
+
|
| 31 |
+
PASSAGE is a deterministically seeded *sample* from an enumerable parameter space. Without obstacles, the ODD is finite and fully enumerable: every `(tile, crop, resolution, cost model, weight, start, goal)` maps deterministically to a unique sample. Additional samples can be generated at will with `make rebuild`.
|
| 32 |
+
|
| 33 |
+
### What data does each instance consist of?
|
| 34 |
+
|
| 35 |
+
- `elevation`: real-valued, normalized against globally calibrated min/max.
|
| 36 |
+
- `markers`: binary start/goal channels.
|
| 37 |
+
- `obstacles`: binary forbidden-cell mask (optional; the free-terrain variant is `obstacles=0`).
|
| 38 |
+
- `path_waypoints_<cost_model>`: ordered `(row, col)` pairs.
|
| 39 |
+
- `path_mask_<cost_model>`: binary `N×N`.
|
| 40 |
+
- `metadata`: structured provenance (see Croissant `record_set.metadata`).
|
| 41 |
+
|
| 42 |
+
### Is there a label or target associated with each instance?
|
| 43 |
+
|
| 44 |
+
Yes — reference paths under each cost model. Paths are *computational annotations* produced by the A* solver (grid backend, Numba-JIT), not human annotations. There are no ambiguous or missing labels by construction.
|
| 45 |
+
|
| 46 |
+
### Is any information missing from individual instances?
|
| 47 |
+
|
| 48 |
+
No; every sample is fully populated by the generator. Upstream AW3D30 tiles may carry sensor artifacts (voids, striping); affected samples are flagged in metadata via the source-tile identifier and, where relevant, the elevation calibration bounds.
|
| 49 |
+
|
| 50 |
+
### Are relationships between individual instances made explicit?
|
| 51 |
+
|
| 52 |
+
Yes: samples inherit the `source_tile_id` and `split` fields from their source AW3D30 tile. The geographic hold-out split policy (`split_mask` at 1°/pixel) is versioned alongside the generator configuration.
|
| 53 |
+
|
| 54 |
+
### Are there recommended data splits?
|
| 55 |
+
|
| 56 |
+
Yes — the default split is 90% train / 2% calibration / 4% validation / 4% test, with a *geographic hold-out* for test (entire 1°×1° source tiles are reserved for test; no source tile appears in both train and test).
|
| 57 |
+
|
| 58 |
+
### Are there any errors, sources of noise, or redundancies?
|
| 59 |
+
|
| 60 |
+
The elevation product inherits JAXA ALOS AW3D30 sensor characteristics (DSM error bounds documented upstream). Path annotations are exact under the documented cost model — no stochastic error. Procedural obstacles are abstractions of real hazards and are not validated against real-world obstacle maps.
|
| 61 |
+
|
| 62 |
+
### Is the dataset self-contained, or does it link to other resources?
|
| 63 |
+
|
| 64 |
+
Fully self-contained at the export stage. Raw AW3D30 tiles are re-derivable via `make download` but not shipped in the release.
|
| 65 |
+
|
| 66 |
+
### Does the dataset contain confidential, personally identifiable, sensitive, or offensive information?
|
| 67 |
+
|
| 68 |
+
No. PASSAGE contains no personal data, no biometric data, and no human subjects. Offensive content is not possible in this domain.
|
| 69 |
+
|
| 70 |
+
## Collection Process
|
| 71 |
+
|
| 72 |
+
### How was the data acquired?
|
| 73 |
+
|
| 74 |
+
Raw elevation tiles are downloaded from the public JAXA ALOS AW3D30 archive (5°×5° packaging) and extracted into 1°×1° sub-tiles at native 30 m/pixel resolution. A global calibration pass computes elevation min/max across the local tile cache. For each requested `(resolution, sample_idx, split)` triple, a deterministic `blake2b` seed drives tile selection, crop placement, start/goal placement, obstacle synthesis, and cost-weight draw. Reference paths are solved with the Numba-JIT grid-backend A* under each configured cost model (see `src/passage/pathfinding_utils.py`).
|
| 75 |
+
|
| 76 |
+
### What mechanisms or procedures were used to collect the data?
|
| 77 |
+
|
| 78 |
+
Code-driven pipeline end-to-end (see `Makefile` and `config/config.yaml`). No crowdsourcing, no human annotators, no subject interaction.
|
| 79 |
+
|
| 80 |
+
### Was any preprocessing, cleaning, or labeling done?
|
| 81 |
+
|
| 82 |
+
- Elevation normalised against globally calibrated min/max.
|
| 83 |
+
- Markers placed subject to obstacle-exclusion and minimum separation.
|
| 84 |
+
- Obstacle masks synthesised from log-uniform super-ellipse parameters, rejected if coverage exceeds 30% after up to 50 placement attempts.
|
| 85 |
+
- Paths solved with exact A* under the configured cost model and the 8-connected grid (step lengths 30 m and 30√2 m).
|
| 86 |
+
|
| 87 |
+
### Was the "raw" data saved in addition to the preprocessed data?
|
| 88 |
+
|
| 89 |
+
Yes — the upstream AW3D30 archive and the calibrated tile cache are persisted locally under `/data/PASSAGE/download/` and `/data/PASSAGE/calibrate/` respectively. Only the processed export (Parquet shards) is distributed.
|
| 90 |
+
|
| 91 |
+
### Is the software available for the preprocessing?
|
| 92 |
+
|
| 93 |
+
Yes — the full generator is open-source in this repository (`src/passage/`), with CI coverage and an end-to-end rebuild via `make rebuild`.
|
| 94 |
+
|
| 95 |
+
## Uses
|
| 96 |
+
|
| 97 |
+
### Has the dataset been used for any tasks already?
|
| 98 |
+
|
| 99 |
+
Yes — PASSAGE is the primary benchmark for the downstream `passage-vision` workspace, which reports dense-field segmentation and cost-to-go regression baselines at the 256×256 operating point, plus a 64→4096 resolution-frontier study.
|
| 100 |
+
|
| 101 |
+
### What (other) tasks could the dataset be used for?
|
| 102 |
+
|
| 103 |
+
- Benchmarking classical path-planning algorithms (Dijkstra, Theta*, D\*, JPS) on real terrain.
|
| 104 |
+
- Training and evaluating graph-neural planners and RL planners in bridge comparisons.
|
| 105 |
+
- Studying multi-resolution scaling, geographic distribution shift, and cost-function transfer in dense prediction.
|
| 106 |
+
- Reproducible cost-model design studies with physically interpretable terms.
|
| 107 |
+
|
| 108 |
+
### Is there anything about the composition of the dataset or the way it was collected that might impact future uses?
|
| 109 |
+
|
| 110 |
+
- Samples are grid-based; they do not support full 3D motion planning or dynamic environments.
|
| 111 |
+
- Obstacles are synthetic. Conclusions about real-world obstacle distributions cannot be drawn directly.
|
| 112 |
+
- Geographic coverage is bounded by AW3D30 availability.
|
| 113 |
+
|
| 114 |
+
### Are there tasks for which the dataset should not be used?
|
| 115 |
+
|
| 116 |
+
- **Operational airborne flight planning or search-and-rescue dispatch**: PASSAGE is an advisory research benchmark. It does not by itself validate safety-critical deployment and does not substitute for EASA/FAA certification processes.
|
| 117 |
+
- **Conclusions about weather, airspace, vegetation, urban structures, or regulations**: out of scope.
|
| 118 |
+
- **Safety-of-life decisions**: predicted paths are not safety-of-life outputs without an in-the-loop deterministic verifier and fallback solver.
|
| 119 |
+
|
| 120 |
+
## Distribution
|
| 121 |
+
|
| 122 |
+
### Will the dataset be distributed to third parties?
|
| 123 |
+
|
| 124 |
+
Yes — the dataset is distributed via Hugging Face (`https://huggingface.co/datasets/thalesgroup/passage`). This mirror is configured for anonymous NeurIPS 2026 review.
|
| 125 |
+
|
| 126 |
+
### How will it be distributed?
|
| 127 |
+
|
| 128 |
+
Parquet shards, zstandard-compressed, one file per resolution × split. Accompanied by:
|
| 129 |
+
|
| 130 |
+
- `croissant.json` (MLCommons 1.1 + RAI 1.0).
|
| 131 |
+
- `outputs/export/manifest.sha256` checksum manifest.
|
| 132 |
+
- README on Hugging Face mirroring the GitHub README.
|
| 133 |
+
- `CITATION.cff`, `CHANGELOG.md`, `LICENSE`, this Datasheet.
|
| 134 |
+
|
| 135 |
+
### When will it be distributed?
|
| 136 |
+
|
| 137 |
+
Version 0.1.0 is released with the NeurIPS 2026 submission (May 2026). Future versions follow semantic versioning in `CHANGELOG.md`.
|
| 138 |
+
|
| 139 |
+
### Will the dataset be distributed under a license? Will it have an associated DOI?
|
| 140 |
+
|
| 141 |
+
- Code: MIT (see `LICENSE`).
|
| 142 |
+
- Dataset: distributed under `DATASET_LICENSE.md`, which documents the inherited JAXA ALOS AW3D30 obligations for the derived artifacts.
|
| 143 |
+
- A Zenodo DOI is planned for the v1.0 release (camera-ready gate) and will be recorded in `CITATION.cff`.
|
| 144 |
+
|
| 145 |
+
### Have any third parties imposed IP-based or other restrictions?
|
| 146 |
+
|
| 147 |
+
JAXA ALOS AW3D30 usage terms are inherited by the derived elevation channel. Users of PASSAGE must comply with the upstream JAXA terms, including attribution.
|
| 148 |
+
|
| 149 |
+
### Do any export controls or other regulatory restrictions apply?
|
| 150 |
+
|
| 151 |
+
No export controls apply; AW3D30 is a public global elevation product.
|
| 152 |
+
|
| 153 |
+
## Maintenance
|
| 154 |
+
|
| 155 |
+
### Who is supporting / hosting / maintaining the dataset?
|
| 156 |
+
|
| 157 |
+
Anonymous submission mirror maintained for peer review. Contact details are withheld until de-anonymisation.
|
| 158 |
+
|
| 159 |
+
### How can the owner be contacted?
|
| 160 |
+
|
| 161 |
+
Contact details are intentionally withheld in the anonymous submission mirror.
|
| 162 |
+
|
| 163 |
+
### Is there an erratum?
|
| 164 |
+
|
| 165 |
+
Errata will be tracked in `CHANGELOG.md`. Breaking schema changes bump the minor or major version and invalidate prior manifest checksums.
|
| 166 |
+
|
| 167 |
+
### Will the dataset be updated?
|
| 168 |
+
|
| 169 |
+
Yes. Updates are published via Hugging Face with a corresponding semantic-version tag in this repository and an entry in `CHANGELOG.md`.
|
| 170 |
+
|
| 171 |
+
### If the dataset relates to people: are there applicable limits on the retention of the data associated with the instances?
|
| 172 |
+
|
| 173 |
+
Not applicable — no human subjects.
|
| 174 |
+
|
| 175 |
+
### Will older versions of the dataset continue to be supported/hosted/maintained?
|
| 176 |
+
|
| 177 |
+
Prior releases remain accessible via their Hugging Face dataset-repo commit SHA and the git tag on GitHub. Deprecations are announced in `CHANGELOG.md`. The deprecation policy: one-minor-version notice, with `rai:dataReleaseMaintenancePlan` documenting active supported versions.
|
| 178 |
+
|
| 179 |
+
### If others want to extend / augment / build on / contribute to the dataset, is there a mechanism for them to do so?
|
| 180 |
+
|
| 181 |
+
Yes — pull requests are welcomed (see `CONTRIBUTING.md` and `CODE_OF_CONDUCT.md`). Contributions that change data semantics require a Croissant update and a Datasheet-section review.
|
| 182 |
+
|
| 183 |
+
---
|
| 184 |
+
|
| 185 |
+
## Lifecycle Statement (NeurIPS 2026 E&D track requirement)
|
| 186 |
+
|
| 187 |
+
- **Status**: active.
|
| 188 |
+
- **Versioning**: semantic; authoritative source is `CITATION.cff` `version` and `croissant.json` `version`.
|
| 189 |
+
- **Maintenance owner**: anonymous submission mirror maintainers; de-anonymised ownership is restored at camera-ready.
|
| 190 |
+
- **Deprecation policy**: prior minor version remains supported for at least one subsequent minor release; deprecations announced in `CHANGELOG.md` and the Hugging Face dataset README.
|
| 191 |
+
- **Security contact**: see `SECURITY.md`.
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 THALES
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
assets/banner.png
ADDED
|
Git LFS Details
|
assets/download.png
ADDED
|
Git LFS Details
|
assets/hold_out_mask.png
ADDED
|
Git LFS Details
|
assets/sample.png
ADDED
|
Git LFS Details
|
calibration/calibrate.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
calibration/max_elevation_map.png
ADDED
|
Git LFS Details
|
calibration/ptp_elevation_map.png
ADDED
|
Git LFS Details
|
croissant.json
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"@context": {
|
| 3 |
+
"@language": "en",
|
| 4 |
+
"@vocab": "https://schema.org/",
|
| 5 |
+
"cr": "http://mlcommons.org/croissant/",
|
| 6 |
+
"dct": "http://purl.org/dc/terms/",
|
| 7 |
+
"extract": "cr:extract",
|
| 8 |
+
"field": "cr:field",
|
| 9 |
+
"fileObject": "cr:FileObject",
|
| 10 |
+
"fileSet": "cr:FileSet",
|
| 11 |
+
"includes": "cr:includes",
|
| 12 |
+
"rai": "http://mlcommons.org/croissant/RAI/",
|
| 13 |
+
"recordSet": "cr:recordSet",
|
| 14 |
+
"sc": "https://schema.org/",
|
| 15 |
+
"source": "cr:source"
|
| 16 |
+
},
|
| 17 |
+
"@id": "https://huggingface.co/datasets/thalesgroup/passage",
|
| 18 |
+
"@type": "sc:Dataset",
|
| 19 |
+
"name": "PASSAGE",
|
| 20 |
+
"description": "PASSAGE is a multi-resolution terrain-routing benchmark generated from JAXA ALOS AW3D30 elevation data. The default benchmark exports 14,130 samples across 64x64 to 4096x4096 resolutions, with deterministic split assignment and deterministic per-sample seeding for tile selection, crop placement, marker placement, and obstacle synthesis.",
|
| 21 |
+
"url": "https://huggingface.co/datasets/thalesgroup/passage",
|
| 22 |
+
"version": "0.1.0",
|
| 23 |
+
"license": "https://huggingface.co/datasets/thalesgroup/passage/blob/main/DATASET_LICENSE.md",
|
| 24 |
+
"keywords": [
|
| 25 |
+
"pathfinding",
|
| 26 |
+
"terrain routing",
|
| 27 |
+
"digital elevation model",
|
| 28 |
+
"benchmark",
|
| 29 |
+
"remote sensing"
|
| 30 |
+
],
|
| 31 |
+
"datePublished": "2026-03-30",
|
| 32 |
+
"creator": [
|
| 33 |
+
{
|
| 34 |
+
"@type": "sc:Person",
|
| 35 |
+
"name": "Anonymous Authors"
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"dct:conformsTo": [
|
| 39 |
+
{
|
| 40 |
+
"@id": "http://mlcommons.org/croissant/1.1"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"@id": "http://mlcommons.org/croissant/RAI/1.0"
|
| 44 |
+
}
|
| 45 |
+
],
|
| 46 |
+
"distribution": [
|
| 47 |
+
{
|
| 48 |
+
"@id": "hf-passage-tree",
|
| 49 |
+
"@type": "cr:FileObject",
|
| 50 |
+
"name": "Hugging Face PASSAGE dataset repository tree",
|
| 51 |
+
"contentUrl": "https://huggingface.co/datasets/thalesgroup/passage/tree/main"
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"@id": "passage-full-parquet",
|
| 55 |
+
"@type": "cr:FileSet",
|
| 56 |
+
"name": "PASSAGE full parquet shards",
|
| 57 |
+
"description": "All full PASSAGE parquet configs from 64x64 through 4096x4096.",
|
| 58 |
+
"containedIn": {
|
| 59 |
+
"@id": "hf-passage-tree"
|
| 60 |
+
},
|
| 61 |
+
"encodingFormat": "application/x-parquet",
|
| 62 |
+
"includes": [
|
| 63 |
+
"64x64/**/*.parquet",
|
| 64 |
+
"128x128/**/*.parquet",
|
| 65 |
+
"256x256/**/*.parquet",
|
| 66 |
+
"512x512/**/*.parquet",
|
| 67 |
+
"1024x1024/**/*.parquet",
|
| 68 |
+
"2048x2048/**/*.parquet",
|
| 69 |
+
"4096x4096/**/*.parquet"
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"@id": "passage-sample-parquet",
|
| 74 |
+
"@type": "cr:FileSet",
|
| 75 |
+
"name": "PASSAGE sample parquet shards",
|
| 76 |
+
"description": "Sample PASSAGE parquet configs with per-solver preview images.",
|
| 77 |
+
"containedIn": {
|
| 78 |
+
"@id": "hf-passage-tree"
|
| 79 |
+
},
|
| 80 |
+
"encodingFormat": "application/x-parquet",
|
| 81 |
+
"includes": [
|
| 82 |
+
"64x64_samples/**/*.parquet",
|
| 83 |
+
"128x128_samples/**/*.parquet",
|
| 84 |
+
"256x256_samples/**/*.parquet",
|
| 85 |
+
"512x512_samples/**/*.parquet",
|
| 86 |
+
"1024x1024_samples/**/*.parquet",
|
| 87 |
+
"2048x2048_samples/**/*.parquet",
|
| 88 |
+
"4096x4096_samples/**/*.parquet"
|
| 89 |
+
]
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"recordSet": [
|
| 93 |
+
{
|
| 94 |
+
"@id": "passage-full-records",
|
| 95 |
+
"@type": "cr:RecordSet",
|
| 96 |
+
"name": "PASSAGE full parquet records",
|
| 97 |
+
"description": "Rows from the non-sample PASSAGE parquet exports.",
|
| 98 |
+
"containedIn": {
|
| 99 |
+
"@id": "passage-full-parquet"
|
| 100 |
+
},
|
| 101 |
+
"field": [
|
| 102 |
+
{
|
| 103 |
+
"@id": "passage-full/id",
|
| 104 |
+
"@type": "cr:Field",
|
| 105 |
+
"name": "id",
|
| 106 |
+
"description": "Zero-padded sample identifier.",
|
| 107 |
+
"source": {
|
| 108 |
+
"fileSet": {
|
| 109 |
+
"@id": "passage-full-parquet"
|
| 110 |
+
},
|
| 111 |
+
"extract": {
|
| 112 |
+
"column": "id"
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"@id": "passage-full/tensor",
|
| 118 |
+
"@type": "cr:Field",
|
| 119 |
+
"name": "tensor",
|
| 120 |
+
"description": "Compressed binary tensor storing normalized elevation, markers, and obstacles.",
|
| 121 |
+
"source": {
|
| 122 |
+
"fileSet": {
|
| 123 |
+
"@id": "passage-full-parquet"
|
| 124 |
+
},
|
| 125 |
+
"extract": {
|
| 126 |
+
"column": "tensor"
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"@id": "passage-full/path-astar-elevation-free",
|
| 132 |
+
"@type": "cr:Field",
|
| 133 |
+
"name": "path_astar_elevation_free",
|
| 134 |
+
"description": "Pixel path for the free-terrain astar_elevation annotation.",
|
| 135 |
+
"source": {
|
| 136 |
+
"fileSet": {
|
| 137 |
+
"@id": "passage-full-parquet"
|
| 138 |
+
},
|
| 139 |
+
"extract": {
|
| 140 |
+
"column": "path_astar_elevation_free"
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"@id": "passage-full/path-astar-elevation-obstacles",
|
| 146 |
+
"@type": "cr:Field",
|
| 147 |
+
"name": "path_astar_elevation_obstacles",
|
| 148 |
+
"description": "Pixel path for the obstacle-aware astar_elevation annotation.",
|
| 149 |
+
"source": {
|
| 150 |
+
"fileSet": {
|
| 151 |
+
"@id": "passage-full-parquet"
|
| 152 |
+
},
|
| 153 |
+
"extract": {
|
| 154 |
+
"column": "path_astar_elevation_obstacles"
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
},
|
| 158 |
+
{
|
| 159 |
+
"@id": "passage-full/path-astar-energy-free",
|
| 160 |
+
"@type": "cr:Field",
|
| 161 |
+
"name": "path_astar_energy_free",
|
| 162 |
+
"description": "Pixel path for the free-terrain astar_energy annotation.",
|
| 163 |
+
"source": {
|
| 164 |
+
"fileSet": {
|
| 165 |
+
"@id": "passage-full-parquet"
|
| 166 |
+
},
|
| 167 |
+
"extract": {
|
| 168 |
+
"column": "path_astar_energy_free"
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"@id": "passage-full/path-astar-energy-obstacles",
|
| 174 |
+
"@type": "cr:Field",
|
| 175 |
+
"name": "path_astar_energy_obstacles",
|
| 176 |
+
"description": "Pixel path for the obstacle-aware astar_energy annotation.",
|
| 177 |
+
"source": {
|
| 178 |
+
"fileSet": {
|
| 179 |
+
"@id": "passage-full-parquet"
|
| 180 |
+
},
|
| 181 |
+
"extract": {
|
| 182 |
+
"column": "path_astar_energy_obstacles"
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
},
|
| 186 |
+
{
|
| 187 |
+
"@id": "passage-full/path-astar-slope-free",
|
| 188 |
+
"@type": "cr:Field",
|
| 189 |
+
"name": "path_astar_slope_free",
|
| 190 |
+
"description": "Pixel path for the free-terrain astar_slope annotation.",
|
| 191 |
+
"source": {
|
| 192 |
+
"fileSet": {
|
| 193 |
+
"@id": "passage-full-parquet"
|
| 194 |
+
},
|
| 195 |
+
"extract": {
|
| 196 |
+
"column": "path_astar_slope_free"
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
"@id": "passage-full/path-astar-slope-obstacles",
|
| 202 |
+
"@type": "cr:Field",
|
| 203 |
+
"name": "path_astar_slope_obstacles",
|
| 204 |
+
"description": "Pixel path for the obstacle-aware astar_slope annotation.",
|
| 205 |
+
"source": {
|
| 206 |
+
"fileSet": {
|
| 207 |
+
"@id": "passage-full-parquet"
|
| 208 |
+
},
|
| 209 |
+
"extract": {
|
| 210 |
+
"column": "path_astar_slope_obstacles"
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"@id": "passage-full/metadata",
|
| 216 |
+
"@type": "cr:Field",
|
| 217 |
+
"name": "metadata",
|
| 218 |
+
"description": "Structured sample metadata including split, resolution, crop geometry, solver settings, timing, and deterministic provenance.",
|
| 219 |
+
"source": {
|
| 220 |
+
"fileSet": {
|
| 221 |
+
"@id": "passage-full-parquet"
|
| 222 |
+
},
|
| 223 |
+
"extract": {
|
| 224 |
+
"column": "metadata"
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
]
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
"@id": "passage-sample-records",
|
| 232 |
+
"@type": "cr:RecordSet",
|
| 233 |
+
"name": "PASSAGE sample parquet records",
|
| 234 |
+
"description": "Rows from the PASSAGE sample parquet exports with preview images.",
|
| 235 |
+
"containedIn": {
|
| 236 |
+
"@id": "passage-sample-parquet"
|
| 237 |
+
},
|
| 238 |
+
"field": [
|
| 239 |
+
{
|
| 240 |
+
"@id": "passage-sample/id",
|
| 241 |
+
"@type": "cr:Field",
|
| 242 |
+
"name": "id",
|
| 243 |
+
"description": "Zero-padded sample identifier.",
|
| 244 |
+
"source": {
|
| 245 |
+
"fileSet": {
|
| 246 |
+
"@id": "passage-sample-parquet"
|
| 247 |
+
},
|
| 248 |
+
"extract": {
|
| 249 |
+
"column": "id"
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"@id": "passage-sample/image-astar-elevation",
|
| 255 |
+
"@type": "cr:Field",
|
| 256 |
+
"name": "image_astar_elevation",
|
| 257 |
+
"description": "Preview image rendered for the astar_elevation solver.",
|
| 258 |
+
"source": {
|
| 259 |
+
"fileSet": {
|
| 260 |
+
"@id": "passage-sample-parquet"
|
| 261 |
+
},
|
| 262 |
+
"extract": {
|
| 263 |
+
"column": "image_astar_elevation"
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
},
|
| 267 |
+
{
|
| 268 |
+
"@id": "passage-sample/image-astar-energy",
|
| 269 |
+
"@type": "cr:Field",
|
| 270 |
+
"name": "image_astar_energy",
|
| 271 |
+
"description": "Preview image rendered for the astar_energy solver.",
|
| 272 |
+
"source": {
|
| 273 |
+
"fileSet": {
|
| 274 |
+
"@id": "passage-sample-parquet"
|
| 275 |
+
},
|
| 276 |
+
"extract": {
|
| 277 |
+
"column": "image_astar_energy"
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
},
|
| 281 |
+
{
|
| 282 |
+
"@id": "passage-sample/image-astar-slope",
|
| 283 |
+
"@type": "cr:Field",
|
| 284 |
+
"name": "image_astar_slope",
|
| 285 |
+
"description": "Preview image rendered for the astar_slope solver.",
|
| 286 |
+
"source": {
|
| 287 |
+
"fileSet": {
|
| 288 |
+
"@id": "passage-sample-parquet"
|
| 289 |
+
},
|
| 290 |
+
"extract": {
|
| 291 |
+
"column": "image_astar_slope"
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"@id": "passage-sample/tensor",
|
| 297 |
+
"@type": "cr:Field",
|
| 298 |
+
"name": "tensor",
|
| 299 |
+
"description": "Compressed binary tensor storing normalized elevation, markers, and obstacles.",
|
| 300 |
+
"source": {
|
| 301 |
+
"fileSet": {
|
| 302 |
+
"@id": "passage-sample-parquet"
|
| 303 |
+
},
|
| 304 |
+
"extract": {
|
| 305 |
+
"column": "tensor"
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"@id": "passage-sample/path-astar-elevation-free",
|
| 311 |
+
"@type": "cr:Field",
|
| 312 |
+
"name": "path_astar_elevation_free",
|
| 313 |
+
"description": "Pixel path for the free-terrain astar_elevation annotation.",
|
| 314 |
+
"source": {
|
| 315 |
+
"fileSet": {
|
| 316 |
+
"@id": "passage-sample-parquet"
|
| 317 |
+
},
|
| 318 |
+
"extract": {
|
| 319 |
+
"column": "path_astar_elevation_free"
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
},
|
| 323 |
+
{
|
| 324 |
+
"@id": "passage-sample/path-astar-elevation-obstacles",
|
| 325 |
+
"@type": "cr:Field",
|
| 326 |
+
"name": "path_astar_elevation_obstacles",
|
| 327 |
+
"description": "Pixel path for the obstacle-aware astar_elevation annotation.",
|
| 328 |
+
"source": {
|
| 329 |
+
"fileSet": {
|
| 330 |
+
"@id": "passage-sample-parquet"
|
| 331 |
+
},
|
| 332 |
+
"extract": {
|
| 333 |
+
"column": "path_astar_elevation_obstacles"
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
},
|
| 337 |
+
{
|
| 338 |
+
"@id": "passage-sample/path-astar-energy-free",
|
| 339 |
+
"@type": "cr:Field",
|
| 340 |
+
"name": "path_astar_energy_free",
|
| 341 |
+
"description": "Pixel path for the free-terrain astar_energy annotation.",
|
| 342 |
+
"source": {
|
| 343 |
+
"fileSet": {
|
| 344 |
+
"@id": "passage-sample-parquet"
|
| 345 |
+
},
|
| 346 |
+
"extract": {
|
| 347 |
+
"column": "path_astar_energy_free"
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
},
|
| 351 |
+
{
|
| 352 |
+
"@id": "passage-sample/path-astar-energy-obstacles",
|
| 353 |
+
"@type": "cr:Field",
|
| 354 |
+
"name": "path_astar_energy_obstacles",
|
| 355 |
+
"description": "Pixel path for the obstacle-aware astar_energy annotation.",
|
| 356 |
+
"source": {
|
| 357 |
+
"fileSet": {
|
| 358 |
+
"@id": "passage-sample-parquet"
|
| 359 |
+
},
|
| 360 |
+
"extract": {
|
| 361 |
+
"column": "path_astar_energy_obstacles"
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
},
|
| 365 |
+
{
|
| 366 |
+
"@id": "passage-sample/path-astar-slope-free",
|
| 367 |
+
"@type": "cr:Field",
|
| 368 |
+
"name": "path_astar_slope_free",
|
| 369 |
+
"description": "Pixel path for the free-terrain astar_slope annotation.",
|
| 370 |
+
"source": {
|
| 371 |
+
"fileSet": {
|
| 372 |
+
"@id": "passage-sample-parquet"
|
| 373 |
+
},
|
| 374 |
+
"extract": {
|
| 375 |
+
"column": "path_astar_slope_free"
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"@id": "passage-sample/path-astar-slope-obstacles",
|
| 381 |
+
"@type": "cr:Field",
|
| 382 |
+
"name": "path_astar_slope_obstacles",
|
| 383 |
+
"description": "Pixel path for the obstacle-aware astar_slope annotation.",
|
| 384 |
+
"source": {
|
| 385 |
+
"fileSet": {
|
| 386 |
+
"@id": "passage-sample-parquet"
|
| 387 |
+
},
|
| 388 |
+
"extract": {
|
| 389 |
+
"column": "path_astar_slope_obstacles"
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
},
|
| 393 |
+
{
|
| 394 |
+
"@id": "passage-sample/metadata",
|
| 395 |
+
"@type": "cr:Field",
|
| 396 |
+
"name": "metadata",
|
| 397 |
+
"description": "Structured sample metadata including split, resolution, crop geometry, solver settings, timing, and deterministic provenance.",
|
| 398 |
+
"source": {
|
| 399 |
+
"fileSet": {
|
| 400 |
+
"@id": "passage-sample-parquet"
|
| 401 |
+
},
|
| 402 |
+
"extract": {
|
| 403 |
+
"column": "metadata"
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
]
|
| 408 |
+
}
|
| 409 |
+
],
|
| 410 |
+
"rai:dataCollection": "Observational JAXA ALOS AW3D30 digital surface model tiles combined with deterministic procedural obstacle synthesis and solver-generated path annotations.",
|
| 411 |
+
"rai:dataCollectionType": [
|
| 412 |
+
"observational",
|
| 413 |
+
"synthetic",
|
| 414 |
+
"computational annotation"
|
| 415 |
+
],
|
| 416 |
+
"rai:dataCollectionRawData": "Raw source tiles are downloaded from JAXA ALOS AW3D30 5x5 degree archives; PASSAGE generation operates on 1x1 degree 3600x3600 sub-tiles at approximately 30 meters per pixel.",
|
| 417 |
+
"rai:dataPreprocessingProtocol": [
|
| 418 |
+
"Calibrate global elevation minima and maxima over the local DSM cache.",
|
| 419 |
+
"Use deterministic per-sample seeding to choose a target elevation, tile, crop, and markers.",
|
| 420 |
+
"Optionally synthesize superellipse obstacles under the configured coverage and size limits.",
|
| 421 |
+
"Solve reference paths with the configured astar_elevation, astar_energy, and astar_slope solvers, with and without obstacles.",
|
| 422 |
+
"Export tensors, metadata, CSV paths, preview images, notebooks, and parquet shards."
|
| 423 |
+
],
|
| 424 |
+
"rai:dataAnnotationProtocol": "Reference paths are computational annotations produced by the configured pathfinding solvers over the generated terrain crops and obstacle masks.",
|
| 425 |
+
"rai:dataReleaseMaintenancePlan": "Releases are versioned in CHANGELOG.md, regenerated through the repository Makefile, and verified with outputs/export/manifest.sha256.",
|
| 426 |
+
"rai:personalSensitiveInformation": "none",
|
| 427 |
+
"rai:dataBiases": [
|
| 428 |
+
"Coverage and elevation fidelity are limited by the underlying AW3D30 product and the chosen download footprint.",
|
| 429 |
+
"Terrain-only routing omits weather, airspace, vegetation, built structures, and operational constraints."
|
| 430 |
+
],
|
| 431 |
+
"rai:dataLimitations": [
|
| 432 |
+
"Procedural obstacle masks are abstractions rather than measured hazards.",
|
| 433 |
+
"Deterministic generation covers sample content; runtime timestamps remain informational metadata."
|
| 434 |
+
],
|
| 435 |
+
"rai:dataUseCases": [
|
| 436 |
+
"Benchmark terrain-aware path planners.",
|
| 437 |
+
"Train and evaluate learned routing surrogates in vision, graph, and reinforcement-learning settings.",
|
| 438 |
+
"Study reproducibility and geographic hold-out generalization across resolutions."
|
| 439 |
+
],
|
| 440 |
+
"rai:dataSocialImpact": "PASSAGE is intended for research and evaluation of routing methods in safety-relevant terrain settings. It is not a certified operational navigation product.",
|
| 441 |
+
"rai:annotationsPerItem": "Every sample carries exactly one ordered path annotation per configured cost model (default: astar_elevation, astar_energy, astar_slope) and, where applicable, per obstacle variant (free-terrain and obstacle-aware). No multi-annotator redundancy.",
|
| 442 |
+
"rai:annotatorDemographics": "Not applicable: annotations are produced exclusively by the Numba-JIT A* grid solver documented in src/passage/pathfinding_utils.py. No human annotators were involved.",
|
| 443 |
+
"rai:dataAnnotationAnalysis": "Annotations are exact under the documented cost model and are validated by construction (same solver, same heuristic, same connectivity). Consistency is enforced by deterministic seeding and by the outputs/export/manifest.sha256 checksum file bundled with each release.",
|
| 444 |
+
"rai:dataAnnotationPlatform": "None: annotations are computational. Generation is driven by the Makefile targets in this repository, executed on CPU with optional GPU used only by downstream baselines, not by dataset generation.",
|
| 445 |
+
"rai:machineAnnotationTools": [
|
| 446 |
+
"Numba-JIT grid-backend A* implemented in src/passage/pathfinding_utils.py",
|
| 447 |
+
"Deterministic blake2b per-sample seed derivation documented in src/passage/seeds.py"
|
| 448 |
+
],
|
| 449 |
+
"rai:dataImpactAssessment": "The dataset is an elevation-derived research benchmark with no personal or biometric content; residual risk is limited to misuse of reference paths as safety-critical navigation outputs outside an in-the-loop deterministic verifier. This risk is mitigated by the scope statement in the Datasheet and by the SECURITY.md misuse disclosure.",
|
| 450 |
+
"rai:safetyOfLifeStatement": "PASSAGE is an advisory research benchmark. Predicted paths are not safety-of-life outputs without an in-the-loop deterministic verifier and fallback solver, and the dataset does not substitute for system-level verification or EASA/FAA-style certification evidence.",
|
| 451 |
+
"rai:citation": "Delhomme, G., Trap, F., Kaakai, F. PASSAGE: A Real-Terrain Multi-Resolution Benchmark for Constrained Path Planning. NeurIPS 2026 Evaluations & Datasets Track (submission)."
|
| 452 |
+
}
|
notebooks/astar_inference_timing.ipynb
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# A* Solver Inference Timing Benchmark\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"Systematic measurement of A* solver inference time across resolutions.\n",
|
| 10 |
+
"These timings serve as the **exact solver reference** for comparing neural surrogate speedup ratios\n",
|
| 11 |
+
"in the PASSAGE NeurIPS paper.\n",
|
| 12 |
+
"\n",
|
| 13 |
+
"**Resolutions:** 64x64, 256x256\n",
|
| 14 |
+
"<!-- TODO:RESOLUTION_UPDATE: add 128x128, 512x512, 1024x1024, 2048x2048, 4096x4096 -->\n",
|
| 15 |
+
"\n",
|
| 16 |
+
"**Solver backends:**\n",
|
| 17 |
+
"- `grid:astar` (Numba JIT, our fastest solver — the one used for ground truth generation)\n",
|
| 18 |
+
"- `grid:dijkstra` (Numba JIT, for comparison)\n",
|
| 19 |
+
"- `networkx:astar` (pure Python, for baseline comparison)\n",
|
| 20 |
+
"\n",
|
| 21 |
+
"**Metrics:**\n",
|
| 22 |
+
"- Mean solve time (ms)\n",
|
| 23 |
+
"- Std deviation\n",
|
| 24 |
+
"- Median\n",
|
| 25 |
+
"- P95 and P99 latencies\n",
|
| 26 |
+
"- Peak memory"
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"cell_type": "code",
|
| 31 |
+
"execution_count": null,
|
| 32 |
+
"metadata": {},
|
| 33 |
+
"outputs": [],
|
| 34 |
+
"source": [
|
| 35 |
+
"import json\n",
|
| 36 |
+
"import logging\n",
|
| 37 |
+
"import sys\n",
|
| 38 |
+
"import time\n",
|
| 39 |
+
"from pathlib import Path\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"import matplotlib.pyplot as plt\n",
|
| 42 |
+
"import numpy as np\n",
|
| 43 |
+
"import pandas as pd\n",
|
| 44 |
+
"import yaml\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"# Suppress verbose logging\n",
|
| 47 |
+
"logging.basicConfig(level=logging.WARNING)\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"ROOT = Path(\".\").resolve().parent\n",
|
| 50 |
+
"sys.path.insert(0, str(ROOT / \"src\"))\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"from passage.generate import find_path # noqa: E402\n",
|
| 53 |
+
"from passage.pathfinding_utils import NUMBA_AVAILABLE # noqa: E402\n",
|
| 54 |
+
"\n",
|
| 55 |
+
"print(f\"Numba available: {NUMBA_AVAILABLE}\")\n",
|
| 56 |
+
"\n",
|
| 57 |
+
"# Configuration\n",
|
| 58 |
+
"TILES_DIR = ROOT / \"outputs\" / \"download\" / \"tiles\"\n",
|
| 59 |
+
"CALIBRATE_PATH = ROOT / \"outputs\" / \"calibrate\" / \"calibration.json\"\n",
|
| 60 |
+
"EXPORT_DIR = ROOT / \"outputs\" / \"export\"\n",
|
| 61 |
+
"\n",
|
| 62 |
+
"# Load calibration\n",
|
| 63 |
+
"with open(CALIBRATE_PATH) as f:\n",
|
| 64 |
+
" calibration = json.load(f)\n",
|
| 65 |
+
"GLOBAL_MIN = float(calibration[\"global_min\"])\n",
|
| 66 |
+
"GLOBAL_MAX = float(calibration[\"global_max\"])\n",
|
| 67 |
+
"\n",
|
| 68 |
+
"# Load config for cost model weights\n",
|
| 69 |
+
"with open(ROOT / \"config\" / \"config.yaml\") as f:\n",
|
| 70 |
+
" config = yaml.safe_load(f)"
|
| 71 |
+
]
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"cell_type": "code",
|
| 75 |
+
"execution_count": null,
|
| 76 |
+
"metadata": {},
|
| 77 |
+
"outputs": [],
|
| 78 |
+
"source": [
|
| 79 |
+
"# Benchmark parameters\n",
|
| 80 |
+
"RESOLUTIONS = [64, 256] # TODO:RESOLUTION_UPDATE: add 128, 512, 1024, 2048, 4096\n",
|
| 81 |
+
"N_SAMPLES = 100 # Number of samples per resolution\n",
|
| 82 |
+
"COST_MODEL = \"energy\" # The default cost model used for labels in passage-vision\n",
|
| 83 |
+
"\n",
|
| 84 |
+
"# Solver configurations to benchmark\n",
|
| 85 |
+
"SOLVERS = [\n",
|
| 86 |
+
" {\n",
|
| 87 |
+
" \"name\": \"grid:astar\",\n",
|
| 88 |
+
" \"backend\": \"grid\",\n",
|
| 89 |
+
" \"solver_name\": \"astar\",\n",
|
| 90 |
+
" \"diagonal_movement\": \"always\",\n",
|
| 91 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 92 |
+
" \"cost_model\": COST_MODEL,\n",
|
| 93 |
+
" \"weight\": config.get(\"solve\", {}).get(\"cost_weight\", {}).get(COST_MODEL, 1.0),\n",
|
| 94 |
+
" },\n",
|
| 95 |
+
" {\n",
|
| 96 |
+
" \"name\": \"grid:dijkstra\",\n",
|
| 97 |
+
" \"backend\": \"grid\",\n",
|
| 98 |
+
" \"solver_name\": \"dijkstra\",\n",
|
| 99 |
+
" \"diagonal_movement\": \"always\",\n",
|
| 100 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 101 |
+
" \"cost_model\": COST_MODEL,\n",
|
| 102 |
+
" \"weight\": config.get(\"solve\", {}).get(\"cost_weight\", {}).get(COST_MODEL, 1.0),\n",
|
| 103 |
+
" },\n",
|
| 104 |
+
"]\n",
|
| 105 |
+
"\n",
|
| 106 |
+
"# Only include networkx for small resolutions (too slow for 512+)\n",
|
| 107 |
+
"# for res in RESOLUTIONS:\n",
|
| 108 |
+
"# if res <= 256:\n",
|
| 109 |
+
"# SOLVERS.append({\n",
|
| 110 |
+
"# \"name\": f\"networkx:astar\",\n",
|
| 111 |
+
"# \"backend\": \"networkx\",\n",
|
| 112 |
+
"# ...\n",
|
| 113 |
+
"# })\n",
|
| 114 |
+
"\n",
|
| 115 |
+
"print(f\"Benchmarking {len(SOLVERS)} solvers at resolutions: {RESOLUTIONS}\")\n",
|
| 116 |
+
"print(f\"Samples per resolution: {N_SAMPLES}\")\n",
|
| 117 |
+
"print(f\"Cost model: {COST_MODEL}\")"
|
| 118 |
+
]
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"cell_type": "markdown",
|
| 122 |
+
"metadata": {},
|
| 123 |
+
"source": [
|
| 124 |
+
"## 1. Generate Test Samples\n",
|
| 125 |
+
"\n",
|
| 126 |
+
"We load samples from the exported parquet data to ensure we benchmark on representative terrain."
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"cell_type": "code",
|
| 131 |
+
"execution_count": null,
|
| 132 |
+
"metadata": {},
|
| 133 |
+
"outputs": [],
|
| 134 |
+
"source": [
|
| 135 |
+
"import pyarrow.parquet as pq\n",
|
| 136 |
+
"import glob as globlib\n",
|
| 137 |
+
"import zstandard as zstd\n",
|
| 138 |
+
"import io\n",
|
| 139 |
+
"import torch\n",
|
| 140 |
+
"\n",
|
| 141 |
+
"\n",
|
| 142 |
+
"def decode_tensor_blob(blob: bytes) -> np.ndarray:\n",
|
| 143 |
+
" \"\"\"Decode a zstandard-compressed tensor blob from parquet.\"\"\"\n",
|
| 144 |
+
" dctx = zstd.ZstdDecompressor()\n",
|
| 145 |
+
" decompressed = dctx.decompress(blob)\n",
|
| 146 |
+
" buf = io.BytesIO(decompressed)\n",
|
| 147 |
+
" tensor = torch.load(buf, weights_only=True, map_location=\"cpu\")\n",
|
| 148 |
+
" return tensor.numpy()\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"\n",
|
| 151 |
+
"def load_samples(resolution: int, split: str = \"test\", n: int = 100) -> list[dict]:\n",
|
| 152 |
+
" \"\"\"Load samples from parquet export.\"\"\"\n",
|
| 153 |
+
" res_dir = EXPORT_DIR / f\"{resolution}x{resolution}\"\n",
|
| 154 |
+
" files = sorted(globlib.glob(str(res_dir / split / \"*.parquet\")))\n",
|
| 155 |
+
"\n",
|
| 156 |
+
" if not files:\n",
|
| 157 |
+
" # Fall back to train split\n",
|
| 158 |
+
" files = sorted(globlib.glob(str(res_dir / \"train\" / \"*.parquet\")))\n",
|
| 159 |
+
" print(f\" Warning: no {split} split for {resolution}x{resolution}, using train\")\n",
|
| 160 |
+
"\n",
|
| 161 |
+
" samples = []\n",
|
| 162 |
+
" for f in files:\n",
|
| 163 |
+
" table = pq.read_table(f)\n",
|
| 164 |
+
" for i in range(min(n - len(samples), len(table))):\n",
|
| 165 |
+
" row = table.slice(i, 1).to_pydict()\n",
|
| 166 |
+
" # Decode the tensor\n",
|
| 167 |
+
" tensor_data = decode_tensor_blob(row[\"tensor\"][0])\n",
|
| 168 |
+
" # tensor_data shape: (3, H, W) -> [elevation, markers, obstacles]\n",
|
| 169 |
+
" elevation = tensor_data[0] # raw elevation\n",
|
| 170 |
+
" markers = tensor_data[1]\n",
|
| 171 |
+
" obstacles = tensor_data[2] if tensor_data.shape[0] > 2 else np.zeros_like(elevation)\n",
|
| 172 |
+
"\n",
|
| 173 |
+
" # Extract start/end from markers\n",
|
| 174 |
+
" start_pos = np.argwhere(np.isclose(markers, 0.0))\n",
|
| 175 |
+
" end_pos = np.argwhere(markers > 0.5)\n",
|
| 176 |
+
"\n",
|
| 177 |
+
" if len(start_pos) < 1 or len(end_pos) < 1:\n",
|
| 178 |
+
" continue\n",
|
| 179 |
+
"\n",
|
| 180 |
+
" start = (int(start_pos[0, 0]), int(start_pos[0, 1]))\n",
|
| 181 |
+
" end = (int(end_pos[0, 0]), int(end_pos[0, 1]))\n",
|
| 182 |
+
"\n",
|
| 183 |
+
" samples.append(\n",
|
| 184 |
+
" {\n",
|
| 185 |
+
" \"elevation\": elevation,\n",
|
| 186 |
+
" \"start\": start,\n",
|
| 187 |
+
" \"end\": end,\n",
|
| 188 |
+
" \"obstacles\": obstacles,\n",
|
| 189 |
+
" }\n",
|
| 190 |
+
" )\n",
|
| 191 |
+
"\n",
|
| 192 |
+
" if len(samples) >= n:\n",
|
| 193 |
+
" break\n",
|
| 194 |
+
" if len(samples) >= n:\n",
|
| 195 |
+
" break\n",
|
| 196 |
+
"\n",
|
| 197 |
+
" print(f\" Loaded {len(samples)} samples at {resolution}x{resolution}\")\n",
|
| 198 |
+
" return samples\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"\n",
|
| 201 |
+
"# Load samples for each resolution\n",
|
| 202 |
+
"test_samples = {}\n",
|
| 203 |
+
"for res in RESOLUTIONS:\n",
|
| 204 |
+
" test_samples[res] = load_samples(res, split=\"test\", n=N_SAMPLES)"
|
| 205 |
+
]
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"cell_type": "markdown",
|
| 209 |
+
"metadata": {},
|
| 210 |
+
"source": [
|
| 211 |
+
"## 2. Run Timing Benchmark\n",
|
| 212 |
+
"\n",
|
| 213 |
+
"For each (resolution, solver) pair, measure solve time over all samples."
|
| 214 |
+
]
|
| 215 |
+
},
|
| 216 |
+
{
|
| 217 |
+
"cell_type": "code",
|
| 218 |
+
"execution_count": null,
|
| 219 |
+
"metadata": {},
|
| 220 |
+
"outputs": [],
|
| 221 |
+
"source": [
|
| 222 |
+
"# Numba JIT warmup: run one solve to trigger compilation\n",
|
| 223 |
+
"if NUMBA_AVAILABLE and test_samples:\n",
|
| 224 |
+
" warmup_res = RESOLUTIONS[0]\n",
|
| 225 |
+
" warmup_sample = test_samples[warmup_res][0]\n",
|
| 226 |
+
" print(\"Warming up Numba JIT...\")\n",
|
| 227 |
+
" _ = find_path(\n",
|
| 228 |
+
" crop=warmup_sample[\"elevation\"],\n",
|
| 229 |
+
" start=warmup_sample[\"start\"],\n",
|
| 230 |
+
" end=warmup_sample[\"end\"],\n",
|
| 231 |
+
" solver_config=SOLVERS[0],\n",
|
| 232 |
+
" )\n",
|
| 233 |
+
" print(\"Warmup complete.\")"
|
| 234 |
+
]
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
"cell_type": "code",
|
| 238 |
+
"execution_count": null,
|
| 239 |
+
"metadata": {},
|
| 240 |
+
"outputs": [],
|
| 241 |
+
"source": [
|
| 242 |
+
"# Main benchmark loop\n",
|
| 243 |
+
"all_timings = []\n",
|
| 244 |
+
"\n",
|
| 245 |
+
"for res in RESOLUTIONS:\n",
|
| 246 |
+
" samples = test_samples.get(res, [])\n",
|
| 247 |
+
" if not samples:\n",
|
| 248 |
+
" print(f\"No samples for {res}x{res}, skipping.\")\n",
|
| 249 |
+
" continue\n",
|
| 250 |
+
"\n",
|
| 251 |
+
" print(f\"\\n=== {res}x{res} ({len(samples)} samples) ===\")\n",
|
| 252 |
+
"\n",
|
| 253 |
+
" for solver in SOLVERS:\n",
|
| 254 |
+
" solver_name = solver[\"name\"]\n",
|
| 255 |
+
" times_ms = []\n",
|
| 256 |
+
" successes = 0\n",
|
| 257 |
+
"\n",
|
| 258 |
+
" for i, sample in enumerate(samples):\n",
|
| 259 |
+
" t0 = time.perf_counter()\n",
|
| 260 |
+
" path = find_path(\n",
|
| 261 |
+
" crop=sample[\"elevation\"],\n",
|
| 262 |
+
" start=sample[\"start\"],\n",
|
| 263 |
+
" end=sample[\"end\"],\n",
|
| 264 |
+
" solver_config=solver,\n",
|
| 265 |
+
" )\n",
|
| 266 |
+
" elapsed_ms = (time.perf_counter() - t0) * 1000\n",
|
| 267 |
+
" times_ms.append(elapsed_ms)\n",
|
| 268 |
+
" if len(path) > 0:\n",
|
| 269 |
+
" successes += 1\n",
|
| 270 |
+
"\n",
|
| 271 |
+
" if (i + 1) % 25 == 0:\n",
|
| 272 |
+
" print(f\" {solver_name}: {i + 1}/{len(samples)} done, mean so far = {np.mean(times_ms):.2f} ms\")\n",
|
| 273 |
+
"\n",
|
| 274 |
+
" times_arr = np.array(times_ms)\n",
|
| 275 |
+
" record = {\n",
|
| 276 |
+
" \"resolution\": f\"{res}x{res}\",\n",
|
| 277 |
+
" \"solver\": solver_name,\n",
|
| 278 |
+
" \"n_samples\": len(samples),\n",
|
| 279 |
+
" \"success_rate\": successes / len(samples),\n",
|
| 280 |
+
" \"mean_ms\": np.mean(times_arr),\n",
|
| 281 |
+
" \"std_ms\": np.std(times_arr),\n",
|
| 282 |
+
" \"median_ms\": np.median(times_arr),\n",
|
| 283 |
+
" \"p95_ms\": np.percentile(times_arr, 95),\n",
|
| 284 |
+
" \"p99_ms\": np.percentile(times_arr, 99),\n",
|
| 285 |
+
" \"min_ms\": np.min(times_arr),\n",
|
| 286 |
+
" \"max_ms\": np.max(times_arr),\n",
|
| 287 |
+
" }\n",
|
| 288 |
+
" all_timings.append(record)\n",
|
| 289 |
+
" print(\n",
|
| 290 |
+
" f\" {solver_name}: mean={record['mean_ms']:.2f} ms, \"\n",
|
| 291 |
+
" f\"median={record['median_ms']:.2f} ms, \"\n",
|
| 292 |
+
" f\"p95={record['p95_ms']:.2f} ms, \"\n",
|
| 293 |
+
" f\"success={record['success_rate']:.1%}\"\n",
|
| 294 |
+
" )\n",
|
| 295 |
+
"\n",
|
| 296 |
+
"timings_df = pd.DataFrame(all_timings)\n",
|
| 297 |
+
"print(\"\\n=== Full Results ===\")\n",
|
| 298 |
+
"print(timings_df.to_string(index=False))"
|
| 299 |
+
]
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"cell_type": "markdown",
|
| 303 |
+
"metadata": {},
|
| 304 |
+
"source": [
|
| 305 |
+
"## 3. Visualization"
|
| 306 |
+
]
|
| 307 |
+
},
|
| 308 |
+
{
|
| 309 |
+
"cell_type": "code",
|
| 310 |
+
"execution_count": null,
|
| 311 |
+
"metadata": {},
|
| 312 |
+
"outputs": [],
|
| 313 |
+
"source": [
|
| 314 |
+
"if not timings_df.empty:\n",
|
| 315 |
+
" # Bar chart: mean solve time per solver per resolution\n",
|
| 316 |
+
" fig, axes = plt.subplots(1, len(RESOLUTIONS), figsize=(7 * len(RESOLUTIONS), 5))\n",
|
| 317 |
+
" if len(RESOLUTIONS) == 1:\n",
|
| 318 |
+
" axes = [axes]\n",
|
| 319 |
+
"\n",
|
| 320 |
+
" fig.suptitle(\"A* Solver Inference Time by Resolution\", fontsize=14, fontweight=\"bold\")\n",
|
| 321 |
+
"\n",
|
| 322 |
+
" for ax, res in zip(axes, RESOLUTIONS):\n",
|
| 323 |
+
" res_df = timings_df[timings_df[\"resolution\"] == f\"{res}x{res}\"]\n",
|
| 324 |
+
" if res_df.empty:\n",
|
| 325 |
+
" continue\n",
|
| 326 |
+
" bars = ax.bar(\n",
|
| 327 |
+
" res_df[\"solver\"], res_df[\"mean_ms\"], yerr=res_df[\"std_ms\"], capsize=5, color=\"steelblue\", alpha=0.8\n",
|
| 328 |
+
" )\n",
|
| 329 |
+
" ax.set_ylabel(\"Time (ms)\")\n",
|
| 330 |
+
" ax.set_title(f\"{res}x{res}\")\n",
|
| 331 |
+
" ax.grid(True, alpha=0.3, axis=\"y\")\n",
|
| 332 |
+
"\n",
|
| 333 |
+
" # Add value labels\n",
|
| 334 |
+
" for bar, val in zip(bars, res_df[\"mean_ms\"]):\n",
|
| 335 |
+
" ax.text(\n",
|
| 336 |
+
" bar.get_x() + bar.get_width() / 2, bar.get_height(), f\"{val:.1f}\", ha=\"center\", va=\"bottom\", fontsize=9\n",
|
| 337 |
+
" )\n",
|
| 338 |
+
"\n",
|
| 339 |
+
" plt.tight_layout()\n",
|
| 340 |
+
" plt.savefig(ROOT / \"outputs\" / \"paper\" / \"astar_timing_bars.pdf\", dpi=150, bbox_inches=\"tight\")\n",
|
| 341 |
+
" plt.show()\n",
|
| 342 |
+
"else:\n",
|
| 343 |
+
" print(\"No timing results to plot.\")"
|
| 344 |
+
]
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"cell_type": "code",
|
| 348 |
+
"execution_count": null,
|
| 349 |
+
"metadata": {},
|
| 350 |
+
"outputs": [],
|
| 351 |
+
"source": [
|
| 352 |
+
"if not timings_df.empty:\n",
|
| 353 |
+
" # Resolution scaling plot (log-log)\n",
|
| 354 |
+
" fig, ax = plt.subplots(figsize=(10, 6))\n",
|
| 355 |
+
"\n",
|
| 356 |
+
" for solver_name in timings_df[\"solver\"].unique():\n",
|
| 357 |
+
" solver_df = timings_df[timings_df[\"solver\"] == solver_name].copy()\n",
|
| 358 |
+
" solver_df[\"res_int\"] = solver_df[\"resolution\"].str.split(\"x\").str[0].astype(int)\n",
|
| 359 |
+
" solver_df = solver_df.sort_values(\"res_int\")\n",
|
| 360 |
+
"\n",
|
| 361 |
+
" ax.plot(solver_df[\"res_int\"], solver_df[\"mean_ms\"], \"o-\", label=solver_name, linewidth=2)\n",
|
| 362 |
+
" ax.fill_between(\n",
|
| 363 |
+
" solver_df[\"res_int\"],\n",
|
| 364 |
+
" solver_df[\"mean_ms\"] - solver_df[\"std_ms\"],\n",
|
| 365 |
+
" solver_df[\"mean_ms\"] + solver_df[\"std_ms\"],\n",
|
| 366 |
+
" alpha=0.15,\n",
|
| 367 |
+
" )\n",
|
| 368 |
+
"\n",
|
| 369 |
+
" ax.set_xscale(\"log\", base=2)\n",
|
| 370 |
+
" ax.set_yscale(\"log\")\n",
|
| 371 |
+
" ax.set_xlabel(\"Resolution (pixels per side)\")\n",
|
| 372 |
+
" ax.set_ylabel(\"Solve Time (ms)\")\n",
|
| 373 |
+
" ax.set_title(\"A* Solver Scaling with Resolution\")\n",
|
| 374 |
+
" ax.legend()\n",
|
| 375 |
+
" ax.grid(True, alpha=0.3)\n",
|
| 376 |
+
"\n",
|
| 377 |
+
" # Add reference lines for neural model times (placeholder)\n",
|
| 378 |
+
" # ax.axhline(y=5, color=\"green\", linestyle=\"--\", alpha=0.5, label=\"~Neural model (5ms)\")\n",
|
| 379 |
+
"\n",
|
| 380 |
+
" plt.tight_layout()\n",
|
| 381 |
+
" plt.savefig(ROOT / \"outputs\" / \"paper\" / \"astar_scaling.pdf\", dpi=150, bbox_inches=\"tight\")\n",
|
| 382 |
+
" plt.show()\n",
|
| 383 |
+
"\n",
|
| 384 |
+
" # TODO:RESOLUTION_UPDATE: This plot becomes most compelling with all 7 resolutions"
|
| 385 |
+
]
|
| 386 |
+
},
|
| 387 |
+
{
|
| 388 |
+
"cell_type": "code",
|
| 389 |
+
"execution_count": null,
|
| 390 |
+
"metadata": {},
|
| 391 |
+
"outputs": [],
|
| 392 |
+
"source": [
|
| 393 |
+
"if not timings_df.empty:\n",
|
| 394 |
+
" # Distribution of solve times (histogram)\n",
|
| 395 |
+
" fig, axes = plt.subplots(1, len(RESOLUTIONS), figsize=(7 * len(RESOLUTIONS), 4))\n",
|
| 396 |
+
" if len(RESOLUTIONS) == 1:\n",
|
| 397 |
+
" axes = [axes]\n",
|
| 398 |
+
"\n",
|
| 399 |
+
" fig.suptitle(\"Distribution of A* Solve Times (grid:astar)\", fontsize=14, fontweight=\"bold\")\n",
|
| 400 |
+
"\n",
|
| 401 |
+
" for ax, res in zip(axes, RESOLUTIONS):\n",
|
| 402 |
+
" # Use grid:astar times (the reference solver)\n",
|
| 403 |
+
" res_grid = timings_df[(timings_df[\"resolution\"] == f\"{res}x{res}\") & (timings_df[\"solver\"] == \"grid:astar\")]\n",
|
| 404 |
+
" if res_grid.empty:\n",
|
| 405 |
+
" continue\n",
|
| 406 |
+
"\n",
|
| 407 |
+
" mean_val = res_grid[\"mean_ms\"].values[0]\n",
|
| 408 |
+
" p95_val = res_grid[\"p95_ms\"].values[0]\n",
|
| 409 |
+
"\n",
|
| 410 |
+
" ax.set_title(f\"{res}x{res} (mean={mean_val:.1f}ms, p95={p95_val:.1f}ms)\")\n",
|
| 411 |
+
" ax.set_xlabel(\"Solve Time (ms)\")\n",
|
| 412 |
+
" ax.set_ylabel(\"Count\")\n",
|
| 413 |
+
" ax.axvline(x=mean_val, color=\"red\", linestyle=\"--\", label=f\"Mean: {mean_val:.1f}ms\")\n",
|
| 414 |
+
" ax.axvline(x=p95_val, color=\"orange\", linestyle=\":\", label=f\"P95: {p95_val:.1f}ms\")\n",
|
| 415 |
+
" ax.legend(fontsize=9)\n",
|
| 416 |
+
" ax.grid(True, alpha=0.3)\n",
|
| 417 |
+
"\n",
|
| 418 |
+
" plt.tight_layout()\n",
|
| 419 |
+
" plt.show()"
|
| 420 |
+
]
|
| 421 |
+
},
|
| 422 |
+
{
|
| 423 |
+
"cell_type": "markdown",
|
| 424 |
+
"metadata": {},
|
| 425 |
+
"source": [
|
| 426 |
+
"## 4. Export Results\n",
|
| 427 |
+
"\n",
|
| 428 |
+
"Save timing results for use in the passage-vision experiment notebook."
|
| 429 |
+
]
|
| 430 |
+
},
|
| 431 |
+
{
|
| 432 |
+
"cell_type": "code",
|
| 433 |
+
"execution_count": null,
|
| 434 |
+
"metadata": {},
|
| 435 |
+
"outputs": [],
|
| 436 |
+
"source": [
|
| 437 |
+
"if not timings_df.empty:\n",
|
| 438 |
+
" # Save as CSV\n",
|
| 439 |
+
" output_dir = ROOT / \"outputs\" / \"paper\"\n",
|
| 440 |
+
" output_dir.mkdir(parents=True, exist_ok=True)\n",
|
| 441 |
+
"\n",
|
| 442 |
+
" csv_path = output_dir / \"astar_inference_timing.csv\"\n",
|
| 443 |
+
" timings_df.to_csv(csv_path, index=False)\n",
|
| 444 |
+
" print(f\"Saved timing results to {csv_path}\")\n",
|
| 445 |
+
"\n",
|
| 446 |
+
" # Also save as JSON for easy loading in passage-vision notebook\n",
|
| 447 |
+
" json_path = output_dir / \"astar_inference_timing.json\"\n",
|
| 448 |
+
" timing_dict = {}\n",
|
| 449 |
+
" for _, row in timings_df[timings_df[\"solver\"] == \"grid:astar\"].iterrows():\n",
|
| 450 |
+
" res_int = int(row[\"resolution\"].split(\"x\")[0])\n",
|
| 451 |
+
" timing_dict[res_int] = {\n",
|
| 452 |
+
" \"mean\": round(row[\"mean_ms\"], 2),\n",
|
| 453 |
+
" \"std\": round(row[\"std_ms\"], 2),\n",
|
| 454 |
+
" \"median\": round(row[\"median_ms\"], 2),\n",
|
| 455 |
+
" \"p95\": round(row[\"p95_ms\"], 2),\n",
|
| 456 |
+
" \"p99\": round(row[\"p99_ms\"], 2),\n",
|
| 457 |
+
" \"n_samples\": int(row[\"n_samples\"]),\n",
|
| 458 |
+
" }\n",
|
| 459 |
+
"\n",
|
| 460 |
+
" with open(json_path, \"w\") as f:\n",
|
| 461 |
+
" json.dump(timing_dict, f, indent=2)\n",
|
| 462 |
+
" print(f\"Saved JSON timing for passage-vision: {json_path}\")\n",
|
| 463 |
+
"\n",
|
| 464 |
+
" print(\"\\nTo load in passage-vision notebook:\")\n",
|
| 465 |
+
" print(f' import json; ASTAR_TIMING = json.load(open(\"{json_path}\"))')\n",
|
| 466 |
+
"else:\n",
|
| 467 |
+
" print(\"No results to export. Run the benchmark cells above first.\")"
|
| 468 |
+
]
|
| 469 |
+
},
|
| 470 |
+
{
|
| 471 |
+
"cell_type": "markdown",
|
| 472 |
+
"metadata": {},
|
| 473 |
+
"source": [
|
| 474 |
+
"### Analysis: A* Solver Timing\n",
|
| 475 |
+
"\n",
|
| 476 |
+
"**Expected scaling behavior:**\n",
|
| 477 |
+
"\n",
|
| 478 |
+
"- **64x64:** Grid A* should complete in ~5-20 ms. At this resolution, A* is cheap enough that neural surrogates offer only modest speedup.\n",
|
| 479 |
+
"\n",
|
| 480 |
+
"- **256x256:** Grid A* should take ~50-500 ms depending on terrain complexity and path length. This is the resolution where neural surrogates start to become compelling.\n",
|
| 481 |
+
"\n",
|
| 482 |
+
"- **512x512+:** Grid A* scales roughly as O(N^2 log N). At 1024x1024, expect ~1-10 seconds. At 4096x4096, expect minutes. This is where neural surrogates provide transformative speedup.\n",
|
| 483 |
+
"\n",
|
| 484 |
+
"**Numba JIT impact:** The grid backend with Numba should be 10-100x faster than NetworkX at the same resolution. This is itself a contribution of the paper (Section 5).\n",
|
| 485 |
+
"\n",
|
| 486 |
+
"**Key paper figure:** The scaling plot (log-log: resolution vs time) with grid and networkx curves diverging at higher resolutions. Overlay neural model inference times to show the crossover point.\n",
|
| 487 |
+
"\n",
|
| 488 |
+
"<!-- TODO:RESOLUTION_UPDATE: The full 64->4096 scaling curve is the most impactful figure. -->"
|
| 489 |
+
]
|
| 490 |
+
}
|
| 491 |
+
],
|
| 492 |
+
"metadata": {
|
| 493 |
+
"kernelspec": {
|
| 494 |
+
"display_name": "passage",
|
| 495 |
+
"language": "python",
|
| 496 |
+
"name": "python3"
|
| 497 |
+
},
|
| 498 |
+
"language_info": {
|
| 499 |
+
"name": "python",
|
| 500 |
+
"version": "3.12.0"
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
"nbformat": 4,
|
| 504 |
+
"nbformat_minor": 4
|
| 505 |
+
}
|
notebooks/costmodel.ipynb
ADDED
|
@@ -0,0 +1,1200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "c7488484",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"MIT License\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"Copyright (c) 2026 THALES\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Permission is hereby granted, free of charge, to any person obtaining a copy\n",
|
| 13 |
+
"of this software and associated documentation files (the \"Software\"), to deal\n",
|
| 14 |
+
"in the Software without restriction, including without limitation the rights\n",
|
| 15 |
+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n",
|
| 16 |
+
"copies of the Software, and to permit persons to whom the Software is\n",
|
| 17 |
+
"furnished to do so, subject to the following conditions:\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"The above copyright notice and this permission notice shall be included in all\n",
|
| 20 |
+
"copies or substantial portions of the Software.\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n",
|
| 23 |
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n",
|
| 24 |
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n",
|
| 25 |
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n",
|
| 26 |
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n",
|
| 27 |
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n",
|
| 28 |
+
"SOFTWARE."
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "markdown",
|
| 33 |
+
"id": "dc454ef6",
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"source": [
|
| 36 |
+
"# Cost Model Comparison & Weight Tuning\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"This notebook compares PASSAGE cost models using `grid:astar` and tunes their\n",
|
| 39 |
+
"weight parameter by balancing three objectives:\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"1. **Maximize path diversity** — Hausdorff distance from the flat `distance` baseline\n",
|
| 42 |
+
"2. **Minimize boundary artifacts** — penalize paths that hug image edges (both overall fraction and contiguous runs)\n",
|
| 43 |
+
"3. **Minimize weight at asymptote** — prefer the smallest weight achieving near-peak score\n",
|
| 44 |
+
"\n",
|
| 45 |
+
"**Combined score** per (cost_model, weight):\n",
|
| 46 |
+
"\n",
|
| 47 |
+
"$$\\text{score}(w) = \\hat{H}(w) \\cdot \\bigl(1 - B(w)\\bigr) \\cdot P_{\\text{run}}(w)$$\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"where $\\hat{H}(w) \\in [0,1]$ is the normalized mean Hausdorff distance from the\n",
|
| 50 |
+
"`distance` baseline, $B(w) \\in [0,1]$ is the mean fraction of path points\n",
|
| 51 |
+
"within a margin of the image boundary, and $P_{\\text{run}}(w) \\in [0,1]$ is a\n",
|
| 52 |
+
"hard penalty for contiguous boundary runs:\n",
|
| 53 |
+
"\n",
|
| 54 |
+
"$$P_{\\text{run}}(w) = 1 - \\text{clamp}\\!\\left(\\frac{C(w) - \\theta}{\\theta},\\; 0,\\; 1\\right)$$\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"where $C(w)$ is the mean max-contiguous-boundary fraction and $\\theta$ is the\n",
|
| 57 |
+
"configurable threshold (`MAX_BOUNDARY_RUN_FRAC`, default 3%). Weights where\n",
|
| 58 |
+
"$C(w) \\ge 2\\theta$ receive a score of zero.\n",
|
| 59 |
+
"\n",
|
| 60 |
+
"Among weights with $\\text{score} \\ge \\tau \\cdot \\max(\\text{score})$, we pick the\n",
|
| 61 |
+
"**smallest** weight (asymptote minimization)."
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"cell_type": "code",
|
| 66 |
+
"execution_count": null,
|
| 67 |
+
"id": "d1ad71f1",
|
| 68 |
+
"metadata": {},
|
| 69 |
+
"outputs": [],
|
| 70 |
+
"source": [
|
| 71 |
+
"import importlib\n",
|
| 72 |
+
"import json\n",
|
| 73 |
+
"import logging\n",
|
| 74 |
+
"import math\n",
|
| 75 |
+
"import multiprocessing as mp\n",
|
| 76 |
+
"import random\n",
|
| 77 |
+
"import sys\n",
|
| 78 |
+
"import time\n",
|
| 79 |
+
"from pathlib import Path\n",
|
| 80 |
+
"\n",
|
| 81 |
+
"import matplotlib.pyplot as plt\n",
|
| 82 |
+
"import numpy as np\n",
|
| 83 |
+
"import pandas as pd\n",
|
| 84 |
+
"from loguru import logger as loguru_logger\n",
|
| 85 |
+
"from matplotlib.lines import Line2D\n",
|
| 86 |
+
"from tqdm import tqdm\n",
|
| 87 |
+
"\n",
|
| 88 |
+
"# Configure logging\n",
|
| 89 |
+
"logging.basicConfig(level=logging.INFO, format=\"%(asctime)s - %(name)s - %(levelname)s - %(message)s\")\n",
|
| 90 |
+
"logger = logging.getLogger(__name__)\n",
|
| 91 |
+
"logger.setLevel(logging.INFO)\n",
|
| 92 |
+
"loguru_logger.remove()\n",
|
| 93 |
+
"loguru_logger.add(sys.stderr, level=\"INFO\")\n",
|
| 94 |
+
"\n",
|
| 95 |
+
"ROOT = Path(\"..\").resolve()\n",
|
| 96 |
+
"sys.path.insert(0, str(ROOT / \"src\"))\n",
|
| 97 |
+
"\n",
|
| 98 |
+
"# Reload to pick up new functions added to pathfinding_utils\n",
|
| 99 |
+
"import passage.pathfinding_utils as pathfinding_utils # noqa: E402\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"importlib.reload(pathfinding_utils)\n",
|
| 102 |
+
"\n",
|
| 103 |
+
"from passage.generate import find_path, load_tile, _assemble_crop_from_tiles # noqa: E402\n",
|
| 104 |
+
"from passage.pathfinding_utils import ( # noqa: E402\n",
|
| 105 |
+
" COST_MODELS,\n",
|
| 106 |
+
" boundary_fraction,\n",
|
| 107 |
+
" hausdorff_distance,\n",
|
| 108 |
+
" max_contiguous_boundary_fraction,\n",
|
| 109 |
+
")"
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"cell_type": "code",
|
| 114 |
+
"execution_count": null,
|
| 115 |
+
"id": "9b7c746f",
|
| 116 |
+
"metadata": {},
|
| 117 |
+
"outputs": [],
|
| 118 |
+
"source": [
|
| 119 |
+
"# Parameters (papermill)\n",
|
| 120 |
+
"RESOLUTION = 256\n",
|
| 121 |
+
"NUM_SAMPLES = 1000\n",
|
| 122 |
+
"NUM_DISPLAY_SAMPLES = 20\n",
|
| 123 |
+
"BOUNDARY_MARGIN = 2 # pixels from edge considered \"near boundary\"\n",
|
| 124 |
+
"SCORE_THRESHOLD = 0.95 # fraction of max score for asymptote selection\n",
|
| 125 |
+
"MAX_BOUNDARY_RUN_FRAC = 0.03 # max allowed contiguous boundary run as fraction of path length\n",
|
| 126 |
+
"NUM_WORKERS = min(mp.cpu_count(), 16) # parallel workers for sample generation"
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"cell_type": "code",
|
| 131 |
+
"execution_count": null,
|
| 132 |
+
"id": "ae36c5ff",
|
| 133 |
+
"metadata": {},
|
| 134 |
+
"outputs": [],
|
| 135 |
+
"source": [
|
| 136 |
+
"# Configuration\n",
|
| 137 |
+
"TILES_DIR = ROOT / \"outputs\" / \"download\" / \"tiles\"\n",
|
| 138 |
+
"CALIBRATE_PATH = ROOT / \"outputs\" / \"calibrate\" / \"calibrate.json\"\n",
|
| 139 |
+
"\n",
|
| 140 |
+
"WEIGHTS = np.pow(10, np.linspace(0, 7, num=40)).tolist()\n",
|
| 141 |
+
"COST_MODELS_LIST = sorted(list(COST_MODELS))\n",
|
| 142 |
+
"COST_MODELS_TUNABLE = [cm for cm in COST_MODELS_LIST if cm != \"distance\"]\n",
|
| 143 |
+
"TILE_SIZE_PX = 3600\n",
|
| 144 |
+
"\n",
|
| 145 |
+
"# Color palette for cost models (consistent across all plots)\n",
|
| 146 |
+
"CM_COLORS = {cm: plt.cm.Set2(i / max(1, len(COST_MODELS_LIST) - 1)) for i, cm in enumerate(COST_MODELS_LIST)}\n",
|
| 147 |
+
"\n",
|
| 148 |
+
"print(f\"Resolution: {RESOLUTION}\")\n",
|
| 149 |
+
"print(f\"Num samples: {NUM_SAMPLES}\")\n",
|
| 150 |
+
"print(f\"Num display samples: {NUM_DISPLAY_SAMPLES}\")\n",
|
| 151 |
+
"print(f\"Weight range: [{WEIGHTS[0]:.1f} ... {WEIGHTS[-1]:.1f}] ({len(WEIGHTS)} values)\")\n",
|
| 152 |
+
"print(f\"Cost models: {COST_MODELS_LIST}\")\n",
|
| 153 |
+
"print(f\"Tunable (non-distance): {COST_MODELS_TUNABLE}\")"
|
| 154 |
+
]
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"cell_type": "code",
|
| 158 |
+
"execution_count": null,
|
| 159 |
+
"id": "ada0aee0",
|
| 160 |
+
"metadata": {},
|
| 161 |
+
"outputs": [],
|
| 162 |
+
"source": [
|
| 163 |
+
"# Load calibration data\n",
|
| 164 |
+
"if not CALIBRATE_PATH.exists():\n",
|
| 165 |
+
" raise FileNotFoundError(f\"Calibration file not found: {CALIBRATE_PATH}. Run 'passage calibrate' first.\")\n",
|
| 166 |
+
"if not TILES_DIR.exists():\n",
|
| 167 |
+
" raise FileNotFoundError(f\"Tiles directory not found: {TILES_DIR}. Run 'passage download' first.\")\n",
|
| 168 |
+
"\n",
|
| 169 |
+
"with open(CALIBRATE_PATH) as f:\n",
|
| 170 |
+
" calibration = json.load(f)\n",
|
| 171 |
+
"\n",
|
| 172 |
+
"global_min = float(calibration[\"global_min\"])\n",
|
| 173 |
+
"global_max = float(calibration[\"global_max\"])\n",
|
| 174 |
+
"tile_stats_df = pd.DataFrame(calibration[\"tile_stats\"])\n",
|
| 175 |
+
"\n",
|
| 176 |
+
"print(f\"Global elevation range: [{global_min:.1f}, {global_max:.1f}]\")\n",
|
| 177 |
+
"print(f\"Number of tiles: {len(tile_stats_df)}\")"
|
| 178 |
+
]
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"cell_type": "markdown",
|
| 182 |
+
"id": "4e262ab2",
|
| 183 |
+
"metadata": {},
|
| 184 |
+
"source": [
|
| 185 |
+
"## Helper Functions"
|
| 186 |
+
]
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"cell_type": "code",
|
| 190 |
+
"execution_count": null,
|
| 191 |
+
"id": "8073ee06",
|
| 192 |
+
"metadata": {},
|
| 193 |
+
"outputs": [],
|
| 194 |
+
"source": [
|
| 195 |
+
"def generate_random_crop(\n",
|
| 196 |
+
" resolution: int,\n",
|
| 197 |
+
" tile_stats_df: pd.DataFrame,\n",
|
| 198 |
+
" tiles_dirpath: Path,\n",
|
| 199 |
+
" global_min: float,\n",
|
| 200 |
+
" global_max: float,\n",
|
| 201 |
+
" seed: int | None = None,\n",
|
| 202 |
+
") -> np.ndarray | None:\n",
|
| 203 |
+
" if seed is not None:\n",
|
| 204 |
+
" random.seed(seed)\n",
|
| 205 |
+
" np.random.seed(seed)\n",
|
| 206 |
+
"\n",
|
| 207 |
+
" half_res = resolution // 2\n",
|
| 208 |
+
" half_tiles = max(1, math.ceil(half_res / TILE_SIZE_PX))\n",
|
| 209 |
+
" n_tiles = 2 * half_tiles + 1\n",
|
| 210 |
+
" grid_h = n_tiles * TILE_SIZE_PX\n",
|
| 211 |
+
" grid_w = n_tiles * TILE_SIZE_PX\n",
|
| 212 |
+
"\n",
|
| 213 |
+
" for _ in range(10):\n",
|
| 214 |
+
" target_elev = random.uniform(global_min, global_max)\n",
|
| 215 |
+
" candidates = tile_stats_df[(tile_stats_df[\"min\"] <= target_elev) & (tile_stats_df[\"max\"] >= target_elev)]\n",
|
| 216 |
+
" if candidates.empty:\n",
|
| 217 |
+
" continue\n",
|
| 218 |
+
" selected = candidates.sample(n=1).iloc[0]\n",
|
| 219 |
+
" center_lat = int(selected[\"lat\"])\n",
|
| 220 |
+
" center_lon = int(selected[\"lon\"])\n",
|
| 221 |
+
" if grid_h < resolution or grid_w < resolution:\n",
|
| 222 |
+
" continue\n",
|
| 223 |
+
" y1 = random.randint(0, grid_h - resolution)\n",
|
| 224 |
+
" x1 = random.randint(0, grid_w - resolution)\n",
|
| 225 |
+
" center_tile = load_tile(tiles_dirpath, center_lat, center_lon)\n",
|
| 226 |
+
" crop = _assemble_crop_from_tiles(\n",
|
| 227 |
+
" tiles_dirpath=tiles_dirpath,\n",
|
| 228 |
+
" center_lat=center_lat,\n",
|
| 229 |
+
" center_lon=center_lon,\n",
|
| 230 |
+
" half_tiles=half_tiles,\n",
|
| 231 |
+
" y1=y1,\n",
|
| 232 |
+
" x1=x1,\n",
|
| 233 |
+
" resolution=resolution,\n",
|
| 234 |
+
" center_tile=center_tile,\n",
|
| 235 |
+
" )\n",
|
| 236 |
+
" return crop\n",
|
| 237 |
+
" return None\n",
|
| 238 |
+
"\n",
|
| 239 |
+
"\n",
|
| 240 |
+
"def get_marker_positions(resolution: int) -> tuple[tuple[int, int], tuple[int, int]]:\n",
|
| 241 |
+
" pos1 = int(0.2 * resolution)\n",
|
| 242 |
+
" pos2 = int(0.8 * resolution)\n",
|
| 243 |
+
" return (pos1, pos1), (pos2, pos2)\n",
|
| 244 |
+
"\n",
|
| 245 |
+
"\n",
|
| 246 |
+
"def compute_path_for_crop(\n",
|
| 247 |
+
" crop: np.ndarray,\n",
|
| 248 |
+
" start: tuple[int, int],\n",
|
| 249 |
+
" end: tuple[int, int],\n",
|
| 250 |
+
" cost_model_name: str,\n",
|
| 251 |
+
" weight: float,\n",
|
| 252 |
+
") -> list:\n",
|
| 253 |
+
" solver_config = {\n",
|
| 254 |
+
" \"name\": \"grid:astar\",\n",
|
| 255 |
+
" \"diagonal_movement\": \"always\",\n",
|
| 256 |
+
" \"weight\": float(weight),\n",
|
| 257 |
+
" \"cost_model\": cost_model_name,\n",
|
| 258 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 259 |
+
" }\n",
|
| 260 |
+
" return find_path(crop, start, end, solver_config)\n",
|
| 261 |
+
"\n",
|
| 262 |
+
"\n",
|
| 263 |
+
"def _process_one_sample(i):\n",
|
| 264 |
+
" \"\"\"Worker: generate one sample and compute all paths (for multiprocessing).\"\"\"\n",
|
| 265 |
+
" crop = generate_random_crop(RESOLUTION, tile_stats_df, TILES_DIR, global_min, global_max, seed=1000 + i)\n",
|
| 266 |
+
" if crop is None:\n",
|
| 267 |
+
" return None\n",
|
| 268 |
+
" start, end = get_marker_positions(RESOLUTION)\n",
|
| 269 |
+
" paths = {}\n",
|
| 270 |
+
" for cm in COST_MODELS_LIST:\n",
|
| 271 |
+
" paths[cm] = {}\n",
|
| 272 |
+
" for w in WEIGHTS:\n",
|
| 273 |
+
" paths[cm][w] = compute_path_for_crop(crop, start, end, cm, w)\n",
|
| 274 |
+
" return {\"index\": i + 1, \"crop\": crop, \"start\": start, \"end\": end, \"paths\": paths}\n",
|
| 275 |
+
"\n",
|
| 276 |
+
"\n",
|
| 277 |
+
"def _process_one_display_sample(i):\n",
|
| 278 |
+
" \"\"\"Worker: generate one display sample with tuned weights (for multiprocessing).\"\"\"\n",
|
| 279 |
+
" crop = generate_random_crop(RESOLUTION, tile_stats_df, TILES_DIR, global_min, global_max, seed=5000 + i)\n",
|
| 280 |
+
" if crop is None:\n",
|
| 281 |
+
" return None\n",
|
| 282 |
+
" start, end = get_marker_positions(RESOLUTION)\n",
|
| 283 |
+
" paths = {}\n",
|
| 284 |
+
" paths[\"distance\"] = compute_path_for_crop(crop, start, end, \"distance\", 1.0)\n",
|
| 285 |
+
" for cm, w in weights_tuned.items():\n",
|
| 286 |
+
" paths[cm] = compute_path_for_crop(crop, start, end, cm, w)\n",
|
| 287 |
+
" return {\"index\": i + 1, \"crop\": crop, \"start\": start, \"end\": end, \"paths\": paths}"
|
| 288 |
+
]
|
| 289 |
+
},
|
| 290 |
+
{
|
| 291 |
+
"cell_type": "markdown",
|
| 292 |
+
"id": "2cf60b38",
|
| 293 |
+
"metadata": {},
|
| 294 |
+
"source": [
|
| 295 |
+
"---\n",
|
| 296 |
+
"\n",
|
| 297 |
+
"## 1. Generate Samples & Compute Paths\n",
|
| 298 |
+
"\n",
|
| 299 |
+
"For each sample, compute paths with every (cost_model, weight) combination."
|
| 300 |
+
]
|
| 301 |
+
},
|
| 302 |
+
{
|
| 303 |
+
"cell_type": "code",
|
| 304 |
+
"execution_count": null,
|
| 305 |
+
"id": "e4ddd798",
|
| 306 |
+
"metadata": {},
|
| 307 |
+
"outputs": [],
|
| 308 |
+
"source": [
|
| 309 |
+
"t0 = time.time()\n",
|
| 310 |
+
"ctx = mp.get_context(\"fork\")\n",
|
| 311 |
+
"with ctx.Pool(NUM_WORKERS) as pool:\n",
|
| 312 |
+
" results = list(\n",
|
| 313 |
+
" tqdm(\n",
|
| 314 |
+
" pool.imap_unordered(_process_one_sample, range(NUM_SAMPLES)),\n",
|
| 315 |
+
" total=NUM_SAMPLES,\n",
|
| 316 |
+
" desc=f\"Generating samples ({NUM_WORKERS} workers)\",\n",
|
| 317 |
+
" )\n",
|
| 318 |
+
" )\n",
|
| 319 |
+
"\n",
|
| 320 |
+
"samples = sorted([r for r in results if r is not None], key=lambda s: s[\"index\"])\n",
|
| 321 |
+
"\n",
|
| 322 |
+
"elapsed = time.time() - t0\n",
|
| 323 |
+
"print(f\"\\nGenerated {len(samples)}/{NUM_SAMPLES} samples in {elapsed:.1f}s ({NUM_WORKERS} workers)\")"
|
| 324 |
+
]
|
| 325 |
+
},
|
| 326 |
+
{
|
| 327 |
+
"cell_type": "markdown",
|
| 328 |
+
"id": "bc957c76",
|
| 329 |
+
"metadata": {},
|
| 330 |
+
"source": [
|
| 331 |
+
"---\n",
|
| 332 |
+
"\n",
|
| 333 |
+
"## 2. Path Length Analysis\n",
|
| 334 |
+
"\n",
|
| 335 |
+
"How does path length vary with weight for each cost model?"
|
| 336 |
+
]
|
| 337 |
+
},
|
| 338 |
+
{
|
| 339 |
+
"cell_type": "code",
|
| 340 |
+
"execution_count": null,
|
| 341 |
+
"id": "8858d965",
|
| 342 |
+
"metadata": {},
|
| 343 |
+
"outputs": [],
|
| 344 |
+
"source": [
|
| 345 |
+
"# Build per-(sample, cost_model, weight) records\n",
|
| 346 |
+
"records = []\n",
|
| 347 |
+
"for sample in samples:\n",
|
| 348 |
+
" for cm in COST_MODELS_LIST:\n",
|
| 349 |
+
" for w in WEIGHTS:\n",
|
| 350 |
+
" path = sample[\"paths\"][cm][w]\n",
|
| 351 |
+
" records.append(\n",
|
| 352 |
+
" {\n",
|
| 353 |
+
" \"sample\": sample[\"index\"],\n",
|
| 354 |
+
" \"cost_model\": cm,\n",
|
| 355 |
+
" \"weight\": w,\n",
|
| 356 |
+
" \"path_length\": len(path),\n",
|
| 357 |
+
" \"found\": len(path) > 0,\n",
|
| 358 |
+
" }\n",
|
| 359 |
+
" )\n",
|
| 360 |
+
"\n",
|
| 361 |
+
"results_df = pd.DataFrame(records)\n",
|
| 362 |
+
"print(f\"Records: {len(results_df)}\")\n",
|
| 363 |
+
"results_df.head()"
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"cell_type": "code",
|
| 368 |
+
"execution_count": null,
|
| 369 |
+
"id": "2dfb4d67",
|
| 370 |
+
"metadata": {},
|
| 371 |
+
"outputs": [],
|
| 372 |
+
"source": [
|
| 373 |
+
"# Mean path length vs weight per cost model\n",
|
| 374 |
+
"fig, axes = plt.subplots(1, 2, figsize=(16, 5))\n",
|
| 375 |
+
"\n",
|
| 376 |
+
"# Left: mean path length\n",
|
| 377 |
+
"ax = axes[0]\n",
|
| 378 |
+
"for cm in COST_MODELS_LIST:\n",
|
| 379 |
+
" sub = results_df[results_df[\"cost_model\"] == cm]\n",
|
| 380 |
+
" agg = sub.groupby(\"weight\")[\"path_length\"].mean()\n",
|
| 381 |
+
" ax.plot(agg.index, agg.values, \"o-\", lw=1.2, markersize=3, label=cm, color=CM_COLORS[cm])\n",
|
| 382 |
+
"ax.set_xscale(\"log\")\n",
|
| 383 |
+
"ax.set_xlabel(\"Weight\")\n",
|
| 384 |
+
"ax.set_ylabel(\"Mean path length (px)\")\n",
|
| 385 |
+
"ax.set_title(\"Mean Path Length vs Weight\")\n",
|
| 386 |
+
"ax.legend(fontsize=8)\n",
|
| 387 |
+
"ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 388 |
+
"\n",
|
| 389 |
+
"# Right: path-found rate\n",
|
| 390 |
+
"ax = axes[1]\n",
|
| 391 |
+
"for cm in COST_MODELS_LIST:\n",
|
| 392 |
+
" sub = results_df[results_df[\"cost_model\"] == cm]\n",
|
| 393 |
+
" agg = sub.groupby(\"weight\")[\"found\"].mean()\n",
|
| 394 |
+
" ax.plot(agg.index, agg.values, \"o-\", lw=1.2, markersize=3, label=cm, color=CM_COLORS[cm])\n",
|
| 395 |
+
"ax.set_xscale(\"log\")\n",
|
| 396 |
+
"ax.set_xlabel(\"Weight\")\n",
|
| 397 |
+
"ax.set_ylabel(\"Path found rate\")\n",
|
| 398 |
+
"ax.set_title(\"Path Success Rate vs Weight\")\n",
|
| 399 |
+
"ax.set_ylim(-0.05, 1.05)\n",
|
| 400 |
+
"ax.legend(fontsize=8)\n",
|
| 401 |
+
"ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 402 |
+
"\n",
|
| 403 |
+
"plt.tight_layout()\n",
|
| 404 |
+
"plt.show()"
|
| 405 |
+
]
|
| 406 |
+
},
|
| 407 |
+
{
|
| 408 |
+
"cell_type": "markdown",
|
| 409 |
+
"id": "bf159867",
|
| 410 |
+
"metadata": {},
|
| 411 |
+
"source": [
|
| 412 |
+
"### Analysis: Path Length & Success Rate\n",
|
| 413 |
+
"\n",
|
| 414 |
+
"**Left panel — Mean path length vs weight:**\n",
|
| 415 |
+
"- The `distance` model (flat cost) produces a constant, short path regardless of weight — it always follows the Euclidean-shortest route, confirming it as our \"straight-line\" baseline.\n",
|
| 416 |
+
"- All elevation-aware cost models show increasing path length with weight: higher weight amplifies the terrain penalty, forcing the solver to route around obstacles instead of crossing them.\n",
|
| 417 |
+
"- `elevation` and `slope_uphill` show the steepest length increase, indicating they generate the most tortuous detours. `absolute_elevation` saturates earliest, meaning its terrain signal is relatively weak compared to distance costs at moderate weights.\n",
|
| 418 |
+
"- Beyond ~$10^5$, most models plateau — the path cannot deviate much further within a 256×256 crop.\n",
|
| 419 |
+
"\n",
|
| 420 |
+
"**Right panel — Path success rate:**\n",
|
| 421 |
+
"- All cost models maintain a 100% success rate across the full weight range. This confirms that the A* solver with 8-connectivity always finds a valid path within the crop, and no weight causes the solver to fail. This is expected since the grid is fully connected (diagonal movement = \"always\") and the start/end points are always at fixed positions (20%/80% of resolution)."
|
| 422 |
+
]
|
| 423 |
+
},
|
| 424 |
+
{
|
| 425 |
+
"cell_type": "markdown",
|
| 426 |
+
"id": "b2a3afc7",
|
| 427 |
+
"metadata": {},
|
| 428 |
+
"source": [
|
| 429 |
+
"---\n",
|
| 430 |
+
"\n",
|
| 431 |
+
"## 3. Hausdorff Distance from `distance` Baseline\n",
|
| 432 |
+
"\n",
|
| 433 |
+
"Measure how different each cost model's path is from the flat `distance` model\n",
|
| 434 |
+
"(straight-line baseline). Higher Hausdorff = more elevation-aware deviation."
|
| 435 |
+
]
|
| 436 |
+
},
|
| 437 |
+
{
|
| 438 |
+
"cell_type": "code",
|
| 439 |
+
"execution_count": null,
|
| 440 |
+
"id": "90af6c1c",
|
| 441 |
+
"metadata": {},
|
| 442 |
+
"outputs": [],
|
| 443 |
+
"source": [
|
| 444 |
+
"# Compute per-(sample, cost_model, weight): Hausdorff vs distance, boundary fraction, contiguous run\n",
|
| 445 |
+
"metric_records = []\n",
|
| 446 |
+
"\n",
|
| 447 |
+
"for sample in tqdm(samples, desc=\"Computing metrics\"):\n",
|
| 448 |
+
" crop = sample[\"crop\"]\n",
|
| 449 |
+
" paths = sample[\"paths\"]\n",
|
| 450 |
+
" res = crop.shape[0]\n",
|
| 451 |
+
"\n",
|
| 452 |
+
" # distance model is weight-independent — use first weight as baseline\n",
|
| 453 |
+
" distance_path = paths[\"distance\"][WEIGHTS[0]]\n",
|
| 454 |
+
"\n",
|
| 455 |
+
" for cm in COST_MODELS_LIST:\n",
|
| 456 |
+
" for w in WEIGHTS:\n",
|
| 457 |
+
" path = paths[cm][w]\n",
|
| 458 |
+
" hd = hausdorff_distance(path, distance_path)\n",
|
| 459 |
+
" bf = boundary_fraction(path, res, BOUNDARY_MARGIN)\n",
|
| 460 |
+
" mcbf = max_contiguous_boundary_fraction(path, res, BOUNDARY_MARGIN)\n",
|
| 461 |
+
" metric_records.append(\n",
|
| 462 |
+
" {\n",
|
| 463 |
+
" \"sample\": sample[\"index\"],\n",
|
| 464 |
+
" \"cost_model\": cm,\n",
|
| 465 |
+
" \"weight\": w,\n",
|
| 466 |
+
" \"hausdorff_vs_distance\": hd,\n",
|
| 467 |
+
" \"boundary_frac\": bf,\n",
|
| 468 |
+
" \"hits_boundary\": bf > 0,\n",
|
| 469 |
+
" \"max_contiguous_boundary_frac\": mcbf,\n",
|
| 470 |
+
" \"path_length\": len(path),\n",
|
| 471 |
+
" }\n",
|
| 472 |
+
" )\n",
|
| 473 |
+
"\n",
|
| 474 |
+
"metric_df = pd.DataFrame(metric_records)\n",
|
| 475 |
+
"print(f\"Metric records: {len(metric_df)}\")"
|
| 476 |
+
]
|
| 477 |
+
},
|
| 478 |
+
{
|
| 479 |
+
"cell_type": "code",
|
| 480 |
+
"execution_count": null,
|
| 481 |
+
"id": "558b0c4b",
|
| 482 |
+
"metadata": {},
|
| 483 |
+
"outputs": [],
|
| 484 |
+
"source": [
|
| 485 |
+
"# Aggregate across samples\n",
|
| 486 |
+
"agg_df = (\n",
|
| 487 |
+
" metric_df.groupby([\"cost_model\", \"weight\"])\n",
|
| 488 |
+
" .agg(\n",
|
| 489 |
+
" mean_hausdorff=(\"hausdorff_vs_distance\", \"mean\"),\n",
|
| 490 |
+
" std_hausdorff=(\"hausdorff_vs_distance\", \"std\"),\n",
|
| 491 |
+
" mean_boundary_frac=(\"boundary_frac\", \"mean\"),\n",
|
| 492 |
+
" boundary_hit_rate=(\"hits_boundary\", \"mean\"),\n",
|
| 493 |
+
" mean_max_contig_boundary=(\"max_contiguous_boundary_frac\", \"mean\"),\n",
|
| 494 |
+
" mean_path_length=(\"path_length\", \"mean\"),\n",
|
| 495 |
+
" )\n",
|
| 496 |
+
" .reset_index()\n",
|
| 497 |
+
")\n",
|
| 498 |
+
"agg_df.head()"
|
| 499 |
+
]
|
| 500 |
+
},
|
| 501 |
+
{
|
| 502 |
+
"cell_type": "code",
|
| 503 |
+
"execution_count": null,
|
| 504 |
+
"id": "1e3f61f3",
|
| 505 |
+
"metadata": {},
|
| 506 |
+
"outputs": [],
|
| 507 |
+
"source": [
|
| 508 |
+
"# Hausdorff distance vs weight — all tunable cost models overlaid\n",
|
| 509 |
+
"fig, ax = plt.subplots(figsize=(12, 6))\n",
|
| 510 |
+
"\n",
|
| 511 |
+
"for cm in COST_MODELS_TUNABLE:\n",
|
| 512 |
+
" sub = agg_df[agg_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 513 |
+
" ax.plot(\n",
|
| 514 |
+
" sub[\"weight\"],\n",
|
| 515 |
+
" sub[\"mean_hausdorff\"],\n",
|
| 516 |
+
" \"o-\",\n",
|
| 517 |
+
" lw=1.5,\n",
|
| 518 |
+
" markersize=4,\n",
|
| 519 |
+
" label=cm,\n",
|
| 520 |
+
" color=CM_COLORS[cm],\n",
|
| 521 |
+
" )\n",
|
| 522 |
+
" ax.fill_between(\n",
|
| 523 |
+
" sub[\"weight\"],\n",
|
| 524 |
+
" sub[\"mean_hausdorff\"] - sub[\"std_hausdorff\"],\n",
|
| 525 |
+
" sub[\"mean_hausdorff\"] + sub[\"std_hausdorff\"],\n",
|
| 526 |
+
" alpha=0.15,\n",
|
| 527 |
+
" color=CM_COLORS[cm],\n",
|
| 528 |
+
" )\n",
|
| 529 |
+
"\n",
|
| 530 |
+
"ax.set_xscale(\"log\")\n",
|
| 531 |
+
"ax.set_xlabel(\"Weight\")\n",
|
| 532 |
+
"ax.set_ylabel(\"Mean Hausdorff distance from `distance` baseline (px)\")\n",
|
| 533 |
+
"ax.set_title(\"Path Diversity: Hausdorff Distance vs Weight\")\n",
|
| 534 |
+
"ax.legend(fontsize=9)\n",
|
| 535 |
+
"ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 536 |
+
"plt.tight_layout()\n",
|
| 537 |
+
"plt.show()"
|
| 538 |
+
]
|
| 539 |
+
},
|
| 540 |
+
{
|
| 541 |
+
"cell_type": "code",
|
| 542 |
+
"execution_count": null,
|
| 543 |
+
"id": "f4d8bb99",
|
| 544 |
+
"metadata": {},
|
| 545 |
+
"outputs": [],
|
| 546 |
+
"source": [
|
| 547 |
+
"# Per-cost-model Hausdorff subplots with individual y-scales\n",
|
| 548 |
+
"n_cm = len(COST_MODELS_TUNABLE)\n",
|
| 549 |
+
"fig, axes = plt.subplots(1, n_cm, figsize=(5 * n_cm, 4), sharey=False)\n",
|
| 550 |
+
"if n_cm == 1:\n",
|
| 551 |
+
" axes = [axes]\n",
|
| 552 |
+
"\n",
|
| 553 |
+
"for idx, cm in enumerate(COST_MODELS_TUNABLE):\n",
|
| 554 |
+
" ax = axes[idx]\n",
|
| 555 |
+
" sub = agg_df[agg_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 556 |
+
" ax.plot(sub[\"weight\"], sub[\"mean_hausdorff\"], \"o-\", lw=1.5, markersize=4, color=CM_COLORS[cm])\n",
|
| 557 |
+
" ax.fill_between(\n",
|
| 558 |
+
" sub[\"weight\"],\n",
|
| 559 |
+
" sub[\"mean_hausdorff\"] - sub[\"std_hausdorff\"],\n",
|
| 560 |
+
" sub[\"mean_hausdorff\"] + sub[\"std_hausdorff\"],\n",
|
| 561 |
+
" alpha=0.2,\n",
|
| 562 |
+
" color=CM_COLORS[cm],\n",
|
| 563 |
+
" )\n",
|
| 564 |
+
" # Mark peak\n",
|
| 565 |
+
" peak_idx = sub[\"mean_hausdorff\"].idxmax()\n",
|
| 566 |
+
" peak_row = sub.loc[peak_idx]\n",
|
| 567 |
+
" ax.scatter([peak_row[\"weight\"]], [peak_row[\"mean_hausdorff\"]], color=\"red\", s=50, zorder=10)\n",
|
| 568 |
+
" ax.annotate(\n",
|
| 569 |
+
" f\"w={peak_row['weight']:.0f}\",\n",
|
| 570 |
+
" xy=(peak_row[\"weight\"], peak_row[\"mean_hausdorff\"]),\n",
|
| 571 |
+
" xytext=(5, 8),\n",
|
| 572 |
+
" textcoords=\"offset points\",\n",
|
| 573 |
+
" fontsize=8,\n",
|
| 574 |
+
" color=\"red\",\n",
|
| 575 |
+
" )\n",
|
| 576 |
+
" ax.set_xscale(\"log\")\n",
|
| 577 |
+
" ax.set_title(cm, fontsize=11)\n",
|
| 578 |
+
" ax.set_xlabel(\"Weight\")\n",
|
| 579 |
+
" if idx == 0:\n",
|
| 580 |
+
" ax.set_ylabel(\"Mean Hausdorff (px)\")\n",
|
| 581 |
+
" ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 582 |
+
"\n",
|
| 583 |
+
"fig.suptitle(\"Hausdorff Distance per Cost Model\", fontsize=13)\n",
|
| 584 |
+
"plt.tight_layout()\n",
|
| 585 |
+
"plt.show()"
|
| 586 |
+
]
|
| 587 |
+
},
|
| 588 |
+
{
|
| 589 |
+
"cell_type": "markdown",
|
| 590 |
+
"id": "6398ef31",
|
| 591 |
+
"metadata": {},
|
| 592 |
+
"source": [
|
| 593 |
+
"### Analysis: Hausdorff Distance from Distance Baseline\n",
|
| 594 |
+
"\n",
|
| 595 |
+
"**Overlay plot:** All tunable cost models show a characteristic rise-then-plateau pattern in Hausdorff distance vs weight, but with very different magnitudes:\n",
|
| 596 |
+
"\n",
|
| 597 |
+
"- **`elevation`** achieves the highest Hausdorff distance (~50 px at peak), meaning it produces the most divergent paths from the straight-line baseline. This makes sense: the `elevation` model penalizes elevation *differences* between successive cells, so it actively routes around ridges and valleys.\n",
|
| 598 |
+
"- **`energy`** and **`slope_uphill`** reach intermediate peaks (~40 px). The `energy` model penalizes cumulative elevation gain, while `slope_uphill` only penalizes uphill slopes — both produce meaningful but more moderate deviations.\n",
|
| 599 |
+
"- **`absolute_elevation`** has the lowest Hausdorff distance (~5 px). This model penalizes *absolute* elevation values rather than gradients, so in crops with relatively uniform elevation, it produces near-straight paths. It only deviates when there are large absolute elevation differences (e.g., sea-level vs mountains).\n",
|
| 600 |
+
"\n",
|
| 601 |
+
"**Per-model subplots (with peaks):** The red markers show the weight at which each model's Hausdorff distance peaks. Beyond these peaks, further weight increases yield diminishing returns (the path has already deviated as far as the 256×256 crop allows). The ±1σ bands show significant sample-to-sample variance, especially for `elevation`, reflecting the diversity of terrain encountered across 1000 random crops.\n",
|
| 602 |
+
"\n",
|
| 603 |
+
"> **Key insight:** Raw Hausdorff maximization alone would always pick the highest possible weight. But as we'll see in the boundary analysis, very high weights cause paths to hug image edges — an artifact, not a meaningful route."
|
| 604 |
+
]
|
| 605 |
+
},
|
| 606 |
+
{
|
| 607 |
+
"cell_type": "markdown",
|
| 608 |
+
"id": "7eb0f6aa",
|
| 609 |
+
"metadata": {},
|
| 610 |
+
"source": [
|
| 611 |
+
"---\n",
|
| 612 |
+
"\n",
|
| 613 |
+
"## 4. Boundary Hit Analysis\n",
|
| 614 |
+
"\n",
|
| 615 |
+
"At high weights, paths may deviate so much that they hug image boundaries —\n",
|
| 616 |
+
"an artifact of the finite crop, not a meaningful route choice."
|
| 617 |
+
]
|
| 618 |
+
},
|
| 619 |
+
{
|
| 620 |
+
"cell_type": "code",
|
| 621 |
+
"execution_count": null,
|
| 622 |
+
"id": "316ae35a",
|
| 623 |
+
"metadata": {},
|
| 624 |
+
"outputs": [],
|
| 625 |
+
"source": [
|
| 626 |
+
"# Boundary hit rate and boundary fraction vs weight\n",
|
| 627 |
+
"fig, axes = plt.subplots(1, 2, figsize=(16, 5))\n",
|
| 628 |
+
"\n",
|
| 629 |
+
"# Left: boundary hit rate (fraction of samples with any boundary contact)\n",
|
| 630 |
+
"ax = axes[0]\n",
|
| 631 |
+
"for cm in COST_MODELS_TUNABLE:\n",
|
| 632 |
+
" sub = agg_df[agg_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 633 |
+
" ax.plot(sub[\"weight\"], sub[\"boundary_hit_rate\"], \"o-\", lw=1.2, markersize=3, label=cm, color=CM_COLORS[cm])\n",
|
| 634 |
+
"ax.set_xscale(\"log\")\n",
|
| 635 |
+
"ax.set_xlabel(\"Weight\")\n",
|
| 636 |
+
"ax.set_ylabel(\"Boundary hit rate (fraction of samples)\")\n",
|
| 637 |
+
"ax.set_title(\"Boundary Hit Rate vs Weight\")\n",
|
| 638 |
+
"ax.set_ylim(-0.05, 1.05)\n",
|
| 639 |
+
"ax.legend(fontsize=8)\n",
|
| 640 |
+
"ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 641 |
+
"\n",
|
| 642 |
+
"# Right: mean boundary fraction (fraction of path points at boundary)\n",
|
| 643 |
+
"ax = axes[1]\n",
|
| 644 |
+
"for cm in COST_MODELS_TUNABLE:\n",
|
| 645 |
+
" sub = agg_df[agg_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 646 |
+
" ax.plot(sub[\"weight\"], sub[\"mean_boundary_frac\"], \"s-\", lw=1.2, markersize=3, label=cm, color=CM_COLORS[cm])\n",
|
| 647 |
+
"ax.set_xscale(\"log\")\n",
|
| 648 |
+
"ax.set_xlabel(\"Weight\")\n",
|
| 649 |
+
"ax.set_ylabel(\"Mean boundary fraction\")\n",
|
| 650 |
+
"ax.set_title(\"Mean Boundary Fraction vs Weight\")\n",
|
| 651 |
+
"ax.legend(fontsize=8)\n",
|
| 652 |
+
"ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 653 |
+
"\n",
|
| 654 |
+
"plt.tight_layout()\n",
|
| 655 |
+
"plt.show()"
|
| 656 |
+
]
|
| 657 |
+
},
|
| 658 |
+
{
|
| 659 |
+
"cell_type": "code",
|
| 660 |
+
"execution_count": null,
|
| 661 |
+
"id": "9ffd51a4",
|
| 662 |
+
"metadata": {},
|
| 663 |
+
"outputs": [],
|
| 664 |
+
"source": [
|
| 665 |
+
"# Per-cost-model boundary fraction subplots\n",
|
| 666 |
+
"fig, axes = plt.subplots(1, n_cm, figsize=(5 * n_cm, 4), sharey=True)\n",
|
| 667 |
+
"if n_cm == 1:\n",
|
| 668 |
+
" axes = [axes]\n",
|
| 669 |
+
"\n",
|
| 670 |
+
"for idx, cm in enumerate(COST_MODELS_TUNABLE):\n",
|
| 671 |
+
" ax = axes[idx]\n",
|
| 672 |
+
" sub = agg_df[agg_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 673 |
+
" ax.fill_between(sub[\"weight\"], 0, sub[\"mean_boundary_frac\"], alpha=0.3, color=CM_COLORS[cm])\n",
|
| 674 |
+
" ax.plot(sub[\"weight\"], sub[\"mean_boundary_frac\"], \"s-\", lw=1.2, markersize=3, color=CM_COLORS[cm])\n",
|
| 675 |
+
" ax.set_xscale(\"log\")\n",
|
| 676 |
+
" ax.set_title(cm, fontsize=11)\n",
|
| 677 |
+
" ax.set_xlabel(\"Weight\")\n",
|
| 678 |
+
" if idx == 0:\n",
|
| 679 |
+
" ax.set_ylabel(\"Mean boundary fraction\")\n",
|
| 680 |
+
" ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 681 |
+
"\n",
|
| 682 |
+
"fig.suptitle(\"Boundary Fraction per Cost Model\", fontsize=13)\n",
|
| 683 |
+
"plt.tight_layout()\n",
|
| 684 |
+
"plt.show()"
|
| 685 |
+
]
|
| 686 |
+
},
|
| 687 |
+
{
|
| 688 |
+
"cell_type": "markdown",
|
| 689 |
+
"id": "6d751dfa",
|
| 690 |
+
"metadata": {},
|
| 691 |
+
"source": [
|
| 692 |
+
"### Analysis: Boundary Artifacts\n",
|
| 693 |
+
"\n",
|
| 694 |
+
"**Left panel — Boundary hit rate:** The fraction of samples where *any* path point falls within 2 pixels of the crop edge. For most models this remains near zero for moderate weights, but:\n",
|
| 695 |
+
"- **`elevation`** stands out with a boundary hit rate climbing to ~20-40% at high weights ($w > 10^4$). This is the most aggressive model — when terrain penalties dominate, the solver finds it cheaper to route along the flat boundary pixels (which have constant elevation) than to cross real terrain features.\n",
|
| 696 |
+
"- **`slope_uphill`** shows a smaller but non-negligible boundary hit rate at very high weights.\n",
|
| 697 |
+
"- **`absolute_elevation`** and **`energy`** remain well-behaved with near-zero boundary contact across all weights.\n",
|
| 698 |
+
"\n",
|
| 699 |
+
"**Right panel — Mean boundary fraction:** Even among samples that *do* hit the boundary, how much of the path is affected? The `elevation` model is again the outlier, with up to ~4% of path points near the boundary at extreme weights. This confirms the need for a penalty term.\n",
|
| 700 |
+
"\n",
|
| 701 |
+
"**Per-model area charts:** Visualize the boundary fraction profile per model. The `elevation` model's boundary fraction rises sharply above $w \\approx 10^3$, precisely the weight range where Hausdorff distance also saturates — confirming that the additional \"deviation\" is actually boundary hugging, not meaningful terrain avoidance.\n",
|
| 702 |
+
"\n",
|
| 703 |
+
"> **Rationale for the boundary penalty:** Without penalizing boundary contact, weight tuning would select extreme weights that produce visually implausible paths running along crop edges. The term $(1 - B(w))$ in the combined score elegantly suppresses these artifact weights."
|
| 704 |
+
]
|
| 705 |
+
},
|
| 706 |
+
{
|
| 707 |
+
"cell_type": "markdown",
|
| 708 |
+
"id": "9d7b275b",
|
| 709 |
+
"metadata": {},
|
| 710 |
+
"source": [
|
| 711 |
+
"---\n",
|
| 712 |
+
"\n",
|
| 713 |
+
"## 5. Weight Tuning: Combined Score\n",
|
| 714 |
+
"\n",
|
| 715 |
+
"Compute the combined score $\\text{score}(w) = \\hat{H}(w) \\cdot (1 - B(w)) \\cdot P_{\\text{run}}(w)$\n",
|
| 716 |
+
"and select the optimal weight per cost model."
|
| 717 |
+
]
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"cell_type": "code",
|
| 721 |
+
"execution_count": null,
|
| 722 |
+
"id": "3a0e4e1c",
|
| 723 |
+
"metadata": {},
|
| 724 |
+
"outputs": [],
|
| 725 |
+
"source": [
|
| 726 |
+
"# Compute normalized Hausdorff, contiguous-run penalty, and combined score\n",
|
| 727 |
+
"tune_df = agg_df[agg_df[\"cost_model\"] != \"distance\"].copy()\n",
|
| 728 |
+
"\n",
|
| 729 |
+
"tune_df[\"h_norm\"] = tune_df.groupby(\"cost_model\")[\"mean_hausdorff\"].transform(\n",
|
| 730 |
+
" lambda s: s / s.max() if s.max() > 0 else 0.0\n",
|
| 731 |
+
")\n",
|
| 732 |
+
"\n",
|
| 733 |
+
"# Contiguous-run penalty: linear ramp from 1→0 between threshold and 2×threshold\n",
|
| 734 |
+
"tune_df[\"run_penalty\"] = 1.0 - np.clip(\n",
|
| 735 |
+
" (tune_df[\"mean_max_contig_boundary\"] - MAX_BOUNDARY_RUN_FRAC) / MAX_BOUNDARY_RUN_FRAC,\n",
|
| 736 |
+
" 0.0,\n",
|
| 737 |
+
" 1.0,\n",
|
| 738 |
+
")\n",
|
| 739 |
+
"\n",
|
| 740 |
+
"tune_df[\"score\"] = tune_df[\"h_norm\"] * (1.0 - tune_df[\"mean_boundary_frac\"]) * tune_df[\"run_penalty\"]\n",
|
| 741 |
+
"tune_df.sort_values([\"cost_model\", \"weight\"], inplace=True)\n",
|
| 742 |
+
"\n",
|
| 743 |
+
"tune_df[\n",
|
| 744 |
+
" [\"cost_model\", \"weight\", \"h_norm\", \"mean_boundary_frac\", \"mean_max_contig_boundary\", \"run_penalty\", \"score\"]\n",
|
| 745 |
+
"].head(10)"
|
| 746 |
+
]
|
| 747 |
+
},
|
| 748 |
+
{
|
| 749 |
+
"cell_type": "code",
|
| 750 |
+
"execution_count": null,
|
| 751 |
+
"id": "50ac9e18",
|
| 752 |
+
"metadata": {},
|
| 753 |
+
"outputs": [],
|
| 754 |
+
"source": [
|
| 755 |
+
"# Select optimal weight per cost model\n",
|
| 756 |
+
"weights_tuned = {}\n",
|
| 757 |
+
"tuning_details = {}\n",
|
| 758 |
+
"\n",
|
| 759 |
+
"for cm in COST_MODELS_TUNABLE:\n",
|
| 760 |
+
" cm_df = tune_df[tune_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 761 |
+
" w_arr = cm_df[\"weight\"].values\n",
|
| 762 |
+
" scores = cm_df[\"score\"].values\n",
|
| 763 |
+
" hausdorffs = cm_df[\"mean_hausdorff\"].values\n",
|
| 764 |
+
" b_fracs = cm_df[\"mean_boundary_frac\"].values\n",
|
| 765 |
+
" contig_runs = cm_df[\"mean_max_contig_boundary\"].values\n",
|
| 766 |
+
" run_pens = cm_df[\"run_penalty\"].values\n",
|
| 767 |
+
"\n",
|
| 768 |
+
" max_score = scores.max()\n",
|
| 769 |
+
" if max_score <= 0:\n",
|
| 770 |
+
" weights_tuned[cm] = 1.0\n",
|
| 771 |
+
" tuning_details[cm] = {\"max_score\": 0, \"chosen_idx\": 0}\n",
|
| 772 |
+
" continue\n",
|
| 773 |
+
"\n",
|
| 774 |
+
" # Among weights achieving >= SCORE_THRESHOLD of max, pick smallest\n",
|
| 775 |
+
" candidates = np.where(scores >= SCORE_THRESHOLD * max_score)[0]\n",
|
| 776 |
+
" idx = int(candidates[0]) if len(candidates) > 0 else int(np.argmax(scores))\n",
|
| 777 |
+
"\n",
|
| 778 |
+
" weights_tuned[cm] = float(w_arr[idx])\n",
|
| 779 |
+
" tuning_details[cm] = {\n",
|
| 780 |
+
" \"max_score\": float(max_score),\n",
|
| 781 |
+
" \"chosen_score\": float(scores[idx]),\n",
|
| 782 |
+
" \"chosen_hausdorff\": float(hausdorffs[idx]),\n",
|
| 783 |
+
" \"chosen_boundary_frac\": float(b_fracs[idx]),\n",
|
| 784 |
+
" \"chosen_max_contig_run\": float(contig_runs[idx]),\n",
|
| 785 |
+
" \"chosen_run_penalty\": float(run_pens[idx]),\n",
|
| 786 |
+
" \"n_candidates\": len(candidates),\n",
|
| 787 |
+
" }\n",
|
| 788 |
+
"\n",
|
| 789 |
+
"print(\"Tuned weights (Hausdorff + boundary + contig-run penalty + asymptote minimization):\")\n",
|
| 790 |
+
"for cm, w in sorted(weights_tuned.items()):\n",
|
| 791 |
+
" d = tuning_details[cm]\n",
|
| 792 |
+
" print(\n",
|
| 793 |
+
" f\" {cm:25s} -> w={w:12.1f} \"\n",
|
| 794 |
+
" f\"(score={d.get('chosen_score', 0):.4f}, \"\n",
|
| 795 |
+
" f\"H={d.get('chosen_hausdorff', 0):.2f}, \"\n",
|
| 796 |
+
" f\"B={d.get('chosen_boundary_frac', 0):.4f}, \"\n",
|
| 797 |
+
" f\"C={d.get('chosen_max_contig_run', 0):.4f}, \"\n",
|
| 798 |
+
" f\"P_run={d.get('chosen_run_penalty', 1):.3f})\"\n",
|
| 799 |
+
" )"
|
| 800 |
+
]
|
| 801 |
+
},
|
| 802 |
+
{
|
| 803 |
+
"cell_type": "code",
|
| 804 |
+
"execution_count": null,
|
| 805 |
+
"id": "377f2718",
|
| 806 |
+
"metadata": {},
|
| 807 |
+
"outputs": [],
|
| 808 |
+
"source": [
|
| 809 |
+
"# 4-panel per-cost-model: Hausdorff | Boundary | Contig Run Penalty | Combined score\n",
|
| 810 |
+
"fig, axes = plt.subplots(n_cm, 4, figsize=(24, 5 * n_cm), squeeze=False)\n",
|
| 811 |
+
"fig.suptitle(\n",
|
| 812 |
+
" f\"Weight Tuning (score threshold = {SCORE_THRESHOLD:.0%}, max contig run = {MAX_BOUNDARY_RUN_FRAC:.0%})\",\n",
|
| 813 |
+
" fontsize=14,\n",
|
| 814 |
+
" y=1.01,\n",
|
| 815 |
+
")\n",
|
| 816 |
+
"\n",
|
| 817 |
+
"for row, cm in enumerate(COST_MODELS_TUNABLE):\n",
|
| 818 |
+
" cm_df = tune_df[tune_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 819 |
+
" ws = cm_df[\"weight\"].values\n",
|
| 820 |
+
" hs = cm_df[\"mean_hausdorff\"].values\n",
|
| 821 |
+
" bs = cm_df[\"mean_boundary_frac\"].values\n",
|
| 822 |
+
" cs = cm_df[\"mean_max_contig_boundary\"].values\n",
|
| 823 |
+
" rps = cm_df[\"run_penalty\"].values\n",
|
| 824 |
+
" ss = cm_df[\"score\"].values\n",
|
| 825 |
+
" w_opt = weights_tuned[cm]\n",
|
| 826 |
+
"\n",
|
| 827 |
+
" # Col 0: Hausdorff\n",
|
| 828 |
+
" ax = axes[row, 0]\n",
|
| 829 |
+
" ax.plot(ws, hs, \"o-\", lw=1.5, color=\"tab:blue\")\n",
|
| 830 |
+
" ax.axvline(w_opt, color=\"red\", ls=\"--\", lw=1, label=f\"w*={w_opt:.0f}\")\n",
|
| 831 |
+
" ax.set_xscale(\"log\")\n",
|
| 832 |
+
" ax.set_ylabel(\"Mean Hausdorff (px)\")\n",
|
| 833 |
+
" ax.set_title(f\"{cm} — Hausdorff\")\n",
|
| 834 |
+
" ax.legend(fontsize=8)\n",
|
| 835 |
+
" ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 836 |
+
"\n",
|
| 837 |
+
" # Col 1: Boundary fraction\n",
|
| 838 |
+
" ax = axes[row, 1]\n",
|
| 839 |
+
" ax.plot(ws, bs, \"s-\", lw=1.5, color=\"tab:orange\")\n",
|
| 840 |
+
" ax.axvline(w_opt, color=\"red\", ls=\"--\", lw=1, label=f\"w*={w_opt:.0f}\")\n",
|
| 841 |
+
" ax.set_xscale(\"log\")\n",
|
| 842 |
+
" ax.set_ylabel(\"Mean boundary fraction\")\n",
|
| 843 |
+
" ax.set_title(f\"{cm} — Boundary frac\")\n",
|
| 844 |
+
" ax.legend(fontsize=8)\n",
|
| 845 |
+
" ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 846 |
+
"\n",
|
| 847 |
+
" # Col 2: Contiguous run & penalty\n",
|
| 848 |
+
" ax = axes[row, 2]\n",
|
| 849 |
+
" ax.plot(ws, cs, \"^-\", lw=1.5, color=\"tab:purple\", label=\"Mean max contig run\")\n",
|
| 850 |
+
" ax.axhline(MAX_BOUNDARY_RUN_FRAC, color=\"gray\", ls=\":\", lw=1, label=f\"θ={MAX_BOUNDARY_RUN_FRAC:.0%}\")\n",
|
| 851 |
+
" ax.axhline(\n",
|
| 852 |
+
" 2 * MAX_BOUNDARY_RUN_FRAC, color=\"gray\", ls=\"--\", lw=1, alpha=0.5, label=f\"2θ={2 * MAX_BOUNDARY_RUN_FRAC:.0%}\"\n",
|
| 853 |
+
" )\n",
|
| 854 |
+
" ax2 = ax.twinx()\n",
|
| 855 |
+
" ax2.plot(ws, rps, \"v-\", lw=1, color=\"tab:red\", alpha=0.6, label=\"P_run\")\n",
|
| 856 |
+
" ax2.set_ylabel(\"Run penalty P_run\", color=\"tab:red\", fontsize=8)\n",
|
| 857 |
+
" ax2.set_ylim(-0.05, 1.15)\n",
|
| 858 |
+
" ax.axvline(w_opt, color=\"red\", ls=\"--\", lw=1, label=f\"w*={w_opt:.0f}\")\n",
|
| 859 |
+
" ax.set_xscale(\"log\")\n",
|
| 860 |
+
" ax.set_ylabel(\"Max contiguous boundary frac\")\n",
|
| 861 |
+
" ax.set_title(f\"{cm} — Contig Run\")\n",
|
| 862 |
+
" # Merge legends from both axes\n",
|
| 863 |
+
" h1, l1 = ax.get_legend_handles_labels()\n",
|
| 864 |
+
" h2, l2 = ax2.get_legend_handles_labels()\n",
|
| 865 |
+
" ax.legend(h1 + h2, l1 + l2, fontsize=7, loc=\"upper left\")\n",
|
| 866 |
+
" ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 867 |
+
"\n",
|
| 868 |
+
" # Col 3: Combined score\n",
|
| 869 |
+
" ax = axes[row, 3]\n",
|
| 870 |
+
" ax.plot(ws, ss, \"D-\", lw=1.5, color=\"tab:green\")\n",
|
| 871 |
+
" max_s = ss.max()\n",
|
| 872 |
+
" ax.axhline(SCORE_THRESHOLD * max_s, color=\"purple\", ls=\":\", lw=1, label=f\"{SCORE_THRESHOLD:.0%} threshold\")\n",
|
| 873 |
+
" ax.axvline(w_opt, color=\"red\", ls=\"--\", lw=1, label=f\"w*={w_opt:.0f}\")\n",
|
| 874 |
+
" opt_idx = int(np.searchsorted(ws, w_opt))\n",
|
| 875 |
+
" ax.scatter([w_opt], [ss[min(opt_idx, len(ss) - 1)]], color=\"red\", s=60, zorder=10)\n",
|
| 876 |
+
" ax.set_xscale(\"log\")\n",
|
| 877 |
+
" ax.set_ylabel(\"Score = Ĥ·(1-B)·P_run\")\n",
|
| 878 |
+
" ax.set_title(f\"{cm} — Score\")\n",
|
| 879 |
+
" ax.legend(fontsize=8)\n",
|
| 880 |
+
" ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 881 |
+
"\n",
|
| 882 |
+
" if row == n_cm - 1:\n",
|
| 883 |
+
" for c in range(4):\n",
|
| 884 |
+
" axes[row, c].set_xlabel(\"Weight\")\n",
|
| 885 |
+
"\n",
|
| 886 |
+
"plt.tight_layout()\n",
|
| 887 |
+
"plt.show()"
|
| 888 |
+
]
|
| 889 |
+
},
|
| 890 |
+
{
|
| 891 |
+
"cell_type": "code",
|
| 892 |
+
"execution_count": null,
|
| 893 |
+
"id": "f7edfec9",
|
| 894 |
+
"metadata": {},
|
| 895 |
+
"outputs": [],
|
| 896 |
+
"source": [
|
| 897 |
+
"# All cost models overlaid: combined score vs weight\n",
|
| 898 |
+
"fig, ax = plt.subplots(figsize=(12, 6))\n",
|
| 899 |
+
"\n",
|
| 900 |
+
"for cm in COST_MODELS_TUNABLE:\n",
|
| 901 |
+
" cm_df = tune_df[tune_df[\"cost_model\"] == cm].sort_values(\"weight\")\n",
|
| 902 |
+
" ax.plot(\n",
|
| 903 |
+
" cm_df[\"weight\"],\n",
|
| 904 |
+
" cm_df[\"score\"],\n",
|
| 905 |
+
" \"o-\",\n",
|
| 906 |
+
" lw=1.5,\n",
|
| 907 |
+
" markersize=4,\n",
|
| 908 |
+
" label=cm,\n",
|
| 909 |
+
" color=CM_COLORS[cm],\n",
|
| 910 |
+
" )\n",
|
| 911 |
+
" # Mark chosen weight\n",
|
| 912 |
+
" w_opt = weights_tuned[cm]\n",
|
| 913 |
+
" opt_row = cm_df.iloc[(cm_df[\"weight\"] - w_opt).abs().argsort().iloc[0]]\n",
|
| 914 |
+
" ax.scatter([w_opt], [opt_row[\"score\"]], color=\"red\", s=60, zorder=10, edgecolors=\"black\", linewidths=0.5)\n",
|
| 915 |
+
" ax.annotate(\n",
|
| 916 |
+
" f\"{w_opt:.0f}\",\n",
|
| 917 |
+
" xy=(w_opt, opt_row[\"score\"]),\n",
|
| 918 |
+
" xytext=(6, 6),\n",
|
| 919 |
+
" textcoords=\"offset points\",\n",
|
| 920 |
+
" fontsize=8,\n",
|
| 921 |
+
" color=\"red\",\n",
|
| 922 |
+
" )\n",
|
| 923 |
+
"\n",
|
| 924 |
+
"ax.set_xscale(\"log\")\n",
|
| 925 |
+
"ax.set_xlabel(\"Weight\")\n",
|
| 926 |
+
"ax.set_ylabel(\"Combined score\")\n",
|
| 927 |
+
"ax.set_title(\"Combined Score vs Weight (all tunable cost models)\")\n",
|
| 928 |
+
"ax.legend(fontsize=9)\n",
|
| 929 |
+
"ax.grid(True, ls=\":\", alpha=0.5)\n",
|
| 930 |
+
"plt.tight_layout()\n",
|
| 931 |
+
"plt.show()"
|
| 932 |
+
]
|
| 933 |
+
},
|
| 934 |
+
{
|
| 935 |
+
"cell_type": "markdown",
|
| 936 |
+
"id": "a607f0fd",
|
| 937 |
+
"metadata": {},
|
| 938 |
+
"source": [
|
| 939 |
+
"### Analysis: Weight Tuning Results\n",
|
| 940 |
+
"\n",
|
| 941 |
+
"**4-panel per-model view (Hausdorff | Boundary | Contig Run | Score):**\n",
|
| 942 |
+
"Each row shows the four signals for one cost model. The red dashed line marks the selected weight $w^*$:\n",
|
| 943 |
+
"\n",
|
| 944 |
+
"- **Column 1 — Hausdorff:** Path diversity from the distance baseline (higher = more diverse).\n",
|
| 945 |
+
"- **Column 2 — Boundary fraction:** Overall fraction of path points near the edge.\n",
|
| 946 |
+
"- **Column 3 — Contiguous run penalty:** The purple curve shows the mean longest contiguous boundary run as a fraction of path length. The gray dotted/dashed lines mark the $\\theta$ (3%) and $2\\theta$ (6%) thresholds. The red overlay shows the resulting penalty $P_{\\text{run}}$: it equals 1.0 below $\\theta$, ramps linearly to 0.0 at $2\\theta$, and stays at 0.0 beyond. This penalizes weights where paths run along edges for extended stretches, especially affecting the `elevation` cost model.\n",
|
| 947 |
+
"- **Column 4 — Combined score:** The product $\\hat{H} \\cdot (1-B) \\cdot P_{\\text{run}}$.\n",
|
| 948 |
+
"\n",
|
| 949 |
+
"With $\\theta = 3\\%$, `elevation` now selects $w^* = 62.4$ — a compromise between the overly strict 1% threshold ($w^* = 11.9$) and the permissive 10% threshold ($w^* = 142.5$). At this weight, the elevation model achieves a Hausdorff distance of ~48 px with a contiguous run of ~2.6%, staying within the 3% bound. The score plateaus around 0.88, reflecting a good balance between path diversity and boundary control.\n",
|
| 950 |
+
"\n",
|
| 951 |
+
"> **Asymptote minimization principle:** Among all weights achieving $\\ge 95\\%$ of the peak score, we always pick the *smallest*. This avoids unnecessarily large weights that would waste computation on negligible improvements and risk overfitting the weight to specific terrain patterns."
|
| 952 |
+
]
|
| 953 |
+
},
|
| 954 |
+
{
|
| 955 |
+
"cell_type": "markdown",
|
| 956 |
+
"id": "43df6a25",
|
| 957 |
+
"metadata": {},
|
| 958 |
+
"source": [
|
| 959 |
+
"---\n",
|
| 960 |
+
"\n",
|
| 961 |
+
"## 6. Summary"
|
| 962 |
+
]
|
| 963 |
+
},
|
| 964 |
+
{
|
| 965 |
+
"cell_type": "code",
|
| 966 |
+
"execution_count": null,
|
| 967 |
+
"id": "aa498fb6",
|
| 968 |
+
"metadata": {},
|
| 969 |
+
"outputs": [],
|
| 970 |
+
"source": [
|
| 971 |
+
"# Summary table\n",
|
| 972 |
+
"summary_rows = []\n",
|
| 973 |
+
"for cm in sorted(weights_tuned.keys()):\n",
|
| 974 |
+
" d = tuning_details[cm]\n",
|
| 975 |
+
" summary_rows.append(\n",
|
| 976 |
+
" {\n",
|
| 977 |
+
" \"cost_model\": cm,\n",
|
| 978 |
+
" \"weight\": weights_tuned[cm],\n",
|
| 979 |
+
" \"score\": d.get(\"chosen_score\", 0),\n",
|
| 980 |
+
" \"hausdorff\": d.get(\"chosen_hausdorff\", 0),\n",
|
| 981 |
+
" \"boundary_frac\": d.get(\"chosen_boundary_frac\", 0),\n",
|
| 982 |
+
" \"max_contig_run\": d.get(\"chosen_max_contig_run\", 0),\n",
|
| 983 |
+
" \"run_penalty\": d.get(\"chosen_run_penalty\", 1),\n",
|
| 984 |
+
" }\n",
|
| 985 |
+
" )\n",
|
| 986 |
+
"\n",
|
| 987 |
+
"summary_table = pd.DataFrame(summary_rows).set_index(\"cost_model\")\n",
|
| 988 |
+
"display(summary_table)\n",
|
| 989 |
+
"\n",
|
| 990 |
+
"print(\"\\nFinal tuned weights:\")\n",
|
| 991 |
+
"for cm, w in sorted(weights_tuned.items()):\n",
|
| 992 |
+
" print(f\" {cm}: {w:.1f}\")"
|
| 993 |
+
]
|
| 994 |
+
},
|
| 995 |
+
{
|
| 996 |
+
"cell_type": "markdown",
|
| 997 |
+
"id": "114dbff8",
|
| 998 |
+
"metadata": {},
|
| 999 |
+
"source": [
|
| 1000 |
+
"### Summary Interpretation\n",
|
| 1001 |
+
"\n",
|
| 1002 |
+
"The summary table shows the final tuned weights with both boundary metrics:\n",
|
| 1003 |
+
"\n",
|
| 1004 |
+
"- **`boundary_frac`**: overall fraction of path points near edges (global average)\n",
|
| 1005 |
+
"- **`max_contig_run`**: longest contiguous boundary segment as fraction of total path\n",
|
| 1006 |
+
"- **`run_penalty`**: the multiplicative penalty applied from the contiguous-run constraint ($P_{\\text{run}}$)\n",
|
| 1007 |
+
"\n",
|
| 1008 |
+
"With $\\theta = 3\\%$, all tuned weights produce paths with contiguous runs below the threshold ($P_{\\text{run}} = 1.0$ for all). The `elevation` model selects $w^* = 62.4$ with a contiguous run of 2.6% — just under the 3% limit — while achieving a Hausdorff distance of ~48 px. The other three models remain unaffected since their contiguous runs are well below 1%.\n",
|
| 1009 |
+
"\n",
|
| 1010 |
+
"> **Practical implication:** These tuned weights can be used directly in `passage generate` to produce a balanced dataset of shortest-path annotations. Each cost model at its tuned weight creates meaningfully different paths from the distance baseline while keeping boundary artifacts — both overall and contiguous — under control."
|
| 1011 |
+
]
|
| 1012 |
+
},
|
| 1013 |
+
{
|
| 1014 |
+
"cell_type": "markdown",
|
| 1015 |
+
"id": "305f41f7",
|
| 1016 |
+
"metadata": {},
|
| 1017 |
+
"source": [
|
| 1018 |
+
"---\n",
|
| 1019 |
+
"\n",
|
| 1020 |
+
"## 7. Final Visualization with Tuned Weights\n",
|
| 1021 |
+
"\n",
|
| 1022 |
+
"Show paths from all non-distance cost models at their tuned weight,\n",
|
| 1023 |
+
"side by side on fresh samples."
|
| 1024 |
+
]
|
| 1025 |
+
},
|
| 1026 |
+
{
|
| 1027 |
+
"cell_type": "code",
|
| 1028 |
+
"execution_count": null,
|
| 1029 |
+
"id": "d93cd7b2",
|
| 1030 |
+
"metadata": {},
|
| 1031 |
+
"outputs": [],
|
| 1032 |
+
"source": [
|
| 1033 |
+
"# Generate display samples with tuned weights\n",
|
| 1034 |
+
"t0 = time.time()\n",
|
| 1035 |
+
"ctx = mp.get_context(\"fork\")\n",
|
| 1036 |
+
"with ctx.Pool(NUM_WORKERS) as pool:\n",
|
| 1037 |
+
" results = list(\n",
|
| 1038 |
+
" tqdm(\n",
|
| 1039 |
+
" pool.imap_unordered(_process_one_display_sample, range(NUM_DISPLAY_SAMPLES)),\n",
|
| 1040 |
+
" total=NUM_DISPLAY_SAMPLES,\n",
|
| 1041 |
+
" desc=f\"Display samples ({NUM_WORKERS} workers)\",\n",
|
| 1042 |
+
" )\n",
|
| 1043 |
+
" )\n",
|
| 1044 |
+
"\n",
|
| 1045 |
+
"display_samples = sorted([r for r in results if r is not None], key=lambda s: s[\"index\"])\n",
|
| 1046 |
+
"\n",
|
| 1047 |
+
"elapsed = time.time() - t0\n",
|
| 1048 |
+
"print(f\"Display samples: {len(display_samples)} in {elapsed:.1f}s ({NUM_WORKERS} workers)\")"
|
| 1049 |
+
]
|
| 1050 |
+
},
|
| 1051 |
+
{
|
| 1052 |
+
"cell_type": "code",
|
| 1053 |
+
"execution_count": null,
|
| 1054 |
+
"id": "feccd12f",
|
| 1055 |
+
"metadata": {},
|
| 1056 |
+
"outputs": [],
|
| 1057 |
+
"source": [
|
| 1058 |
+
"# Visualize each display sample\n",
|
| 1059 |
+
"display_cms = sorted(weights_tuned.keys())\n",
|
| 1060 |
+
"n_cols = len(display_cms)\n",
|
| 1061 |
+
"\n",
|
| 1062 |
+
"legend_handles = [\n",
|
| 1063 |
+
" Line2D([0], [0], color=\"red\", lw=2, label=\"Tuned path\"),\n",
|
| 1064 |
+
" Line2D([0], [0], color=\"gray\", lw=1, ls=\"--\", label=\"Distance baseline\"),\n",
|
| 1065 |
+
" Line2D([0], [0], marker=\"o\", color=\"w\", markerfacecolor=\"lime\", markersize=6, label=\"Start\"),\n",
|
| 1066 |
+
" Line2D([0], [0], marker=\"x\", color=\"cyan\", markersize=6, label=\"End\"),\n",
|
| 1067 |
+
"]\n",
|
| 1068 |
+
"\n",
|
| 1069 |
+
"for sample in display_samples:\n",
|
| 1070 |
+
" crop = sample[\"crop\"]\n",
|
| 1071 |
+
" start = sample[\"start\"]\n",
|
| 1072 |
+
" end = sample[\"end\"]\n",
|
| 1073 |
+
" paths = sample[\"paths\"]\n",
|
| 1074 |
+
" elev_min, elev_max = float(np.min(crop)), float(np.max(crop))\n",
|
| 1075 |
+
"\n",
|
| 1076 |
+
" fig, axes = plt.subplots(1, n_cols, figsize=(5 * n_cols, 5))\n",
|
| 1077 |
+
" if n_cols == 1:\n",
|
| 1078 |
+
" axes = [axes]\n",
|
| 1079 |
+
"\n",
|
| 1080 |
+
" for col, cm in enumerate(display_cms):\n",
|
| 1081 |
+
" ax = axes[col]\n",
|
| 1082 |
+
" ax.imshow(crop, cmap=\"terrain\", vmin=elev_min, vmax=elev_max, origin=\"upper\")\n",
|
| 1083 |
+
"\n",
|
| 1084 |
+
" # Distance baseline in gray\n",
|
| 1085 |
+
" dp = paths.get(\"distance\", [])\n",
|
| 1086 |
+
" if len(dp) > 0:\n",
|
| 1087 |
+
" pa = np.array(dp)\n",
|
| 1088 |
+
" ax.plot(pa[:, 1], pa[:, 0], color=\"gray\", lw=1, ls=\"--\", alpha=0.6)\n",
|
| 1089 |
+
"\n",
|
| 1090 |
+
" # Tuned path in red\n",
|
| 1091 |
+
" path = paths[cm]\n",
|
| 1092 |
+
" if len(path) > 0:\n",
|
| 1093 |
+
" pa = np.array(path)\n",
|
| 1094 |
+
" ax.plot(pa[:, 1], pa[:, 0], color=\"red\", lw=2)\n",
|
| 1095 |
+
"\n",
|
| 1096 |
+
" ax.plot(start[1], start[0], \"o\", color=\"lime\", markersize=6)\n",
|
| 1097 |
+
" ax.plot(end[1], end[0], \"x\", color=\"cyan\", markersize=6)\n",
|
| 1098 |
+
" w = weights_tuned[cm]\n",
|
| 1099 |
+
" ax.set_title(f\"{cm} (w={w:.0f})\", fontsize=10)\n",
|
| 1100 |
+
" ax.axis(\"off\")\n",
|
| 1101 |
+
"\n",
|
| 1102 |
+
" fig.legend(handles=legend_handles, loc=\"upper right\", fontsize=8)\n",
|
| 1103 |
+
" fig.suptitle(f\"Sample {sample['index']} | elev=[{elev_min:.0f}, {elev_max:.0f}]\", fontsize=12)\n",
|
| 1104 |
+
" plt.tight_layout()\n",
|
| 1105 |
+
" plt.show()"
|
| 1106 |
+
]
|
| 1107 |
+
},
|
| 1108 |
+
{
|
| 1109 |
+
"cell_type": "code",
|
| 1110 |
+
"execution_count": null,
|
| 1111 |
+
"id": "5d9ef267",
|
| 1112 |
+
"metadata": {},
|
| 1113 |
+
"outputs": [],
|
| 1114 |
+
"source": [
|
| 1115 |
+
"# All tuned paths overlaid on a single elevation map per sample\n",
|
| 1116 |
+
"for sample in display_samples:\n",
|
| 1117 |
+
" crop = sample[\"crop\"]\n",
|
| 1118 |
+
" start = sample[\"start\"]\n",
|
| 1119 |
+
" end = sample[\"end\"]\n",
|
| 1120 |
+
" paths = sample[\"paths\"]\n",
|
| 1121 |
+
" elev_min, elev_max = float(np.min(crop)), float(np.max(crop))\n",
|
| 1122 |
+
"\n",
|
| 1123 |
+
" fig, ax = plt.subplots(figsize=(7, 7))\n",
|
| 1124 |
+
" ax.imshow(crop, cmap=\"terrain\", vmin=elev_min, vmax=elev_max, origin=\"upper\")\n",
|
| 1125 |
+
"\n",
|
| 1126 |
+
" for cm in display_cms:\n",
|
| 1127 |
+
" path = paths[cm]\n",
|
| 1128 |
+
" if len(path) > 0:\n",
|
| 1129 |
+
" pa = np.array(path)\n",
|
| 1130 |
+
" ax.plot(pa[:, 1], pa[:, 0], lw=2, label=f\"{cm} (w={weights_tuned[cm]:.0f})\", color=CM_COLORS[cm])\n",
|
| 1131 |
+
"\n",
|
| 1132 |
+
" # Distance baseline\n",
|
| 1133 |
+
" dp = paths.get(\"distance\", [])\n",
|
| 1134 |
+
" if len(dp) > 0:\n",
|
| 1135 |
+
" pa = np.array(dp)\n",
|
| 1136 |
+
" ax.plot(pa[:, 1], pa[:, 0], color=\"gray\", lw=1.5, ls=\"--\", label=\"distance\", alpha=0.7)\n",
|
| 1137 |
+
"\n",
|
| 1138 |
+
" ax.plot(start[1], start[0], \"o\", color=\"lime\", markersize=8, zorder=10)\n",
|
| 1139 |
+
" ax.plot(end[1], end[0], \"x\", color=\"cyan\", markersize=8, zorder=10)\n",
|
| 1140 |
+
" ax.legend(fontsize=8, loc=\"lower left\")\n",
|
| 1141 |
+
" ax.set_title(f\"Sample {sample['index']} | elev=[{elev_min:.0f}, {elev_max:.0f}]\", fontsize=11)\n",
|
| 1142 |
+
" ax.axis(\"off\")\n",
|
| 1143 |
+
" plt.tight_layout()\n",
|
| 1144 |
+
" plt.show()"
|
| 1145 |
+
]
|
| 1146 |
+
},
|
| 1147 |
+
{
|
| 1148 |
+
"cell_type": "markdown",
|
| 1149 |
+
"id": "5ac43856",
|
| 1150 |
+
"metadata": {},
|
| 1151 |
+
"source": [
|
| 1152 |
+
"### Analysis: Visual Validation of Tuned Weights\n",
|
| 1153 |
+
"\n",
|
| 1154 |
+
"**Side-by-side view** (one subplot per cost model): Each panel shows the tuned path (red) against the distance baseline (gray dashed). Key observations:\n",
|
| 1155 |
+
"\n",
|
| 1156 |
+
"- **`absolute_elevation`:** Paths are nearly identical to the distance baseline in most samples, consistent with its low Hausdorff distance (~5 px). This model is only useful for subtle variation.\n",
|
| 1157 |
+
"- **`elevation`:** Produces the most visually distinct paths — long detours that follow contour lines, avoiding steep gradients. In some samples (e.g., mountainous terrain), the path may traverse the entire crop perimeter to stay on gentle slopes.\n",
|
| 1158 |
+
"- **`energy`** and **`slope_uphill`:** Intermediate behavior — paths visibly avoid steep terrain but remain more direct than `elevation`. The difference between these two models is subtle and depends on whether the terrain has symmetric or asymmetric slopes.\n",
|
| 1159 |
+
"\n",
|
| 1160 |
+
"**Overlay view** (all models on one map): When multiple cost models are superimposed on the same elevation map, we can directly compare their routing strategies:\n",
|
| 1161 |
+
"- On flat terrain (e.g., Sample 7 with elev=[0, 0]), all models produce identical straight-line paths — correct behavior since there is no terrain to avoid.\n",
|
| 1162 |
+
"- On rugged terrain, the paths fan out, with `elevation` taking the widest detour and `absolute_elevation` staying closest to the diagonal.\n",
|
| 1163 |
+
"- Samples near coastlines or tile edges (with zero-elevation ocean pixels) expose boundary-hugging behavior that our tuning procedure successfully mitigates — at the tuned weights, paths may approach but do not systematically follow the boundary.\n",
|
| 1164 |
+
"\n",
|
| 1165 |
+
"> **Validation:** The visual results confirm that the automated weight selection produces qualitatively sensible paths across diverse terrain conditions, and that none of the tuned weights lead to degenerate boundary-following behavior."
|
| 1166 |
+
]
|
| 1167 |
+
},
|
| 1168 |
+
{
|
| 1169 |
+
"cell_type": "code",
|
| 1170 |
+
"execution_count": null,
|
| 1171 |
+
"id": "d2dc54b2",
|
| 1172 |
+
"metadata": {},
|
| 1173 |
+
"outputs": [],
|
| 1174 |
+
"source": [
|
| 1175 |
+
"weights_tuned"
|
| 1176 |
+
]
|
| 1177 |
+
}
|
| 1178 |
+
],
|
| 1179 |
+
"metadata": {
|
| 1180 |
+
"kernelspec": {
|
| 1181 |
+
"display_name": "passage",
|
| 1182 |
+
"language": "python",
|
| 1183 |
+
"name": "python3"
|
| 1184 |
+
},
|
| 1185 |
+
"language_info": {
|
| 1186 |
+
"codemirror_mode": {
|
| 1187 |
+
"name": "ipython",
|
| 1188 |
+
"version": 3
|
| 1189 |
+
},
|
| 1190 |
+
"file_extension": ".py",
|
| 1191 |
+
"mimetype": "text/x-python",
|
| 1192 |
+
"name": "python",
|
| 1193 |
+
"nbconvert_exporter": "python",
|
| 1194 |
+
"pygments_lexer": "ipython3",
|
| 1195 |
+
"version": "3.12.4"
|
| 1196 |
+
}
|
| 1197 |
+
},
|
| 1198 |
+
"nbformat": 4,
|
| 1199 |
+
"nbformat_minor": 5
|
| 1200 |
+
}
|
notebooks/demo.ipynb
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "64bb19d9",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"MIT License\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"Copyright (c) 2026 THALES\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Permission is hereby granted, free of charge, to any person obtaining a copy\n",
|
| 13 |
+
"of this software and associated documentation files (the \"Software\"), to deal\n",
|
| 14 |
+
"in the Software without restriction, including without limitation the rights\n",
|
| 15 |
+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n",
|
| 16 |
+
"copies of the Software, and to permit persons to whom the Software is\n",
|
| 17 |
+
"furnished to do so, subject to the following conditions:\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"The above copyright notice and this permission notice shall be included in all\n",
|
| 20 |
+
"copies or substantial portions of the Software.\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n",
|
| 23 |
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n",
|
| 24 |
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n",
|
| 25 |
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n",
|
| 26 |
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n",
|
| 27 |
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n",
|
| 28 |
+
"SOFTWARE."
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "markdown",
|
| 33 |
+
"id": "f5d8c6d7",
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"source": [
|
| 36 |
+
"# Demo: load and visualize dataset by resolution & split\n",
|
| 37 |
+
"This notebook demonstrates how to load a single sample from the generated dataset for a specific resolution and split, and visualize the full image and the three tensor layers:\n",
|
| 38 |
+
"\n",
|
| 39 |
+
"- Elevation (normalized float32) ✅\n",
|
| 40 |
+
"- Start / End markers (marker channel: -1 background, 0=start, 1=end) ✅\n",
|
| 41 |
+
"- Obstacles mask (binary) ✅"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"cell_type": "code",
|
| 46 |
+
"execution_count": null,
|
| 47 |
+
"id": "cd4ec8b2",
|
| 48 |
+
"metadata": {},
|
| 49 |
+
"outputs": [],
|
| 50 |
+
"source": [
|
| 51 |
+
"import datasets\n",
|
| 52 |
+
"import numpy as np\n",
|
| 53 |
+
"import matplotlib.pyplot as plt\n",
|
| 54 |
+
"from pathlib import Path\n",
|
| 55 |
+
"from passage.visualization import tensor_to_image\n",
|
| 56 |
+
"from passage.utils import decode_tensor_blob"
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"cell_type": "code",
|
| 61 |
+
"execution_count": null,
|
| 62 |
+
"id": "9a51c7c0",
|
| 63 |
+
"metadata": {
|
| 64 |
+
"tags": [
|
| 65 |
+
"parameters"
|
| 66 |
+
]
|
| 67 |
+
},
|
| 68 |
+
"outputs": [],
|
| 69 |
+
"source": [
|
| 70 |
+
"# Configuration: update these paths if needed\n",
|
| 71 |
+
"RESOLUTION = 256\n",
|
| 72 |
+
"SPLIT = \"train\" # train / validation / test / calibration\n",
|
| 73 |
+
"\n",
|
| 74 |
+
"# Load solver names from config\n",
|
| 75 |
+
"ROOT = Path.cwd().parent if Path.cwd().name == \"notebooks\" else Path.cwd()"
|
| 76 |
+
]
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
"cell_type": "code",
|
| 80 |
+
"execution_count": null,
|
| 81 |
+
"id": "4fd1c106",
|
| 82 |
+
"metadata": {},
|
| 83 |
+
"outputs": [],
|
| 84 |
+
"source": [
|
| 85 |
+
"print(f\"Resolution: {RESOLUTION}, Split: {SPLIT}\")"
|
| 86 |
+
]
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"cell_type": "code",
|
| 90 |
+
"execution_count": null,
|
| 91 |
+
"id": "a72ad7c1",
|
| 92 |
+
"metadata": {},
|
| 93 |
+
"outputs": [],
|
| 94 |
+
"source": [
|
| 95 |
+
"ds = datasets.load_dataset(\n",
|
| 96 |
+
" \"thalesgroup/passage\",\n",
|
| 97 |
+
" name=f\"{RESOLUTION}x{RESOLUTION}\",\n",
|
| 98 |
+
")"
|
| 99 |
+
]
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"cell_type": "code",
|
| 103 |
+
"execution_count": null,
|
| 104 |
+
"id": "60732416",
|
| 105 |
+
"metadata": {},
|
| 106 |
+
"outputs": [],
|
| 107 |
+
"source": [
|
| 108 |
+
"sample = ds[SPLIT][np.random.randint(len(ds[SPLIT]))]\n",
|
| 109 |
+
"sample.keys()"
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"cell_type": "code",
|
| 114 |
+
"execution_count": null,
|
| 115 |
+
"id": "af722980",
|
| 116 |
+
"metadata": {},
|
| 117 |
+
"outputs": [],
|
| 118 |
+
"source": [
|
| 119 |
+
"if \"image\" in sample.keys():\n",
|
| 120 |
+
" plt.imshow(sample[\"image\"])\n",
|
| 121 |
+
" plt.axis(\"off\")\n",
|
| 122 |
+
" plt.tight_layout()"
|
| 123 |
+
]
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"cell_type": "code",
|
| 127 |
+
"execution_count": null,
|
| 128 |
+
"id": "6b70dee9",
|
| 129 |
+
"metadata": {},
|
| 130 |
+
"outputs": [],
|
| 131 |
+
"source": [
|
| 132 |
+
"metadata = sample[\"metadata\"]\n",
|
| 133 |
+
"solvers = metadata[\"paths\"].keys()"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"cell_type": "code",
|
| 138 |
+
"execution_count": null,
|
| 139 |
+
"id": "9f0b5e1c",
|
| 140 |
+
"metadata": {},
|
| 141 |
+
"outputs": [],
|
| 142 |
+
"source": [
|
| 143 |
+
"# Load paths for all solvers\n",
|
| 144 |
+
"solver_paths = {}\n",
|
| 145 |
+
"for solver_name in solvers:\n",
|
| 146 |
+
" free_key = f\"path_{solver_name}_free\"\n",
|
| 147 |
+
" obs_key = f\"path_{solver_name}_obstacles\"\n",
|
| 148 |
+
" solver_paths[solver_name] = {\n",
|
| 149 |
+
" \"free\": sample.get(free_key, []),\n",
|
| 150 |
+
" \"obstacles\": sample.get(obs_key, []),\n",
|
| 151 |
+
" }\n",
|
| 152 |
+
" print(\n",
|
| 153 |
+
" f\"{solver_name}: free={len(solver_paths[solver_name]['free'])} pts, obstacles={len(solver_paths[solver_name]['obstacles'])} pts\"\n",
|
| 154 |
+
" )\n",
|
| 155 |
+
"\n",
|
| 156 |
+
"metadata = sample[\"metadata\"]\n",
|
| 157 |
+
"print(f\"\\nMetadata keys: {list(metadata.keys()) if isinstance(metadata, dict) else 'N/A'}\")"
|
| 158 |
+
]
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"cell_type": "markdown",
|
| 162 |
+
"id": "8bdad721",
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"source": [
|
| 165 |
+
"**NOTE**: Be careful, in order to optimize storage, tensors are saved in **compressed** format. They need to be uncompressed using `decode_tensor_blob` function!"
|
| 166 |
+
]
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"cell_type": "code",
|
| 170 |
+
"execution_count": null,
|
| 171 |
+
"id": "4fef0c42",
|
| 172 |
+
"metadata": {},
|
| 173 |
+
"outputs": [],
|
| 174 |
+
"source": [
|
| 175 |
+
"tensor = decode_tensor_blob(sample[\"tensor\"], (RESOLUTION, RESOLUTION, 3))\n",
|
| 176 |
+
"print(\"tensor.shape:\", tensor.shape, \"dtype:\", tensor.dtype)\n",
|
| 177 |
+
"\n",
|
| 178 |
+
"elevation = (\n",
|
| 179 |
+
" tensor[:, :, 0] * (metadata[\"calibration\"][\"max\"] - metadata[\"calibration\"][\"min\"]) + metadata[\"calibration\"][\"min\"]\n",
|
| 180 |
+
")\n",
|
| 181 |
+
"marker = tensor[:, :, 1]\n",
|
| 182 |
+
"obstacles = tensor[:, :, 2]\n",
|
| 183 |
+
"\n",
|
| 184 |
+
"print(\"Elevation min/max:\", float(elevation.min()), float(elevation.max()))\n",
|
| 185 |
+
"print(\"Marker unique values:\", np.unique(marker)[:10])\n",
|
| 186 |
+
"print(\"Obstacles unique values:\", np.unique(obstacles)[:10])"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"cell_type": "code",
|
| 191 |
+
"execution_count": null,
|
| 192 |
+
"id": "a81ada6e",
|
| 193 |
+
"metadata": {},
|
| 194 |
+
"outputs": [],
|
| 195 |
+
"source": [
|
| 196 |
+
"img_bgr = tensor_to_image(tensor)\n",
|
| 197 |
+
"img_rgb = img_bgr[:, :, ::-1]"
|
| 198 |
+
]
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
"cell_type": "code",
|
| 202 |
+
"execution_count": null,
|
| 203 |
+
"id": "2c9eaa83",
|
| 204 |
+
"metadata": {},
|
| 205 |
+
"outputs": [],
|
| 206 |
+
"source": [
|
| 207 |
+
"# Visualize each channel and paths for all solvers\n",
|
| 208 |
+
"n_solvers = len(solvers)\n",
|
| 209 |
+
"n_base_plots = 3 # Elevation, Obstacles, Markers\n",
|
| 210 |
+
"n_path_plots = n_solvers * 2 # free + obstacles for each solver\n",
|
| 211 |
+
"n_plots = n_base_plots + n_path_plots\n",
|
| 212 |
+
"\n",
|
| 213 |
+
"fig, axes = plt.subplots(1, len(solvers), figsize=(15, 15 * len(solvers)))\n",
|
| 214 |
+
"\n",
|
| 215 |
+
"for i, solver_name in enumerate(solvers):\n",
|
| 216 |
+
" ax = axes[i]\n",
|
| 217 |
+
" img_bgr = tensor_to_image(tensor, solver_paths[solver_name][\"free\"], solver_paths[solver_name][\"obstacles\"])\n",
|
| 218 |
+
" img_rgb = img_bgr[:, :, ::-1]\n",
|
| 219 |
+
" ax.imshow(img_rgb)\n",
|
| 220 |
+
" ax.set_title(f\"Paths from {solver_name}\")\n",
|
| 221 |
+
" ax.axis(\"off\")\n",
|
| 222 |
+
"\n",
|
| 223 |
+
"fig.show()\n",
|
| 224 |
+
"\n",
|
| 225 |
+
"fig, axes = plt.subplots(n_plots, figsize=(10, 10 * n_plots))\n",
|
| 226 |
+
"if n_plots == 1:\n",
|
| 227 |
+
" axes = [axes]\n",
|
| 228 |
+
"\n",
|
| 229 |
+
"# 2. Elevation\n",
|
| 230 |
+
"ax = axes[0]\n",
|
| 231 |
+
"im = ax.imshow(elevation, cmap=\"terrain\")\n",
|
| 232 |
+
"plt.colorbar(im, ax=ax)\n",
|
| 233 |
+
"ax.set_title(\"Elevation (normalized)\")\n",
|
| 234 |
+
"ax.axis(\"off\")\n",
|
| 235 |
+
"\n",
|
| 236 |
+
"# 3. Obstacles\n",
|
| 237 |
+
"ax = axes[1]\n",
|
| 238 |
+
"ax.imshow(obstacles, cmap=\"gray\")\n",
|
| 239 |
+
"ax.set_title(\"Obstacles (mask)\")\n",
|
| 240 |
+
"ax.axis(\"off\")\n",
|
| 241 |
+
"\n",
|
| 242 |
+
"# 4. Markers\n",
|
| 243 |
+
"ax = axes[2]\n",
|
| 244 |
+
"start_mask = marker == 0.0\n",
|
| 245 |
+
"end_mask = marker == 1.0\n",
|
| 246 |
+
"combined = np.zeros((marker.shape[0], marker.shape[1], 3), dtype=np.uint8)\n",
|
| 247 |
+
"combined[start_mask] = [0, 255, 255] # cyan for start\n",
|
| 248 |
+
"combined[end_mask] = [0, 0, 255] # blue for end\n",
|
| 249 |
+
"ax.imshow(combined)\n",
|
| 250 |
+
"ax.set_title(\"Markers — cyan=start, blue=end\")\n",
|
| 251 |
+
"ax.axis(\"off\")\n",
|
| 252 |
+
"\n",
|
| 253 |
+
"# 5+. Path visualizations per solver\n",
|
| 254 |
+
"colors_free = plt.cm.tab10.colors # Different colors for each solver\n",
|
| 255 |
+
"colors_obs = plt.cm.Set2.colors\n",
|
| 256 |
+
"ax_idx = 3\n",
|
| 257 |
+
"for solver_idx, solver_name in enumerate(solvers):\n",
|
| 258 |
+
" free_path = solver_paths[solver_name][\"free\"]\n",
|
| 259 |
+
" obs_path = solver_paths[solver_name][\"obstacles\"]\n",
|
| 260 |
+
"\n",
|
| 261 |
+
" # Free path\n",
|
| 262 |
+
" ax = axes[ax_idx]\n",
|
| 263 |
+
" paths_img = np.zeros((marker.shape[0], marker.shape[1], 3), dtype=np.uint8)\n",
|
| 264 |
+
" color_free = [int(c * 255) for c in colors_free[solver_idx % len(colors_free)][:3]]\n",
|
| 265 |
+
" for x, y in free_path:\n",
|
| 266 |
+
" if 0 <= x < paths_img.shape[0] and 0 <= y < paths_img.shape[1]:\n",
|
| 267 |
+
" paths_img[x, y] = color_free\n",
|
| 268 |
+
" ax.imshow(paths_img)\n",
|
| 269 |
+
" ax.set_title(f\"{solver_name}: Free Path (n={len(free_path)} pts)\")\n",
|
| 270 |
+
" ax.axis(\"off\")\n",
|
| 271 |
+
" ax_idx += 1\n",
|
| 272 |
+
"\n",
|
| 273 |
+
" # Obstacles path\n",
|
| 274 |
+
" ax = axes[ax_idx]\n",
|
| 275 |
+
" paths_img = np.zeros((marker.shape[0], marker.shape[1], 3), dtype=np.uint8)\n",
|
| 276 |
+
" color_obs = [int(c * 255) for c in colors_obs[solver_idx % len(colors_obs)][:3]]\n",
|
| 277 |
+
" for x, y in obs_path:\n",
|
| 278 |
+
" if 0 <= x < paths_img.shape[0] and 0 <= y < paths_img.shape[1]:\n",
|
| 279 |
+
" paths_img[x, y] = color_obs\n",
|
| 280 |
+
" ax.imshow(paths_img)\n",
|
| 281 |
+
" ax.set_title(f\"{solver_name}: Obstacles Path (n={len(obs_path)} pts)\")\n",
|
| 282 |
+
" ax.axis(\"off\")\n",
|
| 283 |
+
" ax_idx += 1\n",
|
| 284 |
+
"\n",
|
| 285 |
+
"plt.tight_layout()\n",
|
| 286 |
+
"plt.show()"
|
| 287 |
+
]
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"cell_type": "code",
|
| 291 |
+
"execution_count": null,
|
| 292 |
+
"id": "963e943c",
|
| 293 |
+
"metadata": {},
|
| 294 |
+
"outputs": [],
|
| 295 |
+
"source": [
|
| 296 |
+
"# All solver paths overlaid for comparison\n",
|
| 297 |
+
"if solvers:\n",
|
| 298 |
+
" fig, axes = plt.subplots(1, 2, figsize=(16, 8))\n",
|
| 299 |
+
"\n",
|
| 300 |
+
" # Free paths comparison\n",
|
| 301 |
+
" ax = axes[0]\n",
|
| 302 |
+
" paths_overlay = np.zeros((marker.shape[0], marker.shape[1], 3), dtype=np.uint8)\n",
|
| 303 |
+
" for solver_idx, solver_name in enumerate(solvers):\n",
|
| 304 |
+
" free_path = solver_paths[solver_name][\"free\"]\n",
|
| 305 |
+
" color = [int(c * 255) for c in plt.cm.tab10.colors[solver_idx % 10][:3]]\n",
|
| 306 |
+
" for x, y in free_path:\n",
|
| 307 |
+
" if 0 <= x < paths_overlay.shape[0] and 0 <= y < paths_overlay.shape[1]:\n",
|
| 308 |
+
" paths_overlay[x, y] = color\n",
|
| 309 |
+
" ax.imshow(paths_overlay)\n",
|
| 310 |
+
" ax.set_title(\"All Solvers: Free Paths Overlay\")\n",
|
| 311 |
+
" ax.axis(\"off\")\n",
|
| 312 |
+
" # Add legend\n",
|
| 313 |
+
" from matplotlib.patches import Patch\n",
|
| 314 |
+
"\n",
|
| 315 |
+
" legend_elements = [Patch(facecolor=plt.cm.tab10.colors[i % 10], label=s) for i, s in enumerate(solvers)]\n",
|
| 316 |
+
" ax.legend(handles=legend_elements, loc=\"upper right\", fontsize=8)\n",
|
| 317 |
+
"\n",
|
| 318 |
+
" # Obstacles paths comparison\n",
|
| 319 |
+
" ax = axes[1]\n",
|
| 320 |
+
" paths_overlay = np.zeros((marker.shape[0], marker.shape[1], 3), dtype=np.uint8)\n",
|
| 321 |
+
" for solver_idx, solver_name in enumerate(solvers):\n",
|
| 322 |
+
" obs_path = solver_paths[solver_name][\"obstacles\"]\n",
|
| 323 |
+
" color = [int(c * 255) for c in plt.cm.tab10.colors[solver_idx % 10][:3]]\n",
|
| 324 |
+
" for x, y in obs_path:\n",
|
| 325 |
+
" if 0 <= x < paths_overlay.shape[0] and 0 <= y < paths_overlay.shape[1]:\n",
|
| 326 |
+
" paths_overlay[x, y] = color\n",
|
| 327 |
+
" ax.imshow(paths_overlay)\n",
|
| 328 |
+
" ax.set_title(\"All Solvers: Obstacles Paths Overlay\")\n",
|
| 329 |
+
" ax.axis(\"off\")\n",
|
| 330 |
+
" ax.legend(handles=legend_elements, loc=\"upper right\", fontsize=8)\n",
|
| 331 |
+
"\n",
|
| 332 |
+
" plt.suptitle(f\"Solver Path Comparison (Resolution: {RESOLUTION})\", fontsize=14, fontweight=\"bold\")\n",
|
| 333 |
+
" plt.tight_layout()\n",
|
| 334 |
+
" plt.show()\n",
|
| 335 |
+
"else:\n",
|
| 336 |
+
" print(\"No solvers configured.\")"
|
| 337 |
+
]
|
| 338 |
+
}
|
| 339 |
+
],
|
| 340 |
+
"metadata": {
|
| 341 |
+
"kernelspec": {
|
| 342 |
+
"display_name": "passage (3.12.3)",
|
| 343 |
+
"language": "python",
|
| 344 |
+
"name": "python3"
|
| 345 |
+
},
|
| 346 |
+
"language_info": {
|
| 347 |
+
"codemirror_mode": {
|
| 348 |
+
"name": "ipython",
|
| 349 |
+
"version": 3
|
| 350 |
+
},
|
| 351 |
+
"file_extension": ".py",
|
| 352 |
+
"mimetype": "text/x-python",
|
| 353 |
+
"name": "python",
|
| 354 |
+
"nbconvert_exporter": "python",
|
| 355 |
+
"pygments_lexer": "ipython3",
|
| 356 |
+
"version": "3.12.3"
|
| 357 |
+
}
|
| 358 |
+
},
|
| 359 |
+
"nbformat": 4,
|
| 360 |
+
"nbformat_minor": 5
|
| 361 |
+
}
|
notebooks/obstacles.ipynb
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "e51ffcfb",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"MIT License\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"Copyright (c) 2026 THALES\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Permission is hereby granted, free of charge, to any person obtaining a copy\n",
|
| 13 |
+
"of this software and associated documentation files (the \"Software\"), to deal\n",
|
| 14 |
+
"in the Software without restriction, including without limitation the rights\n",
|
| 15 |
+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n",
|
| 16 |
+
"copies of the Software, and to permit persons to whom the Software is\n",
|
| 17 |
+
"furnished to do so, subject to the following conditions:\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"The above copyright notice and this permission notice shall be included in all\n",
|
| 20 |
+
"copies or substantial portions of the Software.\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n",
|
| 23 |
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n",
|
| 24 |
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n",
|
| 25 |
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n",
|
| 26 |
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n",
|
| 27 |
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n",
|
| 28 |
+
"SOFTWARE."
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "markdown",
|
| 33 |
+
"id": "34f045f2",
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"source": [
|
| 36 |
+
"# Obstacle Mask Generation\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"This notebook loads an elevation sample and markers, then generates an obstacle mask using randomized superellipses. The obstacle mask uses **0** for valid path cells and **1** for forbidden cells."
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"cell_type": "code",
|
| 43 |
+
"execution_count": null,
|
| 44 |
+
"id": "c019cfff",
|
| 45 |
+
"metadata": {},
|
| 46 |
+
"outputs": [],
|
| 47 |
+
"source": [
|
| 48 |
+
"import json\n",
|
| 49 |
+
"import logging\n",
|
| 50 |
+
"import sys\n",
|
| 51 |
+
"from pathlib import Path\n",
|
| 52 |
+
"\n",
|
| 53 |
+
"import matplotlib.pyplot as plt\n",
|
| 54 |
+
"import numpy as np\n",
|
| 55 |
+
"import pandas as pd\n",
|
| 56 |
+
"import yaml\n",
|
| 57 |
+
"from passage.utils import load_tensor, TENSOR_SUFFIX\n",
|
| 58 |
+
"from loguru import logger as loguru_logger\n",
|
| 59 |
+
"\n",
|
| 60 |
+
"# Configure info logging\n",
|
| 61 |
+
"logging.basicConfig(level=logging.INFO, format=\"%(asctime)s - %(name)s - %(levelname)s - %(message)s\")\n",
|
| 62 |
+
"logger = logging.getLogger(__name__)\n",
|
| 63 |
+
"logger.setLevel(logging.INFO)\n",
|
| 64 |
+
"\n",
|
| 65 |
+
"# Configure loguru for info level\n",
|
| 66 |
+
"loguru_logger.remove()\n",
|
| 67 |
+
"loguru_logger.add(sys.stderr, level=\"INFO\")\n",
|
| 68 |
+
"\n",
|
| 69 |
+
"ROOT = Path(\"..\").resolve()\n",
|
| 70 |
+
"sys.path.insert(0, str(ROOT / \"src\"))"
|
| 71 |
+
]
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"cell_type": "code",
|
| 75 |
+
"execution_count": null,
|
| 76 |
+
"id": "094ec38b",
|
| 77 |
+
"metadata": {},
|
| 78 |
+
"outputs": [],
|
| 79 |
+
"source": [
|
| 80 |
+
"from passage.generate import (\n",
|
| 81 |
+
" _generate_obstacles_mask,\n",
|
| 82 |
+
" _resolve_obstacle_config,\n",
|
| 83 |
+
" _resolve_solver_config,\n",
|
| 84 |
+
" generate_sample,\n",
|
| 85 |
+
" lat_to_str,\n",
|
| 86 |
+
" lon_to_str,\n",
|
| 87 |
+
")"
|
| 88 |
+
]
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"cell_type": "code",
|
| 92 |
+
"execution_count": null,
|
| 93 |
+
"id": "3b3e5dbf",
|
| 94 |
+
"metadata": {
|
| 95 |
+
"tags": [
|
| 96 |
+
"parameters"
|
| 97 |
+
]
|
| 98 |
+
},
|
| 99 |
+
"outputs": [],
|
| 100 |
+
"source": [
|
| 101 |
+
"# Parameters (papermill)\n",
|
| 102 |
+
"RESOLUTION = 512\n",
|
| 103 |
+
"SAMPLE_INDEX = 0\n",
|
| 104 |
+
"CENTER_LAT = None\n",
|
| 105 |
+
"CENTER_LON = None\n",
|
| 106 |
+
"DISABLE_IMAGES = False\n",
|
| 107 |
+
"OVERRIDE_EXISTING = True\n",
|
| 108 |
+
"NUM_MASKS_TO_GENERATE = 30"
|
| 109 |
+
]
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"cell_type": "markdown",
|
| 113 |
+
"id": "d122918f",
|
| 114 |
+
"metadata": {},
|
| 115 |
+
"source": [
|
| 116 |
+
"## Configuration"
|
| 117 |
+
]
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"cell_type": "code",
|
| 121 |
+
"execution_count": null,
|
| 122 |
+
"id": "939fb066",
|
| 123 |
+
"metadata": {},
|
| 124 |
+
"outputs": [],
|
| 125 |
+
"source": [
|
| 126 |
+
"# Paths\n",
|
| 127 |
+
"OUTPUTS_DIR = ROOT / \"outputs\" / \"obstacles\"\n",
|
| 128 |
+
"TILES_DIR = ROOT / \"outputs\" / \"download\" / \"tiles\"\n",
|
| 129 |
+
"CALIBRATE_PATH = ROOT / \"outputs\" / \"calibrate\" / \"calibrate.json\"\n",
|
| 130 |
+
"CONFIG_PATH = ROOT / \"config\" / \"config.yaml\"\n",
|
| 131 |
+
"\n",
|
| 132 |
+
"with open(CONFIG_PATH) as f:\n",
|
| 133 |
+
" config = yaml.safe_load(f) or {}\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"# read obstacles config\n",
|
| 136 |
+
"obstacles_cfg = config.get(\"obstacles\", {})\n",
|
| 137 |
+
"OBSTACLES_ENABLED = bool(obstacles_cfg.get(\"enabled\", False))\n",
|
| 138 |
+
"OBSTACLE_RATIO_MAX = float(obstacles_cfg.get(\"ratio_max\", 0.2))\n",
|
| 139 |
+
"shape_cfg = obstacles_cfg.get(\"shape\", {})\n",
|
| 140 |
+
"size_cfg = shape_cfg.get(\"size\", {})\n",
|
| 141 |
+
"OBSTACLE_SIZE_MIN_RATIO = float(size_cfg.get(\"min_ratio\", 0.20))\n",
|
| 142 |
+
"OBSTACLE_SIZE_MAX_RATIO = float(size_cfg.get(\"max_ratio\", 0.50))\n",
|
| 143 |
+
"N_CFG = shape_cfg.get(\"n\", {})\n",
|
| 144 |
+
"N_DISTRIBUTION_CFG = N_CFG.get(\"distribution\", {})\n",
|
| 145 |
+
"\n",
|
| 146 |
+
"# generation tuning\n",
|
| 147 |
+
"GENERATION_CFG = obstacles_cfg.get(\"generation\", {})\n",
|
| 148 |
+
"obstacle_settings = _resolve_obstacle_config(config)\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"# Obstacle mask generation settings\n",
|
| 151 |
+
"NUM_MASKS_MAX = 40 # Upper bound constant (used for display/experiments)\n",
|
| 152 |
+
"NUM_MASKS_TO_GENERATE = 20 # Number of masks to generate and display (<= NUM_MASKS_MAX)\n",
|
| 153 |
+
"\n",
|
| 154 |
+
"COST_MODEL = (\n",
|
| 155 |
+
" config.get(\"solver\", {}).get(\"grid\", {}).get(\"cost_model\")\n",
|
| 156 |
+
" or config.get(\"solver\", {}).get(\"networkx\", {}).get(\"cost_model\")\n",
|
| 157 |
+
" or config.get(\"solver\", {}).get(\"pathfinding\", {}).get(\"cost_model\")\n",
|
| 158 |
+
" or \"elevation\"\n",
|
| 159 |
+
")\n",
|
| 160 |
+
"\n",
|
| 161 |
+
"# Solver defaults for sample generation read from config\n",
|
| 162 |
+
"GEN_SOLVER_CONFIG = _resolve_solver_config(config.get(\"solver\", {}))"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"cell_type": "code",
|
| 167 |
+
"execution_count": null,
|
| 168 |
+
"id": "229302ed",
|
| 169 |
+
"metadata": {},
|
| 170 |
+
"outputs": [],
|
| 171 |
+
"source": [
|
| 172 |
+
"# Shape and n distribution config (nested structure)\n",
|
| 173 |
+
"shape_cfg = obstacles_cfg.get(\"shape\", {})\n",
|
| 174 |
+
"size_cfg = shape_cfg.get(\"size\", {})\n",
|
| 175 |
+
"OBSTACLE_SIZE_MIN_RATIO = float(size_cfg.get(\"min_ratio\", 0.20))\n",
|
| 176 |
+
"OBSTACLE_SIZE_MAX_RATIO = float(size_cfg.get(\"max_ratio\", 0.50))\n",
|
| 177 |
+
"N_CFG = shape_cfg.get(\"n\", {})\n",
|
| 178 |
+
"N_DISTRIBUTION_CFG = N_CFG.get(\"distribution\", {})"
|
| 179 |
+
]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"cell_type": "markdown",
|
| 183 |
+
"id": "4a57eb31",
|
| 184 |
+
"metadata": {},
|
| 185 |
+
"source": [
|
| 186 |
+
"**Note:** The superellipse exponent `n` may be sampled from different distributions configured under `shape.n.distribution`:\n",
|
| 187 |
+
"\n",
|
| 188 |
+
"- `log_uniform` (default)\n",
|
| 189 |
+
"- `uniform`\n",
|
| 190 |
+
"- `beta`\n",
|
| 191 |
+
"- `exponential` (new): accepts parameter `lambda` (rate) to bias toward lower values; example: `{\"type\": \"exponential\", \"lambda\": 2.0}`"
|
| 192 |
+
]
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"cell_type": "markdown",
|
| 196 |
+
"id": "ff613d2d",
|
| 197 |
+
"metadata": {},
|
| 198 |
+
"source": [
|
| 199 |
+
"## Load or Generate Sample"
|
| 200 |
+
]
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"cell_type": "code",
|
| 204 |
+
"execution_count": null,
|
| 205 |
+
"id": "7195444e",
|
| 206 |
+
"metadata": {},
|
| 207 |
+
"outputs": [],
|
| 208 |
+
"source": [
|
| 209 |
+
"# Validate required inputs\n",
|
| 210 |
+
"if not CALIBRATE_PATH.exists():\n",
|
| 211 |
+
" raise FileNotFoundError(f\"Calibration file not found: {CALIBRATE_PATH}. Run 'passage calibrate' first.\")\n",
|
| 212 |
+
"if not TILES_DIR.exists():\n",
|
| 213 |
+
" raise FileNotFoundError(f\"Tiles directory not found: {TILES_DIR}. Run 'passage download' first.\")\n",
|
| 214 |
+
"\n",
|
| 215 |
+
"# Load calibration data\n",
|
| 216 |
+
"with open(CALIBRATE_PATH) as f:\n",
|
| 217 |
+
" calibration = json.load(f)\n",
|
| 218 |
+
"global_min = float(calibration[\"global_min\"])\n",
|
| 219 |
+
"global_max = float(calibration[\"global_max\"])\n",
|
| 220 |
+
"tile_stats_df = pd.DataFrame(calibration[\"tile_stats\"])\n",
|
| 221 |
+
"\n",
|
| 222 |
+
"# Import tensor utilities\n",
|
| 223 |
+
"\n",
|
| 224 |
+
"\n",
|
| 225 |
+
"def resolve_sample_paths(outputs_dir: Path, resolution: int, index: int, center_lat=None, center_lon=None):\n",
|
| 226 |
+
" \"\"\"Resolve tensor and metadata paths, supporting both compressed (.npy.zst) and legacy (.npy) formats.\"\"\"\n",
|
| 227 |
+
" tensors_root = outputs_dir / str(resolution) / \"tensors\"\n",
|
| 228 |
+
" metadata_root = outputs_dir / str(resolution) / \"metadata\"\n",
|
| 229 |
+
" if center_lat is not None and center_lon is not None:\n",
|
| 230 |
+
" lat_dir = lat_to_str(int(center_lat))\n",
|
| 231 |
+
" lon_dir = lon_to_str(int(center_lon))\n",
|
| 232 |
+
" # Try compressed format first, fall back to legacy\n",
|
| 233 |
+
" tensor_path_compressed = tensors_root / lat_dir / lon_dir / f\"{index:010d}{TENSOR_SUFFIX}\"\n",
|
| 234 |
+
" tensor_path_legacy = tensors_root / lat_dir / lon_dir / f\"{index:010d}.npy\"\n",
|
| 235 |
+
" tensor_path = tensor_path_compressed if tensor_path_compressed.exists() else tensor_path_legacy\n",
|
| 236 |
+
" metadata_path = metadata_root / lat_dir / lon_dir / f\"{index:010d}.yaml\"\n",
|
| 237 |
+
" return tensor_path, metadata_path\n",
|
| 238 |
+
" # Search for tensor with either suffix\n",
|
| 239 |
+
" tensor_matches_compressed = list(tensors_root.rglob(f\"{index:010d}{TENSOR_SUFFIX}\"))\n",
|
| 240 |
+
" tensor_matches_legacy = list(tensors_root.rglob(f\"{index:010d}.npy\"))\n",
|
| 241 |
+
" tensor_matches = tensor_matches_compressed or tensor_matches_legacy\n",
|
| 242 |
+
" metadata_matches = list(metadata_root.rglob(f\"{index:010d}.yaml\"))\n",
|
| 243 |
+
" tensor_path = tensor_matches[0] if tensor_matches else tensors_root / f\"{index:010d}{TENSOR_SUFFIX}\"\n",
|
| 244 |
+
" metadata_path = metadata_matches[0] if metadata_matches else metadata_root / f\"{index:010d}.yaml\"\n",
|
| 245 |
+
" return tensor_path, metadata_path\n",
|
| 246 |
+
"\n",
|
| 247 |
+
"\n",
|
| 248 |
+
"def load_tensor_compat(path: Path, resolution: int) -> np.ndarray:\n",
|
| 249 |
+
" \"\"\"Load a tensor from either compressed (.npy.zst) or legacy (.npy) format.\"\"\"\n",
|
| 250 |
+
" if path.suffix == \".zst\" or str(path).endswith(TENSOR_SUFFIX):\n",
|
| 251 |
+
" return load_tensor(path, (resolution, resolution, 3), \"float32\")\n",
|
| 252 |
+
" else:\n",
|
| 253 |
+
" return np.load(path)\n",
|
| 254 |
+
"\n",
|
| 255 |
+
"\n",
|
| 256 |
+
"tensor_path, metadata_path = resolve_sample_paths(OUTPUTS_DIR, RESOLUTION, SAMPLE_INDEX, CENTER_LAT, CENTER_LON)\n",
|
| 257 |
+
"\n",
|
| 258 |
+
"if OVERRIDE_EXISTING or not tensor_path.exists() or not metadata_path.exists():\n",
|
| 259 |
+
" OUTPUTS_DIR.mkdir(parents=True, exist_ok=True)\n",
|
| 260 |
+
" args = (\n",
|
| 261 |
+
" SAMPLE_INDEX,\n",
|
| 262 |
+
" TILES_DIR,\n",
|
| 263 |
+
" OUTPUTS_DIR,\n",
|
| 264 |
+
" RESOLUTION,\n",
|
| 265 |
+
" tile_stats_df,\n",
|
| 266 |
+
" global_min,\n",
|
| 267 |
+
" global_max,\n",
|
| 268 |
+
" DISABLE_IMAGES,\n",
|
| 269 |
+
" GEN_SOLVER_CONFIG,\n",
|
| 270 |
+
" obstacle_settings,\n",
|
| 271 |
+
" )\n",
|
| 272 |
+
" index, success, message, duration = generate_sample(args)\n",
|
| 273 |
+
" print(f\"Generate sample: success={success}, message='{message}', duration={duration:.2f}s\")\n",
|
| 274 |
+
" if not success:\n",
|
| 275 |
+
" raise RuntimeError(\"Sample generation failed. Try a different resolution or re-run calibration.\")\n",
|
| 276 |
+
" # Re-resolve paths after generation (new format)\n",
|
| 277 |
+
" tensor_path, metadata_path = resolve_sample_paths(OUTPUTS_DIR, RESOLUTION, SAMPLE_INDEX, CENTER_LAT, CENTER_LON)\n",
|
| 278 |
+
"else:\n",
|
| 279 |
+
" print(f\"Using existing tensor: {tensor_path}\")\n",
|
| 280 |
+
"\n",
|
| 281 |
+
"tensor = load_tensor_compat(tensor_path, RESOLUTION)\n",
|
| 282 |
+
"elevation_norm = tensor[:, :, 0]\n",
|
| 283 |
+
"marker_channel = tensor[:, :, 1]\n",
|
| 284 |
+
"obstacle_channel = tensor[:, :, 2] if tensor.shape[2] > 2 else np.zeros_like(marker_channel)\n",
|
| 285 |
+
"elevation_raw = elevation_norm * (global_max - global_min) + global_min\n",
|
| 286 |
+
"\n",
|
| 287 |
+
"print(f\"Loaded tensor shape: {tensor.shape}\")"
|
| 288 |
+
]
|
| 289 |
+
},
|
| 290 |
+
{
|
| 291 |
+
"cell_type": "markdown",
|
| 292 |
+
"id": "009b48e9",
|
| 293 |
+
"metadata": {},
|
| 294 |
+
"source": [
|
| 295 |
+
"## Obstacle Generation"
|
| 296 |
+
]
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"cell_type": "code",
|
| 300 |
+
"execution_count": null,
|
| 301 |
+
"id": "dbdef6b0",
|
| 302 |
+
"metadata": {},
|
| 303 |
+
"outputs": [],
|
| 304 |
+
"source": [
|
| 305 |
+
"# Using _generate_obstacles_mask from generate.py\n",
|
| 306 |
+
"# The function signature is:\n",
|
| 307 |
+
"# _generate_obstacles_mask(\n",
|
| 308 |
+
"# shape, ratio_max, size_min_ratio, size_max_ratio, obstacles_cfg,\n",
|
| 309 |
+
"# marker_positions=None, rng=None, max_attempts=None, generation_cfg=None\n",
|
| 310 |
+
"# ) -> tuple[np.ndarray, float]\n",
|
| 311 |
+
"#\n",
|
| 312 |
+
"# Note: obstacles_cfg is required and contains the full obstacles config dict"
|
| 313 |
+
]
|
| 314 |
+
},
|
| 315 |
+
{
|
| 316 |
+
"cell_type": "code",
|
| 317 |
+
"execution_count": null,
|
| 318 |
+
"id": "ada07c41",
|
| 319 |
+
"metadata": {},
|
| 320 |
+
"outputs": [],
|
| 321 |
+
"source": [
|
| 322 |
+
"start_positions = np.argwhere(np.isclose(marker_channel, 0.0))\n",
|
| 323 |
+
"end_positions = np.argwhere(marker_channel > 0.5)\n",
|
| 324 |
+
"marker_positions = np.vstack([start_positions, end_positions])\n",
|
| 325 |
+
"\n",
|
| 326 |
+
"# Respect the notebook-level constants and ensure we don't exceed the defined maximum\n",
|
| 327 |
+
"NUM_MASKS = min(NUM_MASKS_TO_GENERATE, NUM_MASKS_MAX)\n",
|
| 328 |
+
"\n",
|
| 329 |
+
"masks = []\n",
|
| 330 |
+
"ratios = []\n",
|
| 331 |
+
"for i in range(NUM_MASKS):\n",
|
| 332 |
+
" # Use _generate_obstacles_mask from generate.py\n",
|
| 333 |
+
" mask, ratio = _generate_obstacles_mask(\n",
|
| 334 |
+
" shape=elevation_raw.shape,\n",
|
| 335 |
+
" ratio_max=OBSTACLE_RATIO_MAX,\n",
|
| 336 |
+
" size_min_ratio=OBSTACLE_SIZE_MIN_RATIO,\n",
|
| 337 |
+
" size_max_ratio=OBSTACLE_SIZE_MAX_RATIO,\n",
|
| 338 |
+
" obstacles_cfg=obstacles_cfg,\n",
|
| 339 |
+
" marker_positions=marker_positions,\n",
|
| 340 |
+
" generation_cfg=GENERATION_CFG,\n",
|
| 341 |
+
" )\n",
|
| 342 |
+
" masks.append(mask)\n",
|
| 343 |
+
" ratios.append(ratio)\n",
|
| 344 |
+
"\n",
|
| 345 |
+
"masks_arr = np.stack(masks, axis=0)\n",
|
| 346 |
+
"\n",
|
| 347 |
+
"# Choose the first generated mask as the active obstacles_mask for downstream cells\n",
|
| 348 |
+
"obstacles_mask = masks_arr[0]\n",
|
| 349 |
+
"tensor_with_obstacles = np.stack([elevation_norm, marker_channel, obstacles_mask], axis=-1)\n",
|
| 350 |
+
"\n",
|
| 351 |
+
"print(f\"Generated {NUM_MASKS} obstacle masks (displaying {NUM_MASKS}).\")\n",
|
| 352 |
+
"print(f\"Target obstacle ratio stats: min={min(ratios):.3f}, mean={np.mean(ratios):.3f}, max={max(ratios):.3f}\")\n",
|
| 353 |
+
"print(f\"Tensor with obstacles shape: {tensor_with_obstacles.shape}\")\n",
|
| 354 |
+
"\n",
|
| 355 |
+
"# Display the masks in a compact grid gallery\n",
|
| 356 |
+
"n = masks_arr.shape[0]\n",
|
| 357 |
+
"cols = min(5, n)\n",
|
| 358 |
+
"rows = int(np.ceil(n / cols))\n",
|
| 359 |
+
"\n",
|
| 360 |
+
"fig, axes = plt.subplots(rows, cols, figsize=(4 * cols, 4 * rows))\n",
|
| 361 |
+
"if rows == 1:\n",
|
| 362 |
+
" axes = axes.reshape(1, -1)\n",
|
| 363 |
+
"if cols == 1:\n",
|
| 364 |
+
" axes = axes.reshape(-1, 1)\n",
|
| 365 |
+
"\n",
|
| 366 |
+
"for idx in range(n):\n",
|
| 367 |
+
" r = idx // cols\n",
|
| 368 |
+
" c = idx % cols\n",
|
| 369 |
+
" axes[r, c].imshow(masks_arr[idx], cmap=\"gray\", origin=\"upper\")\n",
|
| 370 |
+
" axes[r, c].set_title(f\"Mask {idx} (r={ratios[idx]:.3f})\", fontsize=9)\n",
|
| 371 |
+
" axes[r, c].axis(\"off\")\n",
|
| 372 |
+
"\n",
|
| 373 |
+
"# Hide empty subplots\n",
|
| 374 |
+
"for idx in range(n, rows * cols):\n",
|
| 375 |
+
" r = idx // cols\n",
|
| 376 |
+
" c = idx % cols\n",
|
| 377 |
+
" axes[r, c].axis(\"off\")\n",
|
| 378 |
+
"\n",
|
| 379 |
+
"plt.tight_layout()\n",
|
| 380 |
+
"plt.show()"
|
| 381 |
+
]
|
| 382 |
+
},
|
| 383 |
+
{
|
| 384 |
+
"cell_type": "markdown",
|
| 385 |
+
"id": "4b4e554d",
|
| 386 |
+
"metadata": {},
|
| 387 |
+
"source": [
|
| 388 |
+
"## Pathfinding (grid:astar)"
|
| 389 |
+
]
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"cell_type": "code",
|
| 393 |
+
"execution_count": null,
|
| 394 |
+
"id": "0a28f930",
|
| 395 |
+
"metadata": {},
|
| 396 |
+
"outputs": [],
|
| 397 |
+
"source": [
|
| 398 |
+
"start_positions = np.argwhere(np.isclose(marker_channel, 0.0))\n",
|
| 399 |
+
"end_positions = np.argwhere(marker_channel > 0.5)\n",
|
| 400 |
+
"if start_positions.shape[0] < 1 or end_positions.shape[0] < 1:\n",
|
| 401 |
+
" raise RuntimeError(\"Expected start and end markers in marker channel.\")\n",
|
| 402 |
+
"\n",
|
| 403 |
+
"start = tuple(start_positions[0])\n",
|
| 404 |
+
"end = tuple(end_positions[0])\n",
|
| 405 |
+
"\n",
|
| 406 |
+
"# Resolve solver config from config.yaml (supports common + backend sections)\n",
|
| 407 |
+
"solver_config = _resolve_solver_config(config.get(\"solver\", {}))\n",
|
| 408 |
+
"# Ensure sensible defaults\n",
|
| 409 |
+
"solver_config.setdefault(\"diagonal_movement\", \"always\")\n",
|
| 410 |
+
"solver_config.setdefault(\"weight\", 30.0)"
|
| 411 |
+
]
|
| 412 |
+
}
|
| 413 |
+
],
|
| 414 |
+
"metadata": {
|
| 415 |
+
"kernelspec": {
|
| 416 |
+
"display_name": "passage (3.12.3)",
|
| 417 |
+
"language": "python",
|
| 418 |
+
"name": "python3"
|
| 419 |
+
},
|
| 420 |
+
"language_info": {
|
| 421 |
+
"codemirror_mode": {
|
| 422 |
+
"name": "ipython",
|
| 423 |
+
"version": 3
|
| 424 |
+
},
|
| 425 |
+
"file_extension": ".py",
|
| 426 |
+
"mimetype": "text/x-python",
|
| 427 |
+
"name": "python",
|
| 428 |
+
"nbconvert_exporter": "python",
|
| 429 |
+
"pygments_lexer": "ipython3",
|
| 430 |
+
"version": "3.12.3"
|
| 431 |
+
}
|
| 432 |
+
},
|
| 433 |
+
"nbformat": 4,
|
| 434 |
+
"nbformat_minor": 5
|
| 435 |
+
}
|
notebooks/solve.ipynb
ADDED
|
@@ -0,0 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|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "969eb9d5",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"MIT License\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"Copyright (c) 2026 THALES\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"Permission is hereby granted, free of charge, to any person obtaining a copy\n",
|
| 13 |
+
"of this software and associated documentation files (the \"Software\"), to deal\n",
|
| 14 |
+
"in the Software without restriction, including without limitation the rights\n",
|
| 15 |
+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n",
|
| 16 |
+
"copies of the Software, and to permit persons to whom the Software is\n",
|
| 17 |
+
"furnished to do so, subject to the following conditions:\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"The above copyright notice and this permission notice shall be included in all\n",
|
| 20 |
+
"copies or substantial portions of the Software.\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n",
|
| 23 |
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n",
|
| 24 |
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n",
|
| 25 |
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n",
|
| 26 |
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n",
|
| 27 |
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n",
|
| 28 |
+
"SOFTWARE."
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "markdown",
|
| 33 |
+
"id": "7b0f8c0e",
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"source": [
|
| 36 |
+
"# Solver Comparison (NetworkX + Pathfinding + Grid)\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"This notebook generates a single sample at a chosen resolution using `passage.generate.generate_sample`,\n",
|
| 39 |
+
"then compares NetworkX, Pathfinding and internal Grid (NumPy) solvers from `passage.generate.find_path`.\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"It records computation time, summarizes results, and visualizes all paths on the elevation map.\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"We report solve time statistics; for a set of times $t_i$, the mean is $\\mu = \\frac{1}{N}\\sum_i t_i$ and the maximum is $\\max_i t_i$.\n"
|
| 44 |
+
]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"cell_type": "code",
|
| 48 |
+
"execution_count": null,
|
| 49 |
+
"id": "cb548b04",
|
| 50 |
+
"metadata": {},
|
| 51 |
+
"outputs": [],
|
| 52 |
+
"source": [
|
| 53 |
+
"import json\n",
|
| 54 |
+
"import logging\n",
|
| 55 |
+
"import sys\n",
|
| 56 |
+
"import time\n",
|
| 57 |
+
"from pathlib import Path\n",
|
| 58 |
+
"\n",
|
| 59 |
+
"import matplotlib.pyplot as plt\n",
|
| 60 |
+
"import matplotlib.cm as cm\n",
|
| 61 |
+
"import numpy as np\n",
|
| 62 |
+
"import pandas as pd\n",
|
| 63 |
+
"import yaml\n",
|
| 64 |
+
"from loguru import logger as loguru_logger\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"# Configure info logging\n",
|
| 67 |
+
"logging.basicConfig(level=logging.INFO, format=\"%(asctime)s - %(name)s - %(levelname)s - %(message)s\")\n",
|
| 68 |
+
"logger = logging.getLogger(__name__)\n",
|
| 69 |
+
"logger.setLevel(logging.INFO)\n",
|
| 70 |
+
"\n",
|
| 71 |
+
"# Configure loguru for info level\n",
|
| 72 |
+
"loguru_logger.remove()\n",
|
| 73 |
+
"loguru_logger.add(sys.stderr, level=\"INFO\")\n",
|
| 74 |
+
"\n",
|
| 75 |
+
"# Add src to path for imports\n",
|
| 76 |
+
"ROOT = Path(\"..\").resolve()\n",
|
| 77 |
+
"sys.path.insert(0, str(ROOT / \"src\"))"
|
| 78 |
+
]
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"cell_type": "code",
|
| 82 |
+
"execution_count": null,
|
| 83 |
+
"id": "625f6f13",
|
| 84 |
+
"metadata": {},
|
| 85 |
+
"outputs": [],
|
| 86 |
+
"source": [
|
| 87 |
+
"from passage.generate import generate_sample, find_path, lat_to_str, lon_to_str, _resolve_obstacle_config\n",
|
| 88 |
+
"from passage.visualization import tensor_to_image"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"cell_type": "code",
|
| 93 |
+
"execution_count": null,
|
| 94 |
+
"id": "2baab49f",
|
| 95 |
+
"metadata": {
|
| 96 |
+
"tags": [
|
| 97 |
+
"parameters"
|
| 98 |
+
]
|
| 99 |
+
},
|
| 100 |
+
"outputs": [],
|
| 101 |
+
"source": [
|
| 102 |
+
"# Parameters (papermill)\n",
|
| 103 |
+
"RESOLUTION = 512"
|
| 104 |
+
]
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"cell_type": "code",
|
| 108 |
+
"execution_count": null,
|
| 109 |
+
"id": "94a64955",
|
| 110 |
+
"metadata": {},
|
| 111 |
+
"outputs": [],
|
| 112 |
+
"source": [
|
| 113 |
+
"# Solvers list (moved to top for visibility)\n",
|
| 114 |
+
"CONFIG_PATH = ROOT / \"config\" / \"config.yaml\"\n",
|
| 115 |
+
"DEFAULT_COST_MODEL = \"elevation\"\n",
|
| 116 |
+
"\n",
|
| 117 |
+
"try:\n",
|
| 118 |
+
" with open(CONFIG_PATH) as f:\n",
|
| 119 |
+
" _config = yaml.safe_load(f) or {}\n",
|
| 120 |
+
" _solver_cfg = _config.get(\"solver\", {})\n",
|
| 121 |
+
" _obstacle_settings = _resolve_obstacle_config(_config)\n",
|
| 122 |
+
" COST_MODEL = (\n",
|
| 123 |
+
" _solver_cfg.get(\"grid\", {}).get(\"cost_model\")\n",
|
| 124 |
+
" or _solver_cfg.get(\"networkx\", {}).get(\"cost_model\")\n",
|
| 125 |
+
" or _solver_cfg.get(\"pathfinding\", {}).get(\"cost_model\")\n",
|
| 126 |
+
" or DEFAULT_COST_MODEL\n",
|
| 127 |
+
" )\n",
|
| 128 |
+
" OBSTACLES_ENABLED = bool(_obstacle_settings.get(\"enabled\", False))\n",
|
| 129 |
+
" OBSTACLE_PENALTY = float(_obstacle_settings.get(\"obstacle_penalty\", 1e8))\n",
|
| 130 |
+
"except Exception:\n",
|
| 131 |
+
" COST_MODEL = DEFAULT_COST_MODEL\n",
|
| 132 |
+
" OBSTACLES_ENABLED = False\n",
|
| 133 |
+
" OBSTACLE_PENALTY = 1e8\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"SOLVERS = [\n",
|
| 136 |
+
" # NetworkX\n",
|
| 137 |
+
" {\"name\": \"networkx:astar\", \"heuristic\": \"euclidean\", \"cost_model\": COST_MODEL, \"label\": \"NetworkX A* (Euclidean)\"},\n",
|
| 138 |
+
" {\n",
|
| 139 |
+
" \"name\": \"networkx:astar_bi\",\n",
|
| 140 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 141 |
+
" \"cost_model\": COST_MODEL,\n",
|
| 142 |
+
" \"label\": \"NetworkX A* (Bidirectional)\",\n",
|
| 143 |
+
" },\n",
|
| 144 |
+
" {\"name\": \"networkx:dijkstra\", \"cost_model\": COST_MODEL, \"label\": \"NetworkX Dijkstra\"},\n",
|
| 145 |
+
" {\"name\": \"networkx:dijkstra_bi\", \"cost_model\": COST_MODEL, \"label\": \"NetworkX Dijkstra (Bidirectional)\"},\n",
|
| 146 |
+
" {\"name\": \"networkx:bellman_ford\", \"cost_model\": COST_MODEL, \"label\": \"NetworkX Bellman-Ford\"},\n",
|
| 147 |
+
" {\"name\": \"networkx:unweighted\", \"cost_model\": COST_MODEL, \"label\": \"NetworkX Unweighted (BFS)\"},\n",
|
| 148 |
+
" # Pathfinding\n",
|
| 149 |
+
" {\n",
|
| 150 |
+
" \"name\": \"pathfinding:astar\",\n",
|
| 151 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 152 |
+
" \"cost_model\": COST_MODEL,\n",
|
| 153 |
+
" \"label\": \"Pathfinding A* (Euclidean)\",\n",
|
| 154 |
+
" },\n",
|
| 155 |
+
" {\"name\": \"pathfinding:dijkstra\", \"cost_model\": COST_MODEL, \"label\": \"Pathfinding Dijkstra\"},\n",
|
| 156 |
+
" {\n",
|
| 157 |
+
" \"name\": \"pathfinding:best_first\",\n",
|
| 158 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 159 |
+
" \"cost_model\": COST_MODEL,\n",
|
| 160 |
+
" \"label\": \"Pathfinding Best-First\",\n",
|
| 161 |
+
" },\n",
|
| 162 |
+
" # Grid (NumPy-based internal solvers)\n",
|
| 163 |
+
" {\"name\": \"grid:astar\", \"heuristic\": \"euclidean\", \"cost_model\": COST_MODEL, \"label\": \"Grid A* (NumPy)\"},\n",
|
| 164 |
+
" {\"name\": \"grid:dijkstra\", \"cost_model\": COST_MODEL, \"label\": \"Grid Dijkstra (NumPy)\"},\n",
|
| 165 |
+
"]"
|
| 166 |
+
]
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"cell_type": "markdown",
|
| 170 |
+
"id": "a0e9f208",
|
| 171 |
+
"metadata": {},
|
| 172 |
+
"source": [
|
| 173 |
+
"## Configuration\n",
|
| 174 |
+
"\n",
|
| 175 |
+
"Choose a resolution and where to store the generated sample."
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"cell_type": "code",
|
| 180 |
+
"execution_count": null,
|
| 181 |
+
"id": "c8de1380",
|
| 182 |
+
"metadata": {},
|
| 183 |
+
"outputs": [],
|
| 184 |
+
"source": [
|
| 185 |
+
"# Sample generation settings\n",
|
| 186 |
+
"RESOLUTION = 256 # 64, 128, 256, 512, 1024, 2048, 4096\n",
|
| 187 |
+
"SAMPLE_INDEX = 0\n",
|
| 188 |
+
"CENTER_LAT = None # Set to int if known\n",
|
| 189 |
+
"CENTER_LON = None # Set to int if known\n",
|
| 190 |
+
"DISABLE_IMAGES = False\n",
|
| 191 |
+
"OVERRIDE_EXISTING = True\n",
|
| 192 |
+
"\n",
|
| 193 |
+
"# Paths\n",
|
| 194 |
+
"OUTPUTS_DIR = ROOT / \"outputs\" / \"solve\"\n",
|
| 195 |
+
"TILES_DIR = ROOT / \"outputs\" / \"download\" / \"tiles\"\n",
|
| 196 |
+
"CALIBRATE_PATH = ROOT / \"outputs\" / \"calibrate\" / \"calibrate.json\"\n",
|
| 197 |
+
"OBSTACLE_SETTINGS = _resolve_obstacle_config(_config if \"_config\" in globals() else {})\n",
|
| 198 |
+
"USE_OBSTACLES = bool(OBSTACLE_SETTINGS.get(\"enabled\", False))\n",
|
| 199 |
+
"OBSTACLE_PENALTY = float(OBSTACLE_SETTINGS.get(\"obstacle_penalty\", 1e8))\n",
|
| 200 |
+
"\n",
|
| 201 |
+
"# Solver defaults for sample generation (used only to ensure a valid path exists)\n",
|
| 202 |
+
"GEN_SOLVER_CONFIG = {\n",
|
| 203 |
+
" \"name\": \"grid:astar\",\n",
|
| 204 |
+
" \"diagonal_movement\": \"always\",\n",
|
| 205 |
+
" \"weight\": 30.0,\n",
|
| 206 |
+
" \"cost_model\": COST_MODEL,\n",
|
| 207 |
+
" \"heuristic\": \"euclidean\",\n",
|
| 208 |
+
"}\n",
|
| 209 |
+
"\n",
|
| 210 |
+
"# Solver comparison settings\n",
|
| 211 |
+
"WEIGHT = 30.0\n",
|
| 212 |
+
"DIAGONAL_MOVEMENT = \"always\"\n",
|
| 213 |
+
"COST_MODEL = COST_MODEL # Pathfinding supports elevation, distance, absolute_elevation"
|
| 214 |
+
]
|
| 215 |
+
},
|
| 216 |
+
{
|
| 217 |
+
"cell_type": "markdown",
|
| 218 |
+
"id": "b275ed67",
|
| 219 |
+
"metadata": {},
|
| 220 |
+
"source": [
|
| 221 |
+
"## Generate or Load Sample\n",
|
| 222 |
+
"\n",
|
| 223 |
+
"This uses `generate_sample` from `passage.generate` to create a single tensor if it does not exist yet."
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"cell_type": "code",
|
| 228 |
+
"execution_count": null,
|
| 229 |
+
"id": "c2971a50",
|
| 230 |
+
"metadata": {},
|
| 231 |
+
"outputs": [],
|
| 232 |
+
"source": [
|
| 233 |
+
"# Validate required inputs\n",
|
| 234 |
+
"if not CALIBRATE_PATH.exists():\n",
|
| 235 |
+
" raise FileNotFoundError(f\"Calibration file not found: {CALIBRATE_PATH}. Run 'passage calibrate' first.\")\n",
|
| 236 |
+
"if not TILES_DIR.exists():\n",
|
| 237 |
+
" raise FileNotFoundError(f\"Tiles directory not found: {TILES_DIR}. Run 'passage download' first.\")\n",
|
| 238 |
+
"\n",
|
| 239 |
+
"# Load calibration data\n",
|
| 240 |
+
"with open(CALIBRATE_PATH) as f:\n",
|
| 241 |
+
" calibration = json.load(f)\n",
|
| 242 |
+
"global_min = float(calibration[\"global_min\"])\n",
|
| 243 |
+
"global_max = float(calibration[\"global_max\"])\n",
|
| 244 |
+
"tile_stats_df = pd.DataFrame(calibration[\"tile_stats\"])\n",
|
| 245 |
+
"\n",
|
| 246 |
+
"\n",
|
| 247 |
+
"def resolve_sample_paths(outputs_dir: Path, resolution: int, index: int, center_lat=None, center_lon=None):\n",
|
| 248 |
+
" tensors_root = outputs_dir / str(resolution) / \"tensors\"\n",
|
| 249 |
+
" metadata_root = outputs_dir / str(resolution) / \"metadata\"\n",
|
| 250 |
+
" if center_lat is not None and center_lon is not None:\n",
|
| 251 |
+
" lat_dir = lat_to_str(int(center_lat))\n",
|
| 252 |
+
" lon_dir = lon_to_str(int(center_lon))\n",
|
| 253 |
+
" tensor_path = tensors_root / lat_dir / lon_dir / f\"{index:010d}.npy\"\n",
|
| 254 |
+
" metadata_path = metadata_root / lat_dir / lon_dir / f\"{index:010d}.yaml\"\n",
|
| 255 |
+
" return tensor_path, metadata_path\n",
|
| 256 |
+
" tensor_matches = list(tensors_root.rglob(f\"{index:010d}.npy\"))\n",
|
| 257 |
+
" metadata_matches = list(metadata_root.rglob(f\"{index:010d}.yaml\"))\n",
|
| 258 |
+
" tensor_path = tensor_matches[0] if tensor_matches else tensors_root / f\"{index:010d}.npy\"\n",
|
| 259 |
+
" metadata_path = metadata_matches[0] if metadata_matches else metadata_root / f\"{index:010d}.yaml\"\n",
|
| 260 |
+
" return tensor_path, metadata_path\n",
|
| 261 |
+
"\n",
|
| 262 |
+
"\n",
|
| 263 |
+
"# Generate sample if not present (or if OVERRIDE_EXISTING is True)\n",
|
| 264 |
+
"tensor_path, metadata_path = resolve_sample_paths(OUTPUTS_DIR, RESOLUTION, SAMPLE_INDEX, CENTER_LAT, CENTER_LON)\n",
|
| 265 |
+
"\n",
|
| 266 |
+
"if OVERRIDE_EXISTING or not tensor_path.exists() or not metadata_path.exists():\n",
|
| 267 |
+
" OUTPUTS_DIR.mkdir(parents=True, exist_ok=True)\n",
|
| 268 |
+
" args = (\n",
|
| 269 |
+
" SAMPLE_INDEX,\n",
|
| 270 |
+
" TILES_DIR,\n",
|
| 271 |
+
" OUTPUTS_DIR,\n",
|
| 272 |
+
" RESOLUTION,\n",
|
| 273 |
+
" tile_stats_df,\n",
|
| 274 |
+
" global_min,\n",
|
| 275 |
+
" global_max,\n",
|
| 276 |
+
" DISABLE_IMAGES,\n",
|
| 277 |
+
" GEN_SOLVER_CONFIG,\n",
|
| 278 |
+
" OBSTACLE_SETTINGS,\n",
|
| 279 |
+
" )\n",
|
| 280 |
+
" index, success, message, duration = generate_sample(args)\n",
|
| 281 |
+
" print(f\"Generate sample: success={success}, message='{message}', duration={duration:.2f}s\")\n",
|
| 282 |
+
" if not success:\n",
|
| 283 |
+
" raise RuntimeError(\"Sample generation failed. Try a different resolution or re-run calibration.\")\n",
|
| 284 |
+
"else:\n",
|
| 285 |
+
" print(f\"Using existing tensor: {tensor_path}\")\n",
|
| 286 |
+
"\n",
|
| 287 |
+
"# Load tensor (shape: H, W, 3) -> channels: elevation (normalized), markers, obstacles\n",
|
| 288 |
+
"tensor = np.load(tensor_path)\n",
|
| 289 |
+
"elevation_norm = tensor[:, :, 0]\n",
|
| 290 |
+
"markers = tensor[:, :, 1]\n",
|
| 291 |
+
"obstacles_mask = tensor[:, :, 2] if tensor.shape[2] > 2 else np.zeros_like(markers)\n",
|
| 292 |
+
"# elevation_raw is the unnormalized elevation in the original units\n",
|
| 293 |
+
"elevation_raw = elevation_norm * (global_max - global_min) + global_min"
|
| 294 |
+
]
|
| 295 |
+
},
|
| 296 |
+
{
|
| 297 |
+
"cell_type": "markdown",
|
| 298 |
+
"id": "4f8c657f",
|
| 299 |
+
"metadata": {},
|
| 300 |
+
"source": [
|
| 301 |
+
"## Extract Markers\n",
|
| 302 |
+
"\n",
|
| 303 |
+
"Use the marker channel to recover the start/end coordinates."
|
| 304 |
+
]
|
| 305 |
+
},
|
| 306 |
+
{
|
| 307 |
+
"cell_type": "code",
|
| 308 |
+
"execution_count": null,
|
| 309 |
+
"id": "957e9865",
|
| 310 |
+
"metadata": {},
|
| 311 |
+
"outputs": [],
|
| 312 |
+
"source": [
|
| 313 |
+
"start_positions = np.argwhere(np.isclose(markers, 0.0))\n",
|
| 314 |
+
"end_positions = np.argwhere(markers > 0.5)\n",
|
| 315 |
+
"if len(start_positions) < 1 or len(end_positions) < 1:\n",
|
| 316 |
+
" raise ValueError(\"Expected start and end markers in the tensor.\")\n",
|
| 317 |
+
"\n",
|
| 318 |
+
"start = tuple(start_positions[0])\n",
|
| 319 |
+
"end = tuple(end_positions[0])\n",
|
| 320 |
+
"\n",
|
| 321 |
+
"print(f\"Start: {start}\")\n",
|
| 322 |
+
"print(f\"End: {end}\")\n",
|
| 323 |
+
"print(f\"Euclidean distance: {np.hypot(start[0] - end[0], start[1] - end[1]):.1f} pixels\")"
|
| 324 |
+
]
|
| 325 |
+
},
|
| 326 |
+
{
|
| 327 |
+
"cell_type": "markdown",
|
| 328 |
+
"id": "2b7b951d",
|
| 329 |
+
"metadata": {},
|
| 330 |
+
"source": [
|
| 331 |
+
"## Visualize Elevation Map\n",
|
| 332 |
+
"\n",
|
| 333 |
+
"Visualize elevation map and markers."
|
| 334 |
+
]
|
| 335 |
+
},
|
| 336 |
+
{
|
| 337 |
+
"cell_type": "code",
|
| 338 |
+
"execution_count": null,
|
| 339 |
+
"id": "f7817ebc",
|
| 340 |
+
"metadata": {},
|
| 341 |
+
"outputs": [],
|
| 342 |
+
"source": [
|
| 343 |
+
"# Display elevation map with matplotlib and show markers if available\n",
|
| 344 |
+
"fig, ax = plt.subplots(figsize=(8, 8))\n",
|
| 345 |
+
"im = ax.imshow(elevation_norm, cmap=\"terrain\", origin=\"upper\")\n",
|
| 346 |
+
"ax.set_title(f\"Elevation (normalized) - {RESOLUTION}x{RESOLUTION} (obstacles={'on' if USE_OBSTACLES else 'off'})\")\n",
|
| 347 |
+
"plt.colorbar(im, ax=ax, label=\"Normalized elevation\")\n",
|
| 348 |
+
"\n",
|
| 349 |
+
"if USE_OBSTACLES:\n",
|
| 350 |
+
" obs_overlay = np.ma.masked_where(obstacles_mask == 0, obstacles_mask)\n",
|
| 351 |
+
" ax.imshow(obs_overlay, cmap=\"Reds\", alpha=0.35, origin=\"upper\")\n",
|
| 352 |
+
"\n",
|
| 353 |
+
"# Plot start/end markers if present\n",
|
| 354 |
+
"try:\n",
|
| 355 |
+
" s = start\n",
|
| 356 |
+
" e = end\n",
|
| 357 |
+
"except NameError:\n",
|
| 358 |
+
" start_positions = np.argwhere(np.isclose(markers, 0.0))\n",
|
| 359 |
+
" end_positions = np.argwhere(markers > 0.5)\n",
|
| 360 |
+
" s = tuple(start_positions[0]) if len(start_positions) > 0 else None\n",
|
| 361 |
+
" e = tuple(end_positions[0]) if len(end_positions) > 0 else None\n",
|
| 362 |
+
"\n",
|
| 363 |
+
"if s is not None:\n",
|
| 364 |
+
" ax.plot(s[1], s[0], \"o\", color=\"lime\", markersize=8, label=\"Start\")\n",
|
| 365 |
+
"if e is not None:\n",
|
| 366 |
+
" ax.plot(e[1], e[0], \"x\", color=\"cyan\", markersize=8, label=\"End\")\n",
|
| 367 |
+
"\n",
|
| 368 |
+
"ax.legend()\n",
|
| 369 |
+
"ax.axis(\"off\")\n",
|
| 370 |
+
"plt.tight_layout()\n",
|
| 371 |
+
"plt.show()\n",
|
| 372 |
+
"\n",
|
| 373 |
+
"# Show tensor_to_image visualization (terrain colormap + overlays)\n",
|
| 374 |
+
"# Extract path pixels and elevation bounds from metadata, then call tensor_to_image\n",
|
| 375 |
+
"path_pixels = None\n",
|
| 376 |
+
"elev_range = None\n",
|
| 377 |
+
"try:\n",
|
| 378 |
+
" if metadata_path.exists():\n",
|
| 379 |
+
" with open(metadata_path) as f:\n",
|
| 380 |
+
" md_local = yaml.safe_load(f)\n",
|
| 381 |
+
" if md_local is not None:\n",
|
| 382 |
+
" # Prefer with_obstacles when obstacles enabled, else without_obstacles\n",
|
| 383 |
+
" if \"paths\" in md_local:\n",
|
| 384 |
+
" path_section = md_local.get(\"paths\", {}).get(\"with_obstacles\") or md_local.get(\"paths\", {}).get(\n",
|
| 385 |
+
" \"without_obstacles\"\n",
|
| 386 |
+
" )\n",
|
| 387 |
+
" if path_section is None:\n",
|
| 388 |
+
" path_section = md_local.get(\"path\", {})\n",
|
| 389 |
+
" else:\n",
|
| 390 |
+
" path_section = md_local.get(\"path\", {})\n",
|
| 391 |
+
"\n",
|
| 392 |
+
" if path_section:\n",
|
| 393 |
+
" path_pixels = [(p[\"i\"], p[\"j\"]) for p in path_section.get(\"pixels\", [])]\n",
|
| 394 |
+
"\n",
|
| 395 |
+
" crop_info = md_local.get(\"crop\", {})\n",
|
| 396 |
+
" if \"min_elevation\" in crop_info and \"max_elevation\" in crop_info:\n",
|
| 397 |
+
" elev_range = (crop_info.get(\"min_elevation\"), crop_info.get(\"max_elevation\"))\n",
|
| 398 |
+
"except Exception:\n",
|
| 399 |
+
" path_pixels = None\n",
|
| 400 |
+
"\n",
|
| 401 |
+
"tensor_vis = np.stack([elevation_norm, markers, obstacles_mask], axis=-1)\n",
|
| 402 |
+
"img_bgr = tensor_to_image(tensor_vis, path_pixels=path_pixels, elev_range=elev_range)\n",
|
| 403 |
+
"img_rgb = img_bgr[:, :, ::-1]\n",
|
| 404 |
+
"\n",
|
| 405 |
+
"fig2, ax2 = plt.subplots(figsize=(8, 8))\n",
|
| 406 |
+
"ax2.imshow(img_rgb, origin=\"upper\")\n",
|
| 407 |
+
"ax2.set_title(\"tensor_to_image visualization (terrain + obstacles + markers)\")\n",
|
| 408 |
+
"ax2.axis(\"off\")\n",
|
| 409 |
+
"plt.tight_layout()\n",
|
| 410 |
+
"plt.show()"
|
| 411 |
+
]
|
| 412 |
+
},
|
| 413 |
+
{
|
| 414 |
+
"cell_type": "markdown",
|
| 415 |
+
"id": "f243d356",
|
| 416 |
+
"metadata": {},
|
| 417 |
+
"source": [
|
| 418 |
+
"## Run Solver Comparison\n",
|
| 419 |
+
"\n",
|
| 420 |
+
"Compare all NetworkX and Pathfinding solvers and record execution time."
|
| 421 |
+
]
|
| 422 |
+
},
|
| 423 |
+
{
|
| 424 |
+
"cell_type": "code",
|
| 425 |
+
"execution_count": null,
|
| 426 |
+
"id": "914168d5",
|
| 427 |
+
"metadata": {},
|
| 428 |
+
"outputs": [],
|
| 429 |
+
"source": [
|
| 430 |
+
"# Apply obstacles if configured\n",
|
| 431 |
+
"elevation_input = elevation_raw\n",
|
| 432 |
+
"if USE_OBSTACLES:\n",
|
| 433 |
+
" elevation_input = elevation_raw.copy()\n",
|
| 434 |
+
" elevation_input[obstacles_mask == 1] = elevation_input.max() + OBSTACLE_PENALTY\n",
|
| 435 |
+
"\n",
|
| 436 |
+
"# Prebuild NetworkX graphs for each cost_model used by networkx solvers (reuse if multiple solvers use same model)\n",
|
| 437 |
+
"networkx_solvers = [s for s in SOLVERS if s[\"name\"].split(\":\", 1)[0] == \"networkx\"]\n",
|
| 438 |
+
"G_prebuilt_map = {}\n",
|
| 439 |
+
"if networkx_solvers:\n",
|
| 440 |
+
" from passage.generate import build_graph_from_elevation\n",
|
| 441 |
+
"\n",
|
| 442 |
+
" # Build a shared graph per cost_model (defaults to global COST_MODEL)\n",
|
| 443 |
+
" cost_models = set(s.get(\"cost_model\", COST_MODEL) for s in networkx_solvers)\n",
|
| 444 |
+
" for cost_model_name in cost_models:\n",
|
| 445 |
+
" G_prebuilt_map[cost_model_name] = build_graph_from_elevation(\n",
|
| 446 |
+
" elevation_input, weight=WEIGHT, diagonal_movement=DIAGONAL_MOVEMENT, cost_model=cost_model_name\n",
|
| 447 |
+
" )\n",
|
| 448 |
+
"\n",
|
| 449 |
+
"results = []\n",
|
| 450 |
+
"\n",
|
| 451 |
+
"for solver_info in SOLVERS:\n",
|
| 452 |
+
" solver_config = {\n",
|
| 453 |
+
" \"name\": solver_info[\"name\"],\n",
|
| 454 |
+
" \"diagonal_movement\": DIAGONAL_MOVEMENT,\n",
|
| 455 |
+
" \"weight\": WEIGHT,\n",
|
| 456 |
+
" \"cost_model\": solver_info.get(\"cost_model\", COST_MODEL),\n",
|
| 457 |
+
" }\n",
|
| 458 |
+
" if \"heuristic\" in solver_info:\n",
|
| 459 |
+
" solver_config[\"heuristic\"] = solver_info[\"heuristic\"]\n",
|
| 460 |
+
"\n",
|
| 461 |
+
" t0 = time.perf_counter()\n",
|
| 462 |
+
"\n",
|
| 463 |
+
" backend_name = solver_info[\"name\"].split(\":\", 1)[0]\n",
|
| 464 |
+
" if backend_name == \"networkx\":\n",
|
| 465 |
+
" prebuilt = G_prebuilt_map.get(solver_config[\"cost_model\"])\n",
|
| 466 |
+
" path = find_path(elevation_input, start, end, solver_config, prebuilt_graph=prebuilt)\n",
|
| 467 |
+
" else:\n",
|
| 468 |
+
" path = find_path(elevation_input, start, end, solver_config)\n",
|
| 469 |
+
"\n",
|
| 470 |
+
" elapsed = (time.perf_counter() - t0) * 1000\n",
|
| 471 |
+
"\n",
|
| 472 |
+
" results.append(\n",
|
| 473 |
+
" {\n",
|
| 474 |
+
" \"solver\": solver_info[\"label\"],\n",
|
| 475 |
+
" \"backend\": backend_name,\n",
|
| 476 |
+
" \"path_length\": len(path),\n",
|
| 477 |
+
" \"time_ms\": elapsed,\n",
|
| 478 |
+
" \"path\": path,\n",
|
| 479 |
+
" }\n",
|
| 480 |
+
" )\n",
|
| 481 |
+
"\n",
|
| 482 |
+
" print(f\"{solver_info['label']}: path_len={len(path)}, time={elapsed:.1f} ms\")\n",
|
| 483 |
+
"\n",
|
| 484 |
+
"\n",
|
| 485 |
+
"timings_df = pd.DataFrame(\n",
|
| 486 |
+
" [\n",
|
| 487 |
+
" {\"Solver\": r[\"solver\"], \"Backend\": r[\"backend\"], \"Path Length\": r[\"path_length\"], \"Time (ms)\": r[\"time_ms\"]}\n",
|
| 488 |
+
" for r in results\n",
|
| 489 |
+
" ]\n",
|
| 490 |
+
")\n",
|
| 491 |
+
"csv_path = OUTPUTS_DIR / f\"solver_times_{RESOLUTION}_{SAMPLE_INDEX:010d}.csv\"\n",
|
| 492 |
+
"csv_path.parent.mkdir(parents=True, exist_ok=True)\n",
|
| 493 |
+
"\n",
|
| 494 |
+
"timings_df.to_csv(csv_path, index=False)\n",
|
| 495 |
+
"print(f\"Saved timings to: {csv_path}\")"
|
| 496 |
+
]
|
| 497 |
+
},
|
| 498 |
+
{
|
| 499 |
+
"cell_type": "markdown",
|
| 500 |
+
"id": "298c4433",
|
| 501 |
+
"metadata": {},
|
| 502 |
+
"source": [
|
| 503 |
+
"**Note:** The *Grid* solvers (`grid:astar`, `grid:dijkstra`) are internal NumPy‑based implementations that avoid constructing a NetworkX graph. They typically run faster and use less memory for large grids (e.g., 1024, 2048, 4096). Consider using these when performance is a priority."
|
| 504 |
+
]
|
| 505 |
+
},
|
| 506 |
+
{
|
| 507 |
+
"cell_type": "markdown",
|
| 508 |
+
"id": "bac3c234",
|
| 509 |
+
"metadata": {},
|
| 510 |
+
"source": [
|
| 511 |
+
"## Results Summary\n",
|
| 512 |
+
"\n",
|
| 513 |
+
"Sort the solvers by execution time."
|
| 514 |
+
]
|
| 515 |
+
},
|
| 516 |
+
{
|
| 517 |
+
"cell_type": "code",
|
| 518 |
+
"execution_count": null,
|
| 519 |
+
"id": "0b4d422c",
|
| 520 |
+
"metadata": {},
|
| 521 |
+
"outputs": [],
|
| 522 |
+
"source": [
|
| 523 |
+
"df = timings_df.sort_values(\"Time (ms)\").reset_index(drop=True)\n",
|
| 524 |
+
"df"
|
| 525 |
+
]
|
| 526 |
+
},
|
| 527 |
+
{
|
| 528 |
+
"cell_type": "markdown",
|
| 529 |
+
"id": "0ea3ad7b",
|
| 530 |
+
"metadata": {},
|
| 531 |
+
"source": [
|
| 532 |
+
"## Timing Bar Chart"
|
| 533 |
+
]
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"cell_type": "code",
|
| 537 |
+
"execution_count": null,
|
| 538 |
+
"id": "655c84fe",
|
| 539 |
+
"metadata": {},
|
| 540 |
+
"outputs": [],
|
| 541 |
+
"source": [
|
| 542 |
+
"fig, ax = plt.subplots(figsize=(10, 6))\n",
|
| 543 |
+
"y_pos = range(len(df))\n",
|
| 544 |
+
"bars = ax.barh(y_pos, df[\"Time (ms)\"], color=\"steelblue\")\n",
|
| 545 |
+
"ax.set_yticks(y_pos)\n",
|
| 546 |
+
"ax.set_yticklabels(df[\"Solver\"])\n",
|
| 547 |
+
"ax.set_xlabel(\"Time (ms)\")\n",
|
| 548 |
+
"ax.set_title(f\"Solver Comparison - {RESOLUTION}x{RESOLUTION}\")\n",
|
| 549 |
+
"ax.invert_yaxis()\n",
|
| 550 |
+
"\n",
|
| 551 |
+
"# Add time labels\n",
|
| 552 |
+
"for i, (bar, time_val) in enumerate(zip(bars, df[\"Time (ms)\"])):\n",
|
| 553 |
+
" ax.text(bar.get_width() + 0.5, bar.get_y() + bar.get_height() / 2, f\"{time_val:.1f} ms\", va=\"center\", fontsize=9)\n",
|
| 554 |
+
"\n",
|
| 555 |
+
"plt.tight_layout()\n",
|
| 556 |
+
"plt.show()"
|
| 557 |
+
]
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"cell_type": "markdown",
|
| 561 |
+
"id": "eef28b05",
|
| 562 |
+
"metadata": {},
|
| 563 |
+
"source": [
|
| 564 |
+
"## Path Visualization (All Solvers)\n",
|
| 565 |
+
"\n",
|
| 566 |
+
"Overlay all solver paths on the elevation map."
|
| 567 |
+
]
|
| 568 |
+
},
|
| 569 |
+
{
|
| 570 |
+
"cell_type": "code",
|
| 571 |
+
"execution_count": null,
|
| 572 |
+
"id": "ef48fc78",
|
| 573 |
+
"metadata": {},
|
| 574 |
+
"outputs": [],
|
| 575 |
+
"source": [
|
| 576 |
+
"fig, ax = plt.subplots(figsize=(10, 10))\n",
|
| 577 |
+
"ax.imshow(elevation_norm, cmap=\"terrain\", alpha=0.85, origin=\"upper\")\n",
|
| 578 |
+
"\n",
|
| 579 |
+
"if USE_OBSTACLES:\n",
|
| 580 |
+
" obs_overlay = np.ma.masked_where(obstacles_mask == 0, obstacles_mask)\n",
|
| 581 |
+
" ax.imshow(obs_overlay, cmap=\"Reds\", alpha=0.25, origin=\"upper\")\n",
|
| 582 |
+
"\n",
|
| 583 |
+
"# Use a colormap for different solvers\n",
|
| 584 |
+
"\n",
|
| 585 |
+
"colors = cm.tab20(np.linspace(0, 1, len(results)))\n",
|
| 586 |
+
"\n",
|
| 587 |
+
"for idx, result in enumerate(results):\n",
|
| 588 |
+
" path = result[\"path\"]\n",
|
| 589 |
+
" if len(path) == 0:\n",
|
| 590 |
+
" continue\n",
|
| 591 |
+
" path_arr = np.array(path)\n",
|
| 592 |
+
" ax.plot(path_arr[:, 1], path_arr[:, 0], linewidth=2, color=colors[idx], label=result[\"solver\"])\n",
|
| 593 |
+
"\n",
|
| 594 |
+
"ax.plot(start[1], start[0], \"o\", color=\"lime\", markersize=8, label=\"Start\")\n",
|
| 595 |
+
"ax.plot(end[1], end[0], \"x\", color=\"cyan\", markersize=8, label=\"End\")\n",
|
| 596 |
+
"\n",
|
| 597 |
+
"ax.set_title(\"All Solver Paths\")\n",
|
| 598 |
+
"ax.legend(loc=\"upper left\", fontsize=8, bbox_to_anchor=(1.02, 1))\n",
|
| 599 |
+
"ax.axis(\"off\")\n",
|
| 600 |
+
"plt.tight_layout()\n",
|
| 601 |
+
"plt.show()"
|
| 602 |
+
]
|
| 603 |
+
},
|
| 604 |
+
{
|
| 605 |
+
"cell_type": "markdown",
|
| 606 |
+
"id": "b4b011ca",
|
| 607 |
+
"metadata": {},
|
| 608 |
+
"source": [
|
| 609 |
+
"## Path Visualization (Per Solver)\n",
|
| 610 |
+
"\n",
|
| 611 |
+
"Show one subplot per solver to compare route shapes."
|
| 612 |
+
]
|
| 613 |
+
},
|
| 614 |
+
{
|
| 615 |
+
"cell_type": "code",
|
| 616 |
+
"execution_count": null,
|
| 617 |
+
"id": "63d892f6",
|
| 618 |
+
"metadata": {},
|
| 619 |
+
"outputs": [],
|
| 620 |
+
"source": [
|
| 621 |
+
"n_solvers = len(results)\n",
|
| 622 |
+
"cols = min(3, n_solvers)\n",
|
| 623 |
+
"rows = (n_solvers + cols - 1) // cols\n",
|
| 624 |
+
"\n",
|
| 625 |
+
"fig, axes = plt.subplots(rows, cols, figsize=(5 * cols, 5 * rows))\n",
|
| 626 |
+
"if rows == 1:\n",
|
| 627 |
+
" axes = axes.reshape(1, -1)\n",
|
| 628 |
+
"if cols == 1:\n",
|
| 629 |
+
" axes = axes.reshape(-1, 1)\n",
|
| 630 |
+
"\n",
|
| 631 |
+
"for idx, result in enumerate(results):\n",
|
| 632 |
+
" r = idx // cols\n",
|
| 633 |
+
" c = idx % cols\n",
|
| 634 |
+
" ax = axes[r, c]\n",
|
| 635 |
+
"\n",
|
| 636 |
+
" ax.imshow(elevation_norm, cmap=\"terrain\", alpha=0.85, origin=\"upper\")\n",
|
| 637 |
+
"\n",
|
| 638 |
+
" if USE_OBSTACLES:\n",
|
| 639 |
+
" obs_overlay = np.ma.masked_where(obstacles_mask == 0, obstacles_mask)\n",
|
| 640 |
+
" ax.imshow(obs_overlay, cmap=\"Reds\", alpha=0.25, origin=\"upper\")\n",
|
| 641 |
+
"\n",
|
| 642 |
+
" path = result[\"path\"]\n",
|
| 643 |
+
" if len(path) > 0:\n",
|
| 644 |
+
" path_arr = np.array(path)\n",
|
| 645 |
+
" ax.plot(path_arr[:, 1], path_arr[:, 0], \"r-\", linewidth=2)\n",
|
| 646 |
+
"\n",
|
| 647 |
+
" ax.plot(start[1], start[0], \"o\", color=\"lime\", markersize=6)\n",
|
| 648 |
+
" ax.plot(end[1], end[0], \"x\", color=\"cyan\", markersize=6)\n",
|
| 649 |
+
" ax.set_title(f\"{result['solver']}\\n{result['time_ms']:.1f}ms, {result['path_length']} px\", fontsize=9)\n",
|
| 650 |
+
" ax.axis(\"off\")\n",
|
| 651 |
+
"\n",
|
| 652 |
+
"# Hide empty subplots\n",
|
| 653 |
+
"for idx in range(n_solvers, rows * cols):\n",
|
| 654 |
+
" r = idx // cols\n",
|
| 655 |
+
" c = idx % cols\n",
|
| 656 |
+
" axes[r, c].axis(\"off\")\n",
|
| 657 |
+
"\n",
|
| 658 |
+
"plt.tight_layout()\n",
|
| 659 |
+
"plt.show()"
|
| 660 |
+
]
|
| 661 |
+
}
|
| 662 |
+
],
|
| 663 |
+
"metadata": {
|
| 664 |
+
"kernelspec": {
|
| 665 |
+
"display_name": "passage (3.12.3)",
|
| 666 |
+
"language": "python",
|
| 667 |
+
"name": "python3"
|
| 668 |
+
},
|
| 669 |
+
"language_info": {
|
| 670 |
+
"codemirror_mode": {
|
| 671 |
+
"name": "ipython",
|
| 672 |
+
"version": 3
|
| 673 |
+
},
|
| 674 |
+
"file_extension": ".py",
|
| 675 |
+
"mimetype": "text/x-python",
|
| 676 |
+
"name": "python",
|
| 677 |
+
"nbconvert_exporter": "python",
|
| 678 |
+
"pygments_lexer": "ipython3",
|
| 679 |
+
"version": "3.12.3"
|
| 680 |
+
}
|
| 681 |
+
},
|
| 682 |
+
"nbformat": 4,
|
| 683 |
+
"nbformat_minor": 5
|
| 684 |
+
}
|