JAX-based Sequential Monte Carlo library for time series prediction
Project description
smcs
smcs is a JAX-based Sequential Monte Carlo library for time series prediction. It combines the academic rigor of particles, the functional design patterns of BlackJAX, and the state-space model abstractions of Dynamax.
Features
- JAX-native: Full JIT compilation and GPU/TPU support
- Type-safe: Comprehensive jaxtyping annotations with runtime checking
- Multiple SMC algorithms:
- Bootstrap Particle Filter
- Auxiliary Particle Filter
- Liu-West Filter (online parameter learning)
- Storvik Filter (sufficient statistics)
- SMC² (nested SMC for parameters)
- PMMH (Particle MCMC)
- Waste-Free SMC
- State-space models:
- Dynamic Linear Models (Local Level, Local Linear Trend)
- ARIMA/SARIMA
- Stochastic Volatility
- GARCH family
- Dynamic Factor Models
- Regime-switching models
- High-level forecasting agents for easy use
- Pandas DataFrame integration
Installation
pip install smcs
For development:
pip install smcs[dev]
Quick Start
Using High-Level Agents
import jax.numpy as jnp
from smcs import LocalLevelAgent, SMCConfig
from smcs.io import from_dataframe
# Load data
data, timestamps = from_dataframe(df)
# Create and configure agent
config = SMCConfig(n_particles=1000, seed=42)
agent = LocalLevelAgent(config)
# Fit model
agent.fit(data, timestamps)
# Generate forecasts
forecast = agent.predict(horizon=10)
print(f"Forecast mean: {forecast.mean}")
print(f"95% interval: [{forecast.quantiles[0.05]}, {forecast.quantiles[0.95]}]")
# Online update with new observation
agent.update(jnp.array([new_value]))
Using Low-Level API
import jax
import jax.numpy as jnp
from smcs import (
run_bootstrap_filter,
LocalLevelModel,
LocalLevelParams,
)
# Define model and parameters
model = LocalLevelModel()
params = LocalLevelParams(
sigma_obs=0.5,
sigma_level=0.1,
m0=0.0,
C0=1.0,
)
# Generate synthetic data
key = jax.random.PRNGKey(42)
observations = jax.random.normal(key, shape=(100, 1))
# Run particle filter
filter_key = jax.random.PRNGKey(123)
state, info = run_bootstrap_filter(
filter_key,
observations,
model,
params,
n_particles=1000,
)
print(f"Log-likelihood: {state.log_likelihood:.4f}")
print(f"Final ESS: {info.ess[-1]:.1f}")
Parameter Learning with Liu-West Filter
from smcs import run_liu_west_filter, LocalLevelModel
model = LocalLevelModel()
# Define parameter conversion
def param_to_model_params(param_vec):
return LocalLevelParams(
sigma_obs=jnp.exp(param_vec[0]),
sigma_level=jnp.exp(param_vec[1]),
m0=0.0,
C0=1.0,
)
# Run Liu-West filter
state, info = run_liu_west_filter(
key,
observations,
model,
param_to_model_params,
initial_state_sampler,
initial_param_sampler,
n_particles=1000,
delta=0.98,
)
# Get estimated parameters
estimated_params = state.weighted_param_mean()
Architecture
smcs/
├── src/smcs/
│ ├── core/ # Particles, resampling, ESS computation
│ ├── algorithms/ # SMC algorithm implementations
│ ├── models/ # State space model definitions
│ ├── agents/ # High-level forecasting agents
│ ├── config/ # Pydantic configuration
│ └── io/ # DataFrame utilities
├── tests/
└── docs/
SMC Algorithms
| Algorithm | Use Case | Complexity |
|---|---|---|
| Bootstrap PF | Basic filtering | O(NT) |
| Auxiliary PF | Informative observations | O(NT) |
| Liu-West | Online parameter learning | O(NT) |
| Storvik | Models with sufficient statistics | O(NT) |
| SMC² | Full online parameter learning | O(Nθ×Nx×T) |
| PMMH | Batch parameter learning | O(N×MCMC) |
| Waste-Free | Efficient MCMC utilization | O(NT) |
State Space Models
| Model | Description |
|---|---|
| Local Level | Random walk + noise |
| Local Linear Trend | Level + slope dynamics |
| ARIMA | Autoregressive integrated moving average |
| Stochastic Volatility | Time-varying volatility |
| GARCH | Deterministic volatility dynamics |
| Dynamic Factor | Multivariate with latent factors |
| Regime-Switching | Markov-switching dynamics |
Configuration
from smcs import SMCConfig
config = SMCConfig(
n_particles=1000, # Number of particles
seed=42, # Random seed
ess_threshold=0.5, # ESS/N ratio for resampling
resampling_method="systematic", # Resampling algorithm
liu_west_delta=0.98, # Liu-West discount factor
jit_compile=True, # JIT compilation
)
Development
# Clone repository
git clone https://github.com/HarudoBoruzus/smcs.git
cd smcs
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run linter
ruff check src tests
# Type checking
mypy src
References
- Gordon, N. J., Salmond, D. J., & Smith, A. F. (1993). Novel approach to nonlinear/non-Gaussian Bayesian state estimation. IEE Proceedings F.
- Pitt, M. K., & Shephard, N. (1999). Filtering via simulation: Auxiliary particle filters. JASA.
- Liu, J., & West, M. (2001). Combined parameter and state estimation in simulation-based filtering.
- Chopin, N., Jacob, P. E., & Papaspiliopoulos, O. (2013). SMC²: an efficient algorithm for sequential analysis of state space models. JRSS-B.
- Andrieu, C., Doucet, A., & Holenstein, R. (2010). Particle Markov chain Monte Carlo methods. JRSS-B.
- Dau, H. D., & Chopin, N. (2022). Waste-free sequential Monte Carlo. JRSS-B.
License
MIT License - see LICENSE for details.
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
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 smcs-0.1.2.tar.gz.
File metadata
- Download URL: smcs-0.1.2.tar.gz
- Upload date:
- Size: 41.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
435e13cb59d1ca5901a88db2707fc72b750f3fcb471fed13316f4e00ec19bb53
|
|
| MD5 |
8b7af8135a26b5ff95cce209158475b8
|
|
| BLAKE2b-256 |
6e4b18fe6805bd4321e858c0b0f1d4cff80cd35fed9f667898dfff1fedc4e246
|
Provenance
The following attestation bundles were made for smcs-0.1.2.tar.gz:
Publisher:
publish.yml on HarudoBoruzu/smcs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smcs-0.1.2.tar.gz -
Subject digest:
435e13cb59d1ca5901a88db2707fc72b750f3fcb471fed13316f4e00ec19bb53 - Sigstore transparency entry: 953289422
- Sigstore integration time:
-
Permalink:
HarudoBoruzu/smcs@f004bbe72d25cbb1582ce6a15e0c2b4a3ae43731 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/HarudoBoruzu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f004bbe72d25cbb1582ce6a15e0c2b4a3ae43731 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file smcs-0.1.2-py3-none-any.whl.
File metadata
- Download URL: smcs-0.1.2-py3-none-any.whl
- Upload date:
- Size: 60.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
045be3f65b9b567397fb16fc3da1e15c9ad01d08b162795f2a3100a4e37ab88e
|
|
| MD5 |
ee808d4e694302416090ec3c91e1153b
|
|
| BLAKE2b-256 |
4f8bfeb99dfc5425528f4ad2cb8e291e2258d45fa5951cdbdb552fe809c70f2b
|
Provenance
The following attestation bundles were made for smcs-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on HarudoBoruzu/smcs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smcs-0.1.2-py3-none-any.whl -
Subject digest:
045be3f65b9b567397fb16fc3da1e15c9ad01d08b162795f2a3100a4e37ab88e - Sigstore transparency entry: 953289424
- Sigstore integration time:
-
Permalink:
HarudoBoruzu/smcs@f004bbe72d25cbb1582ce6a15e0c2b4a3ae43731 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/HarudoBoruzu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f004bbe72d25cbb1582ce6a15e0c2b4a3ae43731 -
Trigger Event:
workflow_dispatch
-
Statement type: