Skip to content

Switching Linear Dynamical Systems Support - #428

Open
DanWaxman wants to merge 32 commits into
mainfrom
ml-slds-fixes
Open

DanWaxman wants to merge 32 commits into
mainfrom
ml-slds-fixes

Conversation

@DanWaxman

Copy link
Copy Markdown
Collaborator

Supersedes #294 #279.

Comment thread pyproject.toml Resolved
Comment thread dynestyx/models/observations.py Resolved
Comment thread dynestyx/models/state_evolution.py Resolved
@mattlevine22

Copy link
Copy Markdown
Collaborator

This PR adds support for switching linear dynamical systems (SLDS): models where a discrete regime selects how a continuous state evolves and generates observations. The same model can be used for simulation, filtering, and forecasting.

Inference uses a Rao–Blackwellized particle filter (RBPF) through CD-Dynamax. It samples the discrete regime histories and uses conditional Kalman updates to integrate out the continuous state.
The main additions are:

  • MixedStateDistribution for joint discrete and continuous states, plus switching linear-Gaussian transition and observation models.
  • RBPFConfig with prior and observation-conditioned ("optimal") proposals.
  • Filtering with NaN-marked missing observations, including fully missing time steps, and support for multiple trajectories through plates.
  • Optional recording of filtered state means, covariances, regime probabilities, and particle weights.
  • Validation of discrete regime indices, with optional rounding before evaluation.

A new tutorial walks through generating synthetic data with known controls, estimating transition probabilities and state-coupling parameters from incomplete observations, and making predictive rollouts conditional on the fitted parameters.

The PR also raises the minimum CD-Dynamax version to 0.5.0 and adds tests for mixed-state validation, batched filtering, missing observations, and NumPyro inference.

@DanWaxman DanWaxman left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some high-level thoughts below, didn't read in depth.

It also makes me curious if we should make a Rao-Blackwellized MCMC path (I think @lll6924 has worked on this type of thing, wonder if it's something he'd be interested in writing).

Comment thread dynestyx/inference/configs/filter.py Resolved
Comment thread dynestyx/inference/configs/filter.py Resolved
Comment thread dynestyx/inference/configs/filter.py Resolved
Co-authored-by: Dan Waxman <dan.waxman1@gmail.com>
@lll6924

lll6924 commented Nov 2, 2026

Copy link
Copy Markdown

Some high-level thoughts below, didn't read in depth.

It also makes me curious if we should make a Rao-Blackwellized MCMC path (I think @lll6924 has worked on this type of thing, wonder if it's something he'd be interested in writing).

Thank you for the invitation. I am too busy preparing for teaching right now (I'll develop 5 courses for an AI major). If I have time in winter/summer, I will check if I can contribute. The package looks very interesting to me!

@DanWaxman

Copy link
Copy Markdown
Collaborator Author

Thank you for the invitation. I am too busy preparing for teaching right now (I'll develop 5 courses for an AI major). If I have time in winter/summer, I will check if I can contribute. The package looks very interesting to me!

That's a lot of courses. good luck! And no rush/pressure at all, just figured I'd flag it as something close to your work (and, at least, someone can use/reference your prior work if we get around to it before then) :)

@mattlevine22 mattlevine22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanWaxman I think it's ready for a look when you have a chance!

@DanWaxman DanWaxman left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still didn't quite read through fully, but here are some changes that will require some more thought.

Also, Claude points out that time alignment isn't the same... dynamax treats SLDS different than other filters and actually don't pair a y_0 to x_0 (ugh!). This also happens for controls (ugh!!).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this reads a bit choppy and not as gentle as our other "gentle intros." I guess it would be fine to merge and mark as an issue, though; this has been hanging long enough.

Comment thread dynestyx/inference/configs/filter.py Resolved
Comment thread dynestyx/inference/configs/filter.py Resolved
Comment thread tests/test_slds_rbpf.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants