Implementation:Pyro ppl Pyro GP TimeSeries
Appearance
| Property | Value |
|---|---|
| Implementation Type | Pattern Doc |
| Source File | examples/contrib/timeseries/gp_models.py
|
| Module | pyro.contrib.timeseries |
| Pyro Features | pyro.contrib.timeseries.IndependentMaternGP, pyro.contrib.timeseries.LinearlyCoupledMaternGP, maximum likelihood training, one-step and multi-step forecasting
|
| Dataset | EEG Eye State (UCI Machine Learning Repository) |
Overview
This file demonstrates Pyro's time series GP models for multivariate time series forecasting. It compares two Gaussian Process models on EEG (electroencephalography) data:
- IndependentMaternGP (IMGP): Models each output dimension independently with a Matern-1.5 kernel. Forecasts are independent across dimensions.
- LinearlyCoupledMaternGP (LCMGP): Uses a linear mixing model where multiple latent GPs are linearly combined to produce correlated output dimensions. This captures cross-channel correlations.
The training procedure:
- Maximize the log marginal likelihood
gp.log_prob(data)using Adam with exponential learning rate decay - Perform one-step-ahead forecasting using a rolling window
- Perform multi-step forecasting from a fixed conditioning set
Code Reference
def main(args):
# Set up model
if args.model == "imgp":
gp = IndependentMaternGP(nu=1.5, obs_dim=obs_dim,
length_scale_init=1.5 * torch.ones(obs_dim)).double()
elif args.model == "lcmgp":
num_gps = 9
gp = LinearlyCoupledMaternGP(nu=1.5, obs_dim=obs_dim, num_gps=num_gps,
length_scale_init=1.5 * torch.ones(num_gps)).double()
# Training loop - maximize log marginal likelihood
adam = torch.optim.Adam(gp.parameters(), lr=args.init_learning_rate)
for step in range(args.num_steps):
loss = -gp.log_prob(data[0:T_train, :]).sum() / T_train
loss.backward()
adam.step()
# One-step-ahead forecasting
for t in range(T_onestep):
dts = torch.tensor([1.0]).double()
pred_dist = gp.forecast(data[0:T_train+t, :], dts)
# Multi-step forecasting
dts = (1 + torch.arange(T_multistep)).double()
pred_dist = gp.forecast(data[0:T_train+T_onestep, :], dts)
I/O Contract
| Parameter | Type | Description |
|---|---|---|
-m / --model |
str |
Model type: "imgp" or "lcmgp" |
-n / --num-steps |
int |
Training steps (default: 300) |
-ilr / --init-learning-rate |
float |
Initial learning rate (default: 0.01) |
-flr / --final-learning-rate |
float |
Final learning rate (default: 0.0003) |
--test |
flag | Use synthetic data for testing |
--plot |
flag | Generate forecast plots |
Output:
- Training loss per step
- Forecast means and confidence intervals for selected channels
- PDF plot showing one-step and multi-step predictions
Usage Examples
# Independent Matern GP on EEG data
# python gp_models.py -m imgp -n 300 --plot
# Linearly Coupled Matern GP
# python gp_models.py -m lcmgp -n 300 --plot
# Quick test with synthetic data
# python gp_models.py --test -m imgp -n 50
Related Pages
- Pyro_ppl_Pyro_SV_DKL - Deep kernel learning combining GP with CNN
- Pyro_ppl_Pyro_GP_BayesOpt - GP-based Bayesian optimization
- Pyro_ppl_Pyro_BART_Forecast - Forecasting with ForecastingModel framework
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment