bayinx 0.3.15__tar.gz → 0.3.17__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.
Files changed (43) hide show
  1. {bayinx-0.3.15 → bayinx-0.3.17}/PKG-INFO +1 -1
  2. {bayinx-0.3.15 → bayinx-0.3.17}/pyproject.toml +2 -2
  3. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/_variational.py +25 -9
  4. {bayinx-0.3.15 → bayinx-0.3.17}/tests/test_predictive.py +5 -1
  5. {bayinx-0.3.15 → bayinx-0.3.17}/.github/workflows/release_and_publish.yml +0 -0
  6. {bayinx-0.3.15 → bayinx-0.3.17}/.gitignore +0 -0
  7. {bayinx-0.3.15 → bayinx-0.3.17}/LICENSE +0 -0
  8. {bayinx-0.3.15 → bayinx-0.3.17}/README.md +0 -0
  9. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/__init__.py +0 -0
  10. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/constraints/__init__.py +0 -0
  11. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/constraints/lower.py +0 -0
  12. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/__init__.py +0 -0
  13. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/_constraint.py +0 -0
  14. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/_flow.py +0 -0
  15. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/_model.py +0 -0
  16. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/_optimization.py +0 -0
  17. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/core/_parameter.py +0 -0
  18. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/__init__.py +0 -0
  19. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/bernoulli.py +0 -0
  20. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/censored/__init__.py +0 -0
  21. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/censored/gamma2/__init__.py +0 -0
  22. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/censored/gamma2/r.py +0 -0
  23. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/censored/posnormal/__init__.py +0 -0
  24. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/censored/posnormal/r.py +0 -0
  25. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/gamma2.py +0 -0
  26. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/normal.py +0 -0
  27. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/posnormal.py +0 -0
  28. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/dists/uniform.py +0 -0
  29. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/__init__.py +0 -0
  30. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/opt/__init__.py +0 -0
  31. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/__init__.py +0 -0
  32. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/flows/__init__.py +0 -0
  33. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/flows/fullaffine.py +0 -0
  34. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/flows/planar.py +0 -0
  35. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/flows/radial.py +0 -0
  36. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/flows/sylvester.py +0 -0
  37. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/meanfield.py +0 -0
  38. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/normalizing_flow.py +0 -0
  39. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/mhx/vi/standard.py +0 -0
  40. {bayinx-0.3.15 → bayinx-0.3.17}/src/bayinx/py.typed +0 -0
  41. {bayinx-0.3.15 → bayinx-0.3.17}/tests/__init__.py +0 -0
  42. {bayinx-0.3.15 → bayinx-0.3.17}/tests/test_variational.py +0 -0
  43. {bayinx-0.3.15 → bayinx-0.3.17}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bayinx
3
- Version: 0.3.15
3
+ Version: 0.3.17
4
4
  Summary: Bayesian Inference with JAX
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "bayinx"
3
- version = "0.3.15"
3
+ version = "0.3.17"
4
4
  description = "Bayesian Inference with JAX"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -19,7 +19,7 @@ build-backend = "hatchling.build"
19
19
  addopts = "-q --benchmark-min-rounds=30 --benchmark-columns=rounds,mean,median,stddev --benchmark-group-by=func"
20
20
 
21
21
  [tool.bumpversion]
22
- current_version = "0.3.15"
22
+ current_version = "0.3.17"
23
23
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
24
24
  serialize = ["{major}.{minor}.{patch}"]
25
25
  search = "{current_version}"
@@ -175,17 +175,33 @@ class Variational(eqx.Module, Generic[M]):
175
175
  data: Any = None,
176
176
  key: Key = jr.PRNGKey(0),
177
177
  ) -> Array:
178
- # Sample draws from the variational approximation
179
- draws: Array = self.sample(n, key)
178
+ # Sample a single draw to evaluate shape of output
179
+ draw: Array = self.sample(1, key)[0]
180
+ output: Array = func(self._unflatten(draw), data)
181
+
182
+ # Allocate space for results
183
+ results: Array = jnp.zeros((n,) + output.shape, dtype=output.dtype)
184
+
185
+ @eqx.filter_jit
186
+ def body_fun(i: int, state: Tuple[Key, Array]) -> Tuple[Key, Array]:
187
+ # Unpack state
188
+ key, results = state
189
+
190
+ # Update PRNG key
191
+ next, key = jr.split(key)
192
+
193
+ # Draw from variational
194
+ draw: Array = self.sample(1, key)
180
195
 
181
- # Evaluate posterior predictive
182
- @jax.jit
183
- @jax.vmap
184
- def evaluate(draw: Array):
185
196
  # Reconstruct model
186
197
  model: M = self._unflatten(draw)
187
198
 
188
- # Evaluate
189
- return func(model, data)
199
+ # Update results with output
200
+ results = results.at[i].set(func(model, data))
201
+
202
+ return next, results
203
+
204
+ # Evaluate draws
205
+ results: Array = jax.lax.fori_loop(0, n, body_fun, (key, results))[1]
190
206
 
191
- return evaluate(draws)
207
+ return results
@@ -10,6 +10,8 @@ from bayinx.mhx.vi import Standard
10
10
 
11
11
  class NormalDist(Model):
12
12
  x: Parameter[Array]
13
+ other: str = "hi"
14
+ other2: float = 10.0
13
15
 
14
16
  def __init__(self):
15
17
  self.x = Parameter(jnp.array([0.0, 0.0]))
@@ -33,9 +35,11 @@ def test_predictive():
33
35
 
34
36
  # Posterior predictive function
35
37
  def extract_first_x(model: NormalDist, data: Any = None) -> Array:
36
- return model.x()[0]
38
+ return model.x()
37
39
 
38
40
  # Sample from posterior
39
41
  first_x_samples: Array = vari.posterior_predictive(extract_first_x, 1000)
40
42
 
41
43
  assert abs(first_x_samples.mean()) < 0.1 and abs(first_x_samples.var() - 1.0) < 0.1
44
+
45
+ # todo: make test for data argument
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes