Metadata-Version: 2.4
Name: geofusion
Version: 0.1.0
Summary: Uncertain machine learning framework for GPS/GNSS sensor fusion
Author-email: Basant Mounir <basant.mounir@gmail.com>, "Amr T. Abdel-Hamid" <amr.abdelhamid@kaust.edu.sa>
License: MIT License
        
        Copyright (c) 2026 Basant Mounir, Amr T. Abdel-Hamid
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Dataset, https://www.kaggle.com/code/basantmounir/geofusion-dataset
Keywords: GPS,GNSS,sensor fusion,uncertain clustering,machine learning,positioning,GeoFusion
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=1.5
Requires-Dist: scipy>=1.10
Requires-Dist: scikit-learn>=1.2
Requires-Dist: torch>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: license-file

# GeoFusion

An uncertain machine learning framework for GPS/GNSS sensor fusion.

GeoFusion estimates true location events from noisy phone-reported GPS coordinates by modelling each observation as an uncertain object, clustering by location event, and fusing the cluster into a refined position estimate.

## Installation

```bash
pip install geofusion
```

## Quick start

```python
import pandas as pd
from geofusion import run_geofusion

df = pd.read_csv("sample_top100_groups.csv")

# UK-medoids (mountain uncertainty model) + Kalman filter
result = run_geofusion(
    df          = df,
    model       = "mountain",
    algorithm   = "ukmedoids",
    algo_params = dict(k=100, random_state=42, n_init=10, n_samples=50),
    estimator   = "kf",
)
print(result)
# GeoFusionResult(
#   model='mountain'  algorithm='ukmedoids'  estimator='kf'
#   nc=100  V=2.75m  H=1.54m  MAE=3.43m
#   runtime=4.5s  peak_RAM=152.1MB
# )

# Access the output dataframe and metrics
df_out  = result.df_out       # original columns + predicted_cluster + predicted_location
metrics = result.metrics       # {'V': ..., 'H': ..., 'MAE': ...}
```

## Uncertainty models

| `model`    | Description | Compatible algorithms |
|------------|-------------|----------------------|
| `certain`  | Raw phone coordinates, no uncertainty | `kmeans`, `kmedoids`, `sdsgc` |
| `volcano`  | Isotropic sigma from satellite geometry cost J_avg (El Abbous & Samanta, 2017) | `ukmeans`, `ukmedoids` |
| `mountain` | Directional Student-t scale from multivariate regression on GSDC dataset | `ukmeans`, `ukmedoids` |

## Clustering algorithms

| `algorithm`  | Description |
|--------------|-------------|
| `kmeans`     | k-means++ (sklearn) |
| `kmedoids`   | k-medoids with k-medoids++ initialisation |
| `ukmeans`    | UK-means (Chau et al., 2006) — provably equivalent to k-means on GPS data |
| `ukmedoids`  | UK-medoids (Gullo et al., 2008) with Monte Carlo expected-distance estimation |
| `sdsgc`      | Structured Doubly Stochastic Graph-Based Clustering (Wang et al., TNNLS 2025) |

## Estimators

| `estimator` | Description |
|-------------|-------------|
| `rep`       | Cluster representative (centroid or medoid) |
| `kf`        | Linear Kalman filter (static target, degree space) |
| `ekf`       | Extended Kalman filter (local metre space — corrects degree-space distortion) |
| `pf`        | Sequential Importance Resampling particle filter |
| `dnn`       | Post-clustering MLP predicting a position correction from cluster-level GNSS features |

## Required dataset columns

| Column | Description |
|--------|-------------|
| `collectionName` | Drive identifier (used for DNN drive-level split) |
| `latDeg_gt` | NovAtel reference latitude (degrees) |
| `lngDeg_gt` | NovAtel reference longitude (degrees) |
| `latDeg_phone` | Phone-reported latitude (degrees) |
| `lngDeg_phone` | Phone-reported longitude (degrees) |
| `j_avg` | Average satellite geometry cost |
| `speedMps` | Vehicle speed (m/s) |
| `n_signals` | Number of satellite signals |
| `avg_rawPrUnc` | Average pseudorange uncertainty (m) |
| `hDop` | Horizontal dilution of precision |
| `vDop` | Vertical dilution of precision |
| `avg_iono` | Average ionospheric delay (m) |
| `avg_tropo` | Average tropospheric delay (m) |

The dataset is publicly available on [Kaggle](https://www.kaggle.com/code/basantmounir/geofusion-dataset).

## algo_params reference

All algorithms accept `k`, `random_state`, `n_init`, `max_iter`.

Additional parameters:
- **`ukmedoids`**: `n_samples` (Monte Carlo samples for expected distance, default 50)
- **`sdsgc`**: `nn` (nearest neighbours, default 5 for k≤50, 4 for k≥100), `strategy` (`early_stop` / `best_of_n` / `threshold`), `threshold` (W-matrix threshold for component extraction), `eigsh_tol`, `eigsh_maxiter`

## estimator_params reference

- **`pf`**: `n_particles` (default 500)
- **`dnn`**: `test_drives` (required), `val_drives` (required), `max_epochs` (200), `patience` (20), `random_state` (42), `subprocess` (False — set True for clean RAM measurement)

## DNN example

```python
result = run_geofusion(
    df               = df,
    model            = "mountain",
    algorithm        = "ukmedoids",
    algo_params      = dict(k=300, random_state=42, n_init=10, n_samples=50),
    estimator        = "dnn",
    estimator_params = dict(
        test_drives = ["2020-08-03-US-MTV-1", "2020-07-08-US-MTV-1", "2021-04-15-US-MTV-1"],
        val_drives  = ["2021-04-28-US-MTV-1", "2021-04-28-US-SJC-1"],
        max_epochs  = 200,
        patience    = 20,
    ),
)
# DNN metrics are evaluated on test-drive clusters only
print(result.metrics)   # {'V': 2.05, 'H': 1.40, 'MAE': 2.71, 'n_test_clusters': 69}
```

## License

MIT
