Skip to main content

ResPolyGP: Orthogonal Legendre Trajectory Gaussian Process Prior Model

Project description

ResPolyGP

ResPolyGP is a Python library for Gaussian Process (GP) trajectory modeling that resolves standard exact GP computational bottlenecks and non-convex initialization challenges on non-stationary, cyclical sequence extrapolation.

By formulating secular polynomial trends as a structured finite-rank prior over Legendre orthogonal basis functions ($K = \Phi A \Phi^\top + \sigma_n^2 I$), ResPolyGP utilizes the Woodbury Matrix Identity and Matrix Determinant Lemma to project the standard cubic exact GP complexity onto a tiny basis space.

This accelerates exact GP polynomial trend inference from $O(N^3)$ time and $O(N^2)$ memory to $O(ND^2 + D^3)$ time and $O(ND + D^2)$ memory (where $D$ is the active basis degree, typically $D \le 5 \ll N$), delivering up to a 1000x computational speedup without any approximation.


Key Features

  1. Orthogonal Bounded Legendre Kernels: Replaces standard unstable monomial trend kernels with recursively computed Legendre orthogonal polynomials mapped onto $x \in [-1, 1]$ to prevent floating-point underflow/overflow and preserve conditioning.
  2. True $O(ND^2 + D^3)$ Woodbury Solver: Employs Woodbury matrix inversion and matrix determinant lemma in low-rank space, bypassing the Cholesky bottleneck and completely preventing NotPSDError.
  3. Sequential Significance Early Stopping: Filters polynomial degrees dynamically via a variance-explained significance threshold ($q_d < 0.01$) to prevent overfitting to local noise crests.
  4. Simplex-Constrained Softmax Priors: Normalizes and refines components on the simplex ($\sum \alpha_k = 1.0$), ensuring structural regularization.
  5. Shape Parameter Freezing / Weights-Only Tuning: Locks shape parameters (e.g. Lomb-Scargle periods and ACF stochastic decay lengths) at their analytical time-domain values, optimizing only mixture weights to eliminate optimization drift.
  6. Spectral Healing: Detrends secular trends analytically to restore stationarity before Lomb-Scargle periodic detection, reducing periodic extrapolation error by over 80%.

Installation

You can install ResPolyGP locally in editable mode for development:

pip install -e .

Dependencies

  • Python >= 3.8
  • numpy
  • scipy
  • torch
  • gpytorch

Quickstart

Below is a simple example showing how to initialize, fit, and predict with ResPolyGPModel.

import numpy as np
from respolygp import ResPolyGPModel

# 1. Generate a noisy cubic trajectory
np.random.seed(42)
t_raw = np.linspace(10, 50, 100)
# Standardized time mapping to [-1, 1]
t_norm = (t_raw - 10) / 40.0 * 2.0 - 1.0
y_raw = 5.0 + 3.0 * t_norm - 2.0 * t_norm**2 + 4.0 * t_norm**3 + np.random.normal(0, 0.1, 100)

# 2. Instantiate and run Legendre trend decomposition
model = ResPolyGPModel(max_degree=5, sig_threshold=0.01, use_robust_scale=True)
decomp = model.fit_decomposition(t_raw, y_raw)
print(f"Active Legendre degrees: {decomp['parameters']['active_degrees']}")

# 3. Initialize hyperparameters from analytical time-domain components
model.initialize_hyperparameters(t_raw, y_raw)

# 4. Refine simplex weights via Adam optimizer
history = model.fit_gp(t_raw, y_raw, lr=0.05, epochs=15, verbose=True)

# 5. Predict out-of-sample in raw physical scale units
t_test = np.array([55.0, 60.0])
mean, var, lower, upper = model.predict_raw(t_test)
print(f"Extrapolated mean: {mean}")
print(f"Extrapolated variance: {var}")
print(f"95% Confidence Bounds: [{lower}, {upper}]")

For additive systems combining both Legendre trends and Lomb-Scargle periodic components, use MostlyFinalAdditiveGPModel:

from respolygp import MostlyFinalAdditiveGPModel

model = MostlyFinalAdditiveGPModel(max_degree=5, sig_threshold=0.01, use_robust_scale=True)
# Runs the full Sequential Reversal (Periodic-First) pipeline and initializes hyperparameters
model.initialize_hyperparameters(t_raw, y_raw)
# Refines simplex weights and noise under shape constraint
model.fit_gp(t_raw, y_raw, lr=0.05, epochs=15)

License

This project is licensed under the MIT License.

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

respolygp-0.1.0.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

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

respolygp-0.1.0-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file respolygp-0.1.0.tar.gz.

File metadata

  • Download URL: respolygp-0.1.0.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for respolygp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26970ee9326f3638732cc3506c616d1145f8440bd445fa65fcd6dad2af2372f2
MD5 751f4cc05001229cf555de6442aec901
BLAKE2b-256 74f3764788baad48d9730593d5a9030fcd115b5c2f241208c3a1031f62b5e21e

See more details on using hashes here.

File details

Details for the file respolygp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: respolygp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for respolygp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa4a6b42fff2cf10fcd8e094ad761a7a6559a7961fdd8b7d531efb9e108afc7b
MD5 1384a0b9303f48580d3f0f6049e47805
BLAKE2b-256 1f3432bb02dc25001bcef636561d483b26ab00a5e38698a31ff22fe456c321c0

See more details on using hashes here.

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