Skip to content

add determinsitic sites for extracting filtering from predictives.#72

Merged
10 commits merged intomainfrom
ml-add-filter-sites
Feb 7, 2026
Merged

add determinsitic sites for extracting filtering from predictives.#72
10 commits merged intomainfrom
ml-add-filter-sites

Conversation

@mattlevine22
Copy link
Collaborator

  • new deterministic sites are {name}_filtered_states_mean, {name}_filtered_states_cov, and {name}_marginal_loglik
  • may want to be careful about memory during MCMC though...

Copy link
Collaborator

@DanWaxman DanWaxman left a comment

Choose a reason for hiding this comment

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

As you mention, saving these things can be a big issue in some cases (long MCMC and/or really large state-space). Before, we had commented-out options to save/not save -- I think we should reinstate that (maybe also option to save only diagonal covar, etc.).

Comment on lines +209 to +212
"tnj,tnk,tn->tjk", particles, particles, jnp.exp(log_weights)
)
filtered_covariances = second_mom - jnp.einsum(
"tj,tk->tjk", filtered_means, filtered_means
Copy link
Collaborator

Choose a reason for hiding this comment

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

... for when #60 lands? (it will eventually...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you mean #63 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also not sure how to know where to put ... in anticipation of batching

Copy link
Collaborator

Choose a reason for hiding this comment

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

See below

@DanWaxman
Copy link
Collaborator

Two remaining things: documentation of what's happening, and also some tests.

Comment on lines +246 to +251
second_mom = jnp.einsum(
"tnj,tnk,tn->tjk", particles, particles, jnp.exp(log_weights)
)
filtered_covariances = second_mom - jnp.einsum(
"tj,tk->tjk", filtered_means, filtered_means
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should work

Suggested change
second_mom = jnp.einsum(
"tnj,tnk,tn->tjk", particles, particles, jnp.exp(log_weights)
)
filtered_covariances = second_mom - jnp.einsum(
"tj,tk->tjk", filtered_means, filtered_means
)
second_mom = jnp.einsum(
"...tnj,...tnk,...tn->...tjk", particles, particles, jnp.exp(log_weights)
)
filtered_covariances = second_mom - jnp.einsum(
"...tj,...tk->...tjk", filtered_means, filtered_means
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

perfect, done, thanks

Copy link
Collaborator Author

@mattlevine22 mattlevine22 left a comment

Choose a reason for hiding this comment

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

should be ready

Comment on lines +273 to +284
add_mean = record_kwargs.get(
"record_filtered_states_mean", False
) and _should_add_site(states.mean.shape, max_elems)
add_chol_cov = record_kwargs.get(
"record_filtered_states_chol_cov", False
) and _should_add_site(states.chol_cov.shape, max_elems)
add_filtered_states_cov = record_kwargs.get(
"record_filtered_states_cov", False
) and _should_add_site((T1, state_dim, state_dim), max_elems)
add_filtered_states_cov_diag = record_kwargs.get(
"record_filtered_states_cov_diag", False
) and _should_add_site((T1, state_dim), max_elems)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why and instead of or? Seems weird I can't override our (helpful, yet arbitrary) _should_add_site suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, yeah. I guess then I should default these things to True and switch to or?

@DanWaxman DanWaxman mentioned this pull request Feb 7, 2026
@mattlevine22 mattlevine22 closed this pull request by merging all changes into main in 6f4564f Feb 7, 2026
@DanWaxman
Copy link
Collaborator

DanWaxman commented Feb 7, 2026 via email

@mattlevine22
Copy link
Collaborator Author

Yeah I realized that after I merged the stuff, sorry. Fixing it now.

mattlevine22 added a commit that referenced this pull request Feb 7, 2026
@mattlevine22
Copy link
Collaborator Author

Addressing in #81

DanWaxman pushed a commit that referenced this pull request Feb 7, 2026
Before, there was no way to override the record site to `True` if the size was big enough. This instead uses the size-based decisions as defaults.
@DanWaxman DanWaxman deleted the ml-add-filter-sites branch March 11, 2026 16:10
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.

2 participants