bayinx 0.3.9__py3-none-any.whl → 0.3.11__py3-none-any.whl

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.
@@ -171,11 +171,11 @@ class Variational(eqx.Module, Generic[M]):
171
171
  # Evaluate posterior predictive
172
172
  @jax.jit
173
173
  @jax.vmap
174
- def evaluate(draw: Array, data: Any = None):
174
+ def evaluate(draw: Array):
175
175
  # Reconstruct model
176
176
  model: M = self._unflatten(draw)
177
177
 
178
178
  # Evaluate
179
179
  return func(model, data)
180
180
 
181
- return evaluate(draws, data)
181
+ return evaluate(draws)
@@ -1,5 +1,6 @@
1
1
  import jax.numpy as jnp
2
- from jaxtyping import Array, ArrayLike, Float
2
+ import jax.random as jr
3
+ from jaxtyping import Array, ArrayLike, Float, Key
3
4
 
4
5
  from bayinx.dists import posnormal
5
6
 
@@ -76,3 +77,40 @@ def logprob(
76
77
  evals = jnp.where(censored, posnormal.logccdf(x, mu, sigma), evals)
77
78
 
78
79
  return evals
80
+
81
+ def sample(
82
+ n: int,
83
+ mu: Float[ArrayLike, "..."],
84
+ sigma: Float[ArrayLike, "..."],
85
+ censor: Float[ArrayLike, "..."] = jnp.inf,
86
+ key: Key = jr.PRNGKey(0)
87
+ ) -> Float[Array, "..."]:
88
+ """
89
+ Sample from a right-censored positive Normal distribution.
90
+
91
+ # Parameters
92
+ - `n`: Number of draws to sample per-parameter.
93
+ - `mu`: The mean.
94
+ - `sigma`: The standard deviation.
95
+ - `censor`: The censor.
96
+
97
+ # Returns
98
+ Draws from a right-censored positive Normal distribution. The output will have the shape of (n,) + the broadcasted shapes of `mu`, `sigma`, and `censor`.
99
+ """
100
+ # Cast to Array
101
+ mu, sigma, censor = (
102
+ jnp.asarray(mu),
103
+ jnp.asarray(sigma),
104
+ jnp.asarray(censor),
105
+ )
106
+
107
+ # Derive shape
108
+ shape = (n,) + jnp.broadcast_shapes(mu.shape, sigma.shape, censor.shape)
109
+
110
+ # Draw from positive normal
111
+ draws = jr.truncated_normal(key, 0.0, jnp.inf, shape) * sigma + mu
112
+
113
+ # Censor values
114
+ draws = jnp.where(censor <= draws, censor, draws)
115
+
116
+ return draws
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bayinx
3
- Version: 0.3.9
3
+ Version: 0.3.11
4
4
  Summary: Bayesian Inference with JAX
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -7,7 +7,7 @@ bayinx/core/_constraint.py,sha256=Gx07ZT66VE2y-qZCmBDm3_y0wO4xQyslZW10Lec1_lM,76
7
7
  bayinx/core/_flow.py,sha256=3q4rKvATnbUpuj4ICUd4lIxu_3z7GRDuNujVhAku1X0,2342
8
8
  bayinx/core/_model.py,sha256=FJUyYVE9e2uTFamxtSMKY_VV2stiU2QF68Wl_7EAKEU,2895
9
9
  bayinx/core/_parameter.py,sha256=r20JedTW2lY0miNNh9y6LeIVAsGX1kP_rlGxphW_jZg,1080
10
- bayinx/core/_variational.py,sha256=X8o81b8vyU7vJxw8pZYH_nxc3u990tRUZgRhMNodNI4,5484
10
+ bayinx/core/_variational.py,sha256=yU5_fsolFD8De0mJptjRBVq5lA7rQsDvT3qmVGbW-gI,5460
11
11
  bayinx/dists/__init__.py,sha256=9DdPea7HAnBOzaV_4gM5noPX8YCb_p06d8PJvGfFy3Y,118
12
12
  bayinx/dists/bernoulli.py,sha256=xMV9BgtVX_1XkPdZ43q0meMIEkgMyuUPx--dyo6_DKs,1006
13
13
  bayinx/dists/gamma2.py,sha256=MuFudL2UTfk8HgWVofNaR36JTmUpmtxvg1Mifu98MvM,1567
@@ -18,7 +18,7 @@ bayinx/dists/censored/__init__.py,sha256=UVihMbQgAzCoOk_Zt5wrumPv5-acuTzV3TYMB-U
18
18
  bayinx/dists/censored/gamma2/__init__.py,sha256=GO3jIF1En0ZxYF5JqvC0helLAL6yv8-LG6Ih2NOUYQc,33
19
19
  bayinx/dists/censored/gamma2/r.py,sha256=dKAOYstufwgDwibQZHrJxA1d2gawj-7K3IkaCRCzNTg,2446
20
20
  bayinx/dists/censored/posnormal/__init__.py,sha256=GO3jIF1En0ZxYF5JqvC0helLAL6yv8-LG6Ih2NOUYQc,33
21
- bayinx/dists/censored/posnormal/r.py,sha256=hyuNR3HZY-Tgtso-WwjcZT6Ejxfyax_VKwIvVix44Jc,2362
21
+ bayinx/dists/censored/posnormal/r.py,sha256=Ypi6w_t53pAzRVzjcStx2RhozkAlCDLnQmgKykhpQQ4,3426
22
22
  bayinx/mhx/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
23
23
  bayinx/mhx/vi/__init__.py,sha256=2woNB5oZxfs8pZCkOfzriGahRFLzkLdkTj8_keTN0I0,205
24
24
  bayinx/mhx/vi/meanfield.py,sha256=Z7kGQAyp5iB8rEdjbwAbVTFH4GwxlTKDZFbdJ-FN5Vs,3739
@@ -29,7 +29,7 @@ bayinx/mhx/vi/flows/fullaffine.py,sha256=11y_A0oO3bkKDSz-EQ6Sf4Ec2M7vHZxw94EdvAD
29
29
  bayinx/mhx/vi/flows/planar.py,sha256=2I2WzIskl8MRpJkK13FQE3vSF-077qo8gRed_EL1Pn8,1920
30
30
  bayinx/mhx/vi/flows/radial.py,sha256=e0GfuO-CL8SVr3YnEfsxStpyKcJlFpzMyjMp3sa38hg,2503
31
31
  bayinx/mhx/vi/flows/sylvester.py,sha256=ppK0BmS_ThvrCEhJiP_-p-kj67TQHSlU_RUZpDbIhsQ,469
32
- bayinx-0.3.9.dist-info/METADATA,sha256=yn3AC0J8_xLnLYEEocDZyNRlyyuN2Ys8C--i9AFFYeY,3079
33
- bayinx-0.3.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
34
- bayinx-0.3.9.dist-info/licenses/LICENSE,sha256=VMhLhj5hx6VAENZBaNfXrmsNl7ov9uRh0jZ6D3ltgv4,1070
35
- bayinx-0.3.9.dist-info/RECORD,,
32
+ bayinx-0.3.11.dist-info/METADATA,sha256=0D6AlI-tcUBQiLQXnCBPgj62oy-LzOQxV93Rw2cv5cA,3080
33
+ bayinx-0.3.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
34
+ bayinx-0.3.11.dist-info/licenses/LICENSE,sha256=VMhLhj5hx6VAENZBaNfXrmsNl7ov9uRh0jZ6D3ltgv4,1070
35
+ bayinx-0.3.11.dist-info/RECORD,,