Bayesian time-difference-of-arrival positioning using PyMC
Project description
This code implements Bayesian time-difference-of-arrival (TDOA) positioning using PyMC, a modern probabilistic programming framework. It is an updated version repackaged for installation via pip and compatible with modern PyMC versions.
Original Version
The original implementation of this code was created by Ben Moseley. You can view the original repository here: GitHub - Bayesian TDOA Positioning by Ben Moseley.
Overview
Bayesian TDOA positioning is utilized for estimating the position of a signal emitter based on the differences in signal arrival times at multiple sensor locations. This approach applies Bayesian inference methods to provide probabilistic estimations of the emitter’s location.
Installation
This package can be installed via pip. Ensure that you have Python 3.12.9 or higher installed.
pip install bayes-positioner
Usage Example
The following is an example script demonstrating Bayesian TDOA positioning using this package:
"""
Bayesian Time Difference of Arrival (TDOA) Positioning System using PyMC.
Original author bmoseley: https://github.com/benmoseley/bayesian-time-difference-of-arrival-positioning
Updated to work with PyMC 5 and made into an installable package by CBeckwith
"""
from bayes_positioner import BayesianTDOAPositioner
import pymc as pm
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
if __name__ == "__main__":
# Define problem parameters
np.random.seed(1) # Set random seed for reproducibility
N_STATIONS = 4 # Number of receiver stations
x_true = np.array([500, 500]) # True source position
v_true = 346.0 # True wave speed
t1_true = 0.5 * (np.sqrt(2) * 500 / 346) # True time offset
stations = np.random.randint(250, 750, size=(N_STATIONS, 2)) # Receiver positions
# Generate noisy observations
d_true = np.linalg.norm(stations - x_true, axis=1)
t0_true = d_true / v_true
t_obs = t0_true - t1_true + 0.05 * np.random.randn(*t0_true.shape)
# Bayesian inference
B = BayesianTDOAPositioner(stations)
trace = B.sample(t_obs)
# Posterior analysis
mu, sd = B.fit_xy_posterior(trace)
t0_pred = B.forward(mu)
# Print results
print(f"Posterior mean position: {mu}")
print(f"Posterior std-dev: {sd}")
print(f"True TOA: {t0_true}")
print(f"Predicted TOA: {t0_pred}")
print(f"True Time Offset (t1): {t1_true}")
# Plot trace (optional)
pm.plot_trace(trace)
plt.show()
# Plot results
plt.figure(figsize=(6, 6))
plt.scatter(stations[:, 0], stations[:, 1], marker="^", s=80, label="Receivers", c="blue")
plt.scatter(x_true[0], x_true[1], s=50, label="True Source", c="red")
plt.gca().add_patch(
patches.Ellipse(
xy=(mu[0], mu[1]), width=4 * sd[0], height=4 * sd[1], color="black",
alpha=0.5, label="Posterior ($2\\sigma$)"
)
)
plt.legend()
plt.xlim(0, B.x_lim)
plt.ylim(0, B.x_lim)
plt.xlabel("x (m)")
plt.ylabel("y (m)")
plt.title("Bayesian TDOA Positioning Results")
plt.grid()
plt.show()
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bayes_positioner-0.1.2.tar.gz.
File metadata
- Download URL: bayes_positioner-0.1.2.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22a87827b75dfea92f2afc671e4197ba055d82cb7ac012c3fcde3bac800cb494
|
|
| MD5 |
1c99ee6f737ff970312d47b2ead5bc1f
|
|
| BLAKE2b-256 |
3db0e70ab6f847e74349f90a97fab2e26bffc9a5ed411a7be17b0f7c48691071
|
File details
Details for the file bayes_positioner-0.1.2-py3-none-any.whl.
File metadata
- Download URL: bayes_positioner-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53c2e576b1b4da2f653a9a7d088ee7f0013effa47d5e370452bac6036e04b538
|
|
| MD5 |
20b90ae1c9445aa3ed7e950a486f06b1
|
|
| BLAKE2b-256 |
9db8446872d8e79f304ad41c0e3e3f4f5238159572e2da460038db8e8cbaafb9
|