Tutorial: Model Selection

This notebook demonstrates how to select an appropriate GP model for your data in pgmuvi:

  1. Using automated model selection (auto_select_model())

  2. Manually comparing models using the PSD and predictive plots

  3. Adjusting num_mixtures

  4. Using alternative kernels (e.g., spectral mixture + RBF, flicker noise)

Prerequisites: the pgmuvi_tutorial notebook and familiarity with the Model Selection how-to guide in the documentation.

1. Setup

We load a light curve with a known quasi-periodic signal plus red noise, to illustrate the difference between model choices.

[ ]:
import numpy as np
import matplotlib.pyplot as plt
import pgmuvi

# TODO: Replace with a real or better-motivated synthetic dataset
rng = np.random.default_rng(7)
times = np.sort(rng.uniform(0, 800, 250))
# Signal: quasi-periodic + red-noise-like trend
period = 120.0
fluxes = (
    1.0
    + 0.4 * np.sin(2 * np.pi * times / period)
    + 0.1 * np.sin(2 * np.pi * times / (period / 2))
    + rng.normal(0, 0.06, len(times))
)
errors = np.full_like(fluxes, 0.06)
lc = pgmuvi.lightcurve.Lightcurve(times, fluxes, errors)

2. Automated Model Selection

auto_select_model() evaluates the data characteristics and suggests the most appropriate GP model.

[ ]:
# TODO: Expand with auto_select_model() output and interpretation
recommended, diagnostics = lc.auto_select_model()
print(f"Recommended model: {recommended}")
if diagnostics.get("reason"):
    print(f"Reason: {diagnostics['reason']}")

3. Comparing Models

We fit two candidate models and compare their predictive distributions and inferred PSDs.

[ ]:
# Model A: pure spectral mixture (1D)
# TODO: Expand with fit(model="1D") (or set_model("1D"); fit()), then plot_psd()
# Optionally call fit_LS() first to inspect candidate periods / diagnostics.

# Model B: quasi-periodic (single period + coherence decay)
# TODO: Expand with fit(model="1DQuasiPeriodic") (or set_model("1DQuasiPeriodic"); fit()), then plot_psd()
# For spectral mixture + RBF combinations see the custom-kernel example script.

4. Choosing num_mixtures

Here we compare fits with 1, 2, and 4 spectral mixture components to illustrate the effect of model complexity.

[ ]:
# TODO: Loop over num_mixtures values, compare log-likelihood and BIC

5. Alternative Kernels

For advanced users, pgmuvi supports alternative kernel structures. For example, '1DMatern' provides a smooth but aperiodic covariance suitable for red-noise-like sources, while '1DQuasiPeriodic' models a coherence-decaying periodic signal. See the alternative_kernels_1d.py example script for more kernel configurations.

[ ]:
# TODO: Expand with a custom kernel example (e.g. '1DMatern' for red-noise-like behaviour)
# or refer to the alternative_kernels_1d.py example script for custom kernel combinations.

Next Steps

  • See the Model Selection how-to guide in the documentation for a summary of all available models.

  • Once you have selected a model, see the Interpreting Results how-to guide.

  • For rigorous uncertainty quantification: MCMC support (mcmc()) is planned for a future release and is not yet available.