Skip to main content

LogPsplines in JAX

Project description

PyPI - Version JAX - Accelerated

LogPSplinePSD

Log-spline representation of the power spectral density (PSD) in the frequency domain, using penalized B-splines with a discrete penalty on spline coefficients to prevent overfitting.

Overview

LogPSplinePSD implements a Bayesian model for PSD estimation by fitting a log-spline to the periodogram. Main features:

  • Log-frequency representation: Works on the log-scale of frequencies for numerical stability and improved resolution.

  • P-spline prior: Applies a discrete difference penalty to log B-spline coefficients, enforcing smoothness in the log-PSD domain (see [Eilers1996]).

  • Whittle likelihood: Employs Whittle’s approximation for fast likelihood evaluation on periodogram ordinates.

  • CPU/GPU sampling: Uses NumPyro (JAX) to perform efficient Hamiltonian Monte Carlo inference.

Methodology

The approach follows the P-spline framework for spectral density estimation described by Maturana-Russel & Meyer (2021) [MaturanaRussel2021].

  1. Basis construction Define order-r B-spline basis functions \(B_k(\omega)\), \(k=1,\dots,K+r\), on a grid of interior knots in the log-frequency domain.

  2. Penalized prior Apply a discrete \(D\)th-order difference penalty to the spline coefficients \(\{\beta_k\}\), which induces smoothness in the estimated log-PSD.

  3. Knot placement (optional) For spectra with sharp features, knot locations can be set based on quantiles of the raw periodogram values to allocate flexibility where needed.

4. Model and likelihood The log-PSD is modeled as:

\begin{equation*} \log f(\lambda_l) = \sum_k \beta_k \, B_k(\log \lambda_l) \end{equation*}

Whittle’s approximation for the periodogram \(I_n(\lambda_l)\) yields the log-likelihood:

\begin{equation*} \log L(\beta) \propto -\sum_{l=1}^{\nu} \left[ \log f(\lambda_l) + \frac{I_n(\lambda_l)}{f(\lambda_l)} \right] \end{equation*}

5. Inference We have two options for inference:

  • Use Metropolis-Hastings to sample from the posterior distribution of the spline coefficients.

  • Use NumPyro’s NUTS sampler to jointly sample the spline coefficients.

This fixed-basis P-spline approach avoids reversible-jump MCMC over knot numbers and positions, reducing computational cost while retaining flexibility to capture complex spectral features.

Finally, one can also provide a ‘parametric model’ of the PSD as a function that can then be ‘corrected’ non-parametrically by the spline model. This is useful for cases where a known functional form (e.g., power-law) is expected, but additional flexibility is needed to account for deviations in the data.

Installation

pip install LogPSplinePSD

Basic Usage

See demo.py

Demo Image

Author

NZ Gravity

Acknowledgements

Part of the NZ-Gravity and International LISA Consortium efforts on gravitational-wave data analysis.

References

  • Aimen, M., et al. (in preparation).

  • Maturana-Russel, J., & Meyer, R. (2021). P-spline spectral density estimation with a discrete penalty. arXiv:1905.01832.

  • Eilers, P. H. C., & Marx, B. D. (1996). Flexible smoothing with B-splines and penalties. Statistical Science, 11(2), 89–121. DOI:10.1214/ss/1038425655.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logpsplinepsd-0.0.3.tar.gz (938.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logpsplinepsd-0.0.3-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file logpsplinepsd-0.0.3.tar.gz.

File metadata

  • Download URL: logpsplinepsd-0.0.3.tar.gz
  • Upload date:
  • Size: 938.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for logpsplinepsd-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4a4e76a5431726ed0e82054e27b8194700e867adbe0966359f7d46c50beb4d76
MD5 a2fdfa9a3a163f66bf086e3685043a0e
BLAKE2b-256 2b941e133fd9344dcea33876a41306c484d904fba34b40685647b8575cd449c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for logpsplinepsd-0.0.3.tar.gz:

Publisher: pypi.yml on nz-gravity/LogPSplinePSD

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logpsplinepsd-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: logpsplinepsd-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for logpsplinepsd-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f22736b78b815efefd2a799b13a094f9d0b6d72e2b637d11e12af8874c0917bc
MD5 639caec4a17319b3244acf3f3e016fd0
BLAKE2b-256 f1ae840a12b85303353069a13a7746a6d54a77b0f7e562d395d6a7aa96ed3f5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for logpsplinepsd-0.0.3-py3-none-any.whl:

Publisher: pypi.yml on nz-gravity/LogPSplinePSD

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page