-
-
Notifications
You must be signed in to change notification settings - Fork 177
Adding Latent SDE #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anh-tong
wants to merge
12
commits into
patrick-kidger:main
Choose a base branch
from
anh-tong:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,266
−53
Open
Adding Latent SDE #104
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0378b23
+ small change in KL divergence computation
anh-tong dbed128
minor fix
anh-tong 71e3ccc
fix description
anh-tong 47c87ec
check out the original notebook and make small doc change
anh-tong 1513384
kl divergence via abstractions of control term
anh-tong 9217c06
minor fix
anh-tong a59a111
neural vae lorenz data (in progress)
anh-tong 7ab9bb0
remove used imports and refactor test
anh-tong 92a1842
complete test neural sde vae
anh-tong da636e5
sde KL with block diagonal diffusion
anh-tong d8a68b2
sync fork and rename jax.tree_util
anh-tong dc5fde4
fix typo
anh-tong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,11 @@ | |
|
|
||
|
|
||
| def _kl(drift1, drift2, diffusion): | ||
| inv_diffusion = jnp.linalg.pinv(diffusion) | ||
| scale = inv_diffusion @ (drift1 - drift2) | ||
| if diffusion.ndim == 1: | ||
| scale = (drift1 - drift2) / diffusion | ||
| else: | ||
| inv_diffusion = jnp.linalg.pinv(diffusion) | ||
| scale = inv_diffusion @ (drift1 - drift2) | ||
| return 0.5 * jnp.sum(scale**2) | ||
|
|
||
|
|
||
|
|
@@ -23,7 +26,7 @@ class _AugDrift(eqx.Module): | |
| def __call__(self, t, y, args): | ||
| y, _ = y | ||
| context = self.context(t) | ||
| aug_y = jnp.concatenate([y, context], axis=-1) | ||
| aug_y = jnp.concatenate([y, context], axis=-1) if context is not None else y | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: flipping the |
||
| drift1 = self.drift1(t, aug_y, args) | ||
| drift2 = self.drift2(t, y, args) | ||
| diffusion = self.diffusion(t, y, args) | ||
|
|
@@ -66,6 +69,8 @@ def sde_kl_divergence( | |
| bm: AbstractBrownianPath, | ||
| ): | ||
| aug_y0 = (y0, 0.0) | ||
| if context is None: | ||
| context = lambda t: None | ||
| return ( | ||
| _AugDrift(drift1, drift2, diffusion, context), | ||
| _AugDiffusion(diffusion), | ||
|
|
||
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my original code here in
sde_kl_divergencewas pretty hacky and not library-ready, and I think it'll still need some more work to get ready.In particular I think it would make most sense to operate the level of terms. This would allow for abstracting over the kind of diffusion used -- e.g.
ControlTermversusWeaklyDiagonalControlTermetc. -- rather than the current vector-field-based approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may need to bump the version number. Here, I have changed
sde_kl_divergenceAPI from taking drift functions, a diffusion function ... into taking twoMultiTerm. Although there is a duplication in control terms as they share the same, this sounds more natural as we compare two SDEs.