bgnx 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bgnx-0.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BGNX Project
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.
bgnx-0.0.2/PKG-INFO ADDED
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: bgnx
3
+ Version: 0.0.2
4
+ Summary: BGNX: a framework for travel time prediction (early alpha: evaluation utilities).
5
+ Author: BGNX Project
6
+ License: MIT
7
+ Keywords: travel time,ETA,transportation,evaluation,machine learning
8
+ Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: numpy>=1.22
17
+ Requires-Dist: scipy>=1.8
18
+ Provides-Extra: torch
19
+ Requires-Dist: torch>=2.0; extra == "torch"
20
+ Dynamic: license-file
21
+
22
+ # BGNX
23
+
24
+ **BGNX** is a framework for travel time prediction, under development.
25
+
26
+ This early alpha (0.0.x) ships only general evaluation utilities. The models and the full documentation will be
27
+ released with the accompanying publications.
28
+
29
+ ```bash
30
+ pip install bgnx # metrics and paired comparison
31
+ pip install "bgnx[torch]" # + CPU/GPU device helper
32
+ ```
33
+
34
+ ```python
35
+ import numpy as np
36
+ from bgnx import metrics, paired_comparison
37
+
38
+ y = np.array([10.0, 12.5, 30.0, 7.0]) # observed durations (minutes)
39
+ pa = np.array([11.0, 12.0, 27.0, 8.0]) # model A
40
+ pb = np.array([ 9.0, 15.0, 25.0, 9.5]) # model B
41
+
42
+ print(metrics(y, pa)) # MAE, MedAE, MAPE, MARE, RMSLE, R2, EV
43
+ print(paired_comparison(y, pa, pb)) # MAE difference (B - A), bootstrap 95% CI, Wilcoxon p-value
44
+ ```
45
+
46
+ `paired_comparison` compares two models on the **same** observations: the 95% interval of the MAE difference comes
47
+ from a paired bootstrap (resampling observations), and the paired absolute errors are compared with the Wilcoxon
48
+ signed-rank test.
49
+
50
+ License: MIT.
bgnx-0.0.2/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # BGNX
2
+
3
+ **BGNX** is a framework for travel time prediction, under development.
4
+
5
+ This early alpha (0.0.x) ships only general evaluation utilities. The models and the full documentation will be
6
+ released with the accompanying publications.
7
+
8
+ ```bash
9
+ pip install bgnx # metrics and paired comparison
10
+ pip install "bgnx[torch]" # + CPU/GPU device helper
11
+ ```
12
+
13
+ ```python
14
+ import numpy as np
15
+ from bgnx import metrics, paired_comparison
16
+
17
+ y = np.array([10.0, 12.5, 30.0, 7.0]) # observed durations (minutes)
18
+ pa = np.array([11.0, 12.0, 27.0, 8.0]) # model A
19
+ pb = np.array([ 9.0, 15.0, 25.0, 9.5]) # model B
20
+
21
+ print(metrics(y, pa)) # MAE, MedAE, MAPE, MARE, RMSLE, R2, EV
22
+ print(paired_comparison(y, pa, pb)) # MAE difference (B - A), bootstrap 95% CI, Wilcoxon p-value
23
+ ```
24
+
25
+ `paired_comparison` compares two models on the **same** observations: the 95% interval of the MAE difference comes
26
+ from a paired bootstrap (resampling observations), and the paired absolute errors are compared with the Wilcoxon
27
+ signed-rank test.
28
+
29
+ License: MIT.
@@ -0,0 +1,7 @@
1
+ """BGNX: a framework for travel time prediction (early alpha: evaluation utilities only).
2
+ """
3
+ from .metrics import metrics
4
+ from .stats import paired_comparison
5
+
6
+ __version__ = '0.0.2'
7
+ __all__ = ['metrics', 'paired_comparison', '__version__']
@@ -0,0 +1,49 @@
1
+ """Training device helper (needs PyTorch: pip install "bgnx[torch]"): CPU or GPU, batch size and learning rate from a
2
+ JSON file, with environment overrides.
3
+
4
+ from bgnx.device import configure_device, move
5
+ dev, cfg = configure_device() # picks the device and prints the choice
6
+ tensors = move(tensors, dev, cfg) # whole training set on the GPU if it fits (data_on_gpu = auto)
7
+
8
+ Settings: defaults below, then the JSON in BGNX_DEVICE_CONFIG (if set), then BGNX_DEVICE=cpu|cuda|auto.
9
+ """
10
+ import json, os
11
+ from pathlib import Path
12
+
13
+ DEFAULTS = {'device': 'auto', 'cpu_threads': 8, 'data_on_gpu': 'auto', 'batch': None, 'lr': None, 'predict_batch': 32768}
14
+
15
+ def _torch():
16
+ try:
17
+ import torch
18
+ except ImportError as e:
19
+ raise ImportError('bgnx.device needs PyTorch: pip install "bgnx[torch]"') from e
20
+ return torch
21
+
22
+ def read_device_config():
23
+ """Defaults, then the JSON file, then the environment variable."""
24
+ cfg = dict(DEFAULTS)
25
+ path = os.environ.get('BGNX_DEVICE_CONFIG')
26
+ if path and Path(path).exists():
27
+ cfg.update({k: v for k, v in json.loads(Path(path).read_text(encoding='utf-8')).items() if k in DEFAULTS})
28
+ if os.environ.get('BGNX_DEVICE'): cfg['device'] = os.environ['BGNX_DEVICE']
29
+ return cfg
30
+
31
+ def configure_device():
32
+ """Returns (torch.device, config dict)."""
33
+ torch = _torch(); cfg = read_device_config()
34
+ torch.set_num_threads(int(cfg['cpu_threads']))
35
+ wanted = str(cfg['device']).lower()
36
+ if wanted not in ('auto', 'cuda', 'cpu'): raise ValueError(f'invalid device: {wanted}')
37
+ if wanted == 'cuda' and not torch.cuda.is_available(): print('warning: cuda requested but unavailable; using cpu', flush=True)
38
+ dev = torch.device('cuda' if wanted != 'cpu' and torch.cuda.is_available() else 'cpu')
39
+ name = torch.cuda.get_device_name(dev) if dev.type == 'cuda' else f'{torch.get_num_threads()} threads'
40
+ print(f'device: {dev} ({name})', flush=True)
41
+ return dev, cfg
42
+
43
+ def move(tensors, dev, cfg, headroom=1.5):
44
+ """Copies a tuple of tensors to the GPU if `data_on_gpu` allows and it fits (with headroom); otherwise returns it as is."""
45
+ torch = _torch()
46
+ if dev.type != 'cuda' or cfg['data_on_gpu'] in (False, 'false'): return tensors
47
+ size = sum(t.element_size()*t.nelement() for t in tensors)
48
+ if cfg['data_on_gpu'] == 'auto' and size*headroom > torch.cuda.mem_get_info(dev)[0]: return tensors
49
+ return tuple(t.to(dev) for t in tensors)
@@ -0,0 +1,12 @@
1
+ """Error metrics for travel time prediction. Units follow the inputs (e.g. minutes); predictions are clipped at zero.
2
+ """
3
+ import numpy as np
4
+
5
+ def metrics(y, p):
6
+ """MAE, MedAE, MAPE (%), MARE (sum|e| / sum y), RMSLE, R2 and explained variance (EV)."""
7
+ y = np.asarray(y, dtype=float); p = np.maximum(np.asarray(p, dtype=float), 0)
8
+ if y.shape != p.shape: raise ValueError(f'y and p differ in shape: {y.shape} vs {p.shape}')
9
+ e = y - p; a = np.abs(e); var = y.var()
10
+ return {'MAE': a.mean(), 'MedAE': float(np.median(a)), 'MAPE_%': 100*np.mean(a/y), 'MARE': a.sum()/y.sum(),
11
+ 'RMSLE': float(np.sqrt(np.mean((np.log1p(p) - np.log1p(y))**2))),
12
+ 'R2': 1 - np.mean(e**2)/var, 'EV': 1 - e.var()/var}
@@ -0,0 +1,17 @@
1
+ """Paired comparison of two models on the SAME observations: bootstrap interval of the MAE difference and the Wilcoxon
2
+ signed-rank test on the paired absolute errors.
3
+ """
4
+ import numpy as np
5
+ from scipy.stats import wilcoxon
6
+
7
+ def paired_comparison(y, pred_a, pred_b, replicas=2000, seed=42, level=0.95):
8
+ """Difference = MAE(B) - MAE(A) (positive = A is better), its bootstrap interval and the Wilcoxon p-value."""
9
+ y = np.asarray(y, dtype=float)
10
+ ea = np.abs(np.asarray(pred_a, dtype=float) - y); eb = np.abs(np.asarray(pred_b, dtype=float) - y)
11
+ if not (ea.shape == eb.shape == y.shape): raise ValueError('y, pred_a and pred_b must have the same shape')
12
+ d = eb - ea; n = len(d); rng = np.random.default_rng(seed)
13
+ boot = np.array([d[rng.integers(0, n, n)].mean() for _ in range(replicas)])
14
+ lo, hi = np.percentile(boot, [100*(1 - level)/2, 100*(1 + level)/2])
15
+ p = float(wilcoxon(ea, eb).pvalue) if np.any(d != 0) else 1.0
16
+ return {'mae_a': ea.mean(), 'mae_b': eb.mean(), 'difference': d.mean(), 'ci_low': lo, 'ci_high': hi,
17
+ 'level': level, 'wilcoxon_p': p, 'n': n}
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: bgnx
3
+ Version: 0.0.2
4
+ Summary: BGNX: a framework for travel time prediction (early alpha: evaluation utilities).
5
+ Author: BGNX Project
6
+ License: MIT
7
+ Keywords: travel time,ETA,transportation,evaluation,machine learning
8
+ Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: numpy>=1.22
17
+ Requires-Dist: scipy>=1.8
18
+ Provides-Extra: torch
19
+ Requires-Dist: torch>=2.0; extra == "torch"
20
+ Dynamic: license-file
21
+
22
+ # BGNX
23
+
24
+ **BGNX** is a framework for travel time prediction, under development.
25
+
26
+ This early alpha (0.0.x) ships only general evaluation utilities. The models and the full documentation will be
27
+ released with the accompanying publications.
28
+
29
+ ```bash
30
+ pip install bgnx # metrics and paired comparison
31
+ pip install "bgnx[torch]" # + CPU/GPU device helper
32
+ ```
33
+
34
+ ```python
35
+ import numpy as np
36
+ from bgnx import metrics, paired_comparison
37
+
38
+ y = np.array([10.0, 12.5, 30.0, 7.0]) # observed durations (minutes)
39
+ pa = np.array([11.0, 12.0, 27.0, 8.0]) # model A
40
+ pb = np.array([ 9.0, 15.0, 25.0, 9.5]) # model B
41
+
42
+ print(metrics(y, pa)) # MAE, MedAE, MAPE, MARE, RMSLE, R2, EV
43
+ print(paired_comparison(y, pa, pb)) # MAE difference (B - A), bootstrap 95% CI, Wilcoxon p-value
44
+ ```
45
+
46
+ `paired_comparison` compares two models on the **same** observations: the 95% interval of the MAE difference comes
47
+ from a paired bootstrap (resampling observations), and the paired absolute errors are compared with the Wilcoxon
48
+ signed-rank test.
49
+
50
+ License: MIT.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ bgnx/__init__.py
5
+ bgnx/device.py
6
+ bgnx/metrics.py
7
+ bgnx/stats.py
8
+ bgnx.egg-info/PKG-INFO
9
+ bgnx.egg-info/SOURCES.txt
10
+ bgnx.egg-info/dependency_links.txt
11
+ bgnx.egg-info/requires.txt
12
+ bgnx.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ numpy>=1.22
2
+ scipy>=1.8
3
+
4
+ [torch]
5
+ torch>=2.0
@@ -0,0 +1 @@
1
+ bgnx
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "bgnx"
7
+ version = "0.0.2"
8
+ description = "BGNX: a framework for travel time prediction (early alpha: evaluation utilities)."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "BGNX Project" }]
13
+ keywords = ["travel time", "ETA", "transportation", "evaluation", "machine learning"]
14
+ classifiers = [
15
+ "Development Status :: 2 - Pre-Alpha",
16
+ "Intended Audience :: Science/Research",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Scientific/Engineering",
20
+ ]
21
+ dependencies = ["numpy>=1.22", "scipy>=1.8"]
22
+
23
+ [project.optional-dependencies]
24
+ torch = ["torch>=2.0"]
25
+
26
+ [tool.setuptools.packages.find]
27
+ include = ["bgnx*"]
bgnx-0.0.2/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+