Skip to main content

bayes_positioner

Bayesian Time-Difference-of-Arrival Positioning

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

Metadata

Release files for bayes-positioner 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bayes-positioner 0.1.2
File Size Uploaded Provenance
bayes_positioner-0.1.2.tar.gz 17.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bayes-positioner 0.1.2
File Interpreter ABI Platform
bayes_positioner-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / bayes_positioner-0.1.2.tar.gz

Download URL bayes_positioner-0.1.2.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
22a87827b75dfea92f2afc671e4197ba055d82cb7ac012c3fcde3bac800cb494
BLAKE2b-256 checksum
How to use checksums
3db0e70ab6f847e74349f90a97fab2e26bffc9a5ed411a7be17b0f7c48691071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / bayes_positioner-0.1.2-py3-none-any.whl

Download URL bayes_positioner-0.1.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53c2e576b1b4da2f653a9a7d088ee7f0013effa47d5e370452bac6036e04b538
BLAKE2b-256 checksum
How to use checksums
9db8446872d8e79f304ad41c0e3e3f4f5238159572e2da460038db8e8cbaafb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for bayes-positioner 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page