cuthbertlib 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/PKG-INFO +1 -1
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/autodiff.py +22 -9
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/pyproject.toml +1 -1
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/.gitignore +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/discrete/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/discrete/filtering.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/discrete/smoothing.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/ensemble_kalman/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/ensemble_kalman/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/ensemble_kalman/filtering.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/ensemble_kalman/localization.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/ensemble_kalman/smoothing.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/kalman/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/kalman/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/kalman/filtering.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/kalman/generate.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/kalman/sampling.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/kalman/smoothing.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linalg/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linalg/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linalg/collect_nans_chol.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linalg/marginal_sqrt_cov.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linalg/symmetric_inv_sqrt.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linalg/tria.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linearize/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linearize/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linearize/log_density.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linearize/moments.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/linearize/taylor.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/common.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/cubature.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/gauss_hermite.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/linearize.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/unscented.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/quadrature/utils.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/adaptive.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/killing.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/multinomial.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/no_resampling.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/protocols.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/systematic.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/resampling/utils.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/ess.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/smoothing/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/smoothing/exact_sampling.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/smoothing/mcmc.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/smoothing/protocols.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/smc/smoothing/tracing.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/stats/README.md +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/stats/__init__.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/stats/multivariate_normal.py +0 -0
- {cuthbertlib-0.1.1 → cuthbertlib-0.1.2}/cuthbertlib/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cuthbertlib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Atomic building blocks for state-space model inference with JAX
|
|
5
5
|
Author-email: Sam Duffield <s@mduffield.com>, Sahel Iqbal <sahel13miqbal@proton.me>, Adrien Corenflos <adrien.corenflos.stats@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -6,6 +6,7 @@ This can be wrapped around a resampling scheme such as multinomial or systematic
|
|
|
6
6
|
resampling.
|
|
7
7
|
|
|
8
8
|
See [Scibior and Wood (2021)](https://arxiv.org/abs/2106.10314) for more details.
|
|
9
|
+
For the discount, see [Tan et al.](https://arxiv.org/abs/2407.03085v2).
|
|
9
10
|
"""
|
|
10
11
|
|
|
11
12
|
from functools import wraps
|
|
@@ -15,19 +16,31 @@ import jax.numpy as jnp
|
|
|
15
16
|
|
|
16
17
|
from cuthbertlib.resampling.protocols import Resampling
|
|
17
18
|
from cuthbertlib.resampling.utils import apply_resampling_indices
|
|
18
|
-
from cuthbertlib.types import
|
|
19
|
+
from cuthbertlib.types import (
|
|
20
|
+
Array,
|
|
21
|
+
ArrayLike,
|
|
22
|
+
ArrayTree,
|
|
23
|
+
ArrayTreeLike,
|
|
24
|
+
ScalarArrayLike,
|
|
25
|
+
)
|
|
19
26
|
|
|
20
27
|
|
|
21
|
-
def stop_gradient_decorator(
|
|
28
|
+
def stop_gradient_decorator(
|
|
29
|
+
func: Resampling, alpha: ScalarArrayLike = 1.0
|
|
30
|
+
) -> Resampling:
|
|
22
31
|
"""Wrap a Resampling function to use stop gradient resampling.
|
|
23
32
|
|
|
24
33
|
Args:
|
|
25
34
|
func: A resampling function with signature
|
|
26
35
|
(key, logits, positions, n) -> (indices, logits_out, positions_out).
|
|
36
|
+
alpha: A scalar multiplier for the log-weight correction, clipped to [0, 1].
|
|
37
|
+
The default, 1, preserves the original stop-gradient estimator;
|
|
38
|
+
0 removes the correction.
|
|
27
39
|
|
|
28
40
|
Returns:
|
|
29
41
|
A Resampling function implementing stop gradient resampling.
|
|
30
42
|
"""
|
|
43
|
+
alpha = jnp.clip(jnp.broadcast_to(alpha, ()), 0, 1)
|
|
31
44
|
# Build a descriptive docstring that includes the wrapped function doc
|
|
32
45
|
wrapped_doc = func.__doc__ or ""
|
|
33
46
|
doc = f"""
|
|
@@ -35,9 +48,11 @@ def stop_gradient_decorator(func: Resampling) -> Resampling:
|
|
|
35
48
|
|
|
36
49
|
This wrapper will call the provided resampling function, and then apply
|
|
37
50
|
the stop gradient trick of [Scibior and Wood (2021)](https://arxiv.org/abs/2106.10314).
|
|
38
|
-
|
|
51
|
+
With alpha=1, resulting estimates of the score function (i.e., the gradient of the
|
|
39
52
|
log-likelihood with respect to model parameters) are unbiased,
|
|
40
|
-
corresponding to the classical Fisher estimate.
|
|
53
|
+
corresponding to the classical Fisher estimate. Values below 1 discount
|
|
54
|
+
the log-weight correction at resampling as in [Tan et al.](https://arxiv.org/abs/2407.03085v2).
|
|
55
|
+
With alpha=0, the correction is zero and gradients still pass through the selected particles.
|
|
41
56
|
|
|
42
57
|
Wrapped resampler documentation:
|
|
43
58
|
{wrapped_doc}
|
|
@@ -51,11 +66,9 @@ def stop_gradient_decorator(func: Resampling) -> Resampling:
|
|
|
51
66
|
key, jax.lax.stop_gradient(logits), positions, n
|
|
52
67
|
)
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- jax.lax.stop_gradient(apply_resampling_indices(logits, idx_base))
|
|
58
|
-
)
|
|
69
|
+
selected = apply_resampling_indices(logits, idx_base)
|
|
70
|
+
correction = alpha * (selected - jax.lax.stop_gradient(selected))
|
|
71
|
+
logits = jnp.asarray(logits_base + correction)
|
|
59
72
|
return idx_base, logits, positions_base
|
|
60
73
|
|
|
61
74
|
# Attach the composed docstring and return a jitted version
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|