pymc-extras 0.2.4__py3-none-any.whl → 0.2.6__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.
Files changed (69) hide show
  1. pymc_extras/__init__.py +6 -4
  2. pymc_extras/distributions/__init__.py +2 -0
  3. pymc_extras/distributions/continuous.py +3 -2
  4. pymc_extras/distributions/discrete.py +3 -1
  5. pymc_extras/distributions/transforms/__init__.py +3 -0
  6. pymc_extras/distributions/transforms/partial_order.py +227 -0
  7. pymc_extras/inference/__init__.py +4 -2
  8. pymc_extras/inference/find_map.py +62 -17
  9. pymc_extras/inference/fit.py +6 -4
  10. pymc_extras/inference/laplace.py +14 -8
  11. pymc_extras/inference/pathfinder/lbfgs.py +49 -13
  12. pymc_extras/inference/pathfinder/pathfinder.py +89 -103
  13. pymc_extras/statespace/core/statespace.py +191 -52
  14. pymc_extras/statespace/filters/distributions.py +15 -16
  15. pymc_extras/statespace/filters/kalman_filter.py +1 -18
  16. pymc_extras/statespace/filters/kalman_smoother.py +2 -6
  17. pymc_extras/statespace/models/ETS.py +10 -0
  18. pymc_extras/statespace/models/SARIMAX.py +26 -5
  19. pymc_extras/statespace/models/VARMAX.py +12 -2
  20. pymc_extras/statespace/models/structural.py +18 -5
  21. pymc_extras/statespace/utils/data_tools.py +24 -9
  22. pymc_extras-0.2.6.dist-info/METADATA +318 -0
  23. pymc_extras-0.2.6.dist-info/RECORD +65 -0
  24. {pymc_extras-0.2.4.dist-info → pymc_extras-0.2.6.dist-info}/WHEEL +1 -2
  25. pymc_extras/version.py +0 -11
  26. pymc_extras/version.txt +0 -1
  27. pymc_extras-0.2.4.dist-info/METADATA +0 -110
  28. pymc_extras-0.2.4.dist-info/RECORD +0 -105
  29. pymc_extras-0.2.4.dist-info/top_level.txt +0 -2
  30. tests/__init__.py +0 -13
  31. tests/distributions/__init__.py +0 -19
  32. tests/distributions/test_continuous.py +0 -185
  33. tests/distributions/test_discrete.py +0 -210
  34. tests/distributions/test_discrete_markov_chain.py +0 -258
  35. tests/distributions/test_multivariate.py +0 -304
  36. tests/model/__init__.py +0 -0
  37. tests/model/marginal/__init__.py +0 -0
  38. tests/model/marginal/test_distributions.py +0 -132
  39. tests/model/marginal/test_graph_analysis.py +0 -182
  40. tests/model/marginal/test_marginal_model.py +0 -967
  41. tests/model/test_model_api.py +0 -38
  42. tests/statespace/__init__.py +0 -0
  43. tests/statespace/test_ETS.py +0 -411
  44. tests/statespace/test_SARIMAX.py +0 -405
  45. tests/statespace/test_VARMAX.py +0 -184
  46. tests/statespace/test_coord_assignment.py +0 -116
  47. tests/statespace/test_distributions.py +0 -270
  48. tests/statespace/test_kalman_filter.py +0 -326
  49. tests/statespace/test_representation.py +0 -175
  50. tests/statespace/test_statespace.py +0 -872
  51. tests/statespace/test_statespace_JAX.py +0 -156
  52. tests/statespace/test_structural.py +0 -836
  53. tests/statespace/utilities/__init__.py +0 -0
  54. tests/statespace/utilities/shared_fixtures.py +0 -9
  55. tests/statespace/utilities/statsmodel_local_level.py +0 -42
  56. tests/statespace/utilities/test_helpers.py +0 -310
  57. tests/test_blackjax_smc.py +0 -222
  58. tests/test_find_map.py +0 -103
  59. tests/test_histogram_approximation.py +0 -109
  60. tests/test_laplace.py +0 -265
  61. tests/test_linearmodel.py +0 -208
  62. tests/test_model_builder.py +0 -306
  63. tests/test_pathfinder.py +0 -203
  64. tests/test_pivoted_cholesky.py +0 -24
  65. tests/test_printing.py +0 -98
  66. tests/test_prior_from_trace.py +0 -172
  67. tests/test_splines.py +0 -77
  68. tests/utils.py +0 -0
  69. {pymc_extras-0.2.4.dist-info → pymc_extras-0.2.6.dist-info/licenses}/LICENSE +0 -0
@@ -1,175 +0,0 @@
1
- import unittest
2
-
3
- import numpy as np
4
- import pytensor
5
- import pytensor.tensor as pt
6
-
7
- from numpy.testing import assert_allclose
8
-
9
- from pymc_extras.statespace.core.representation import PytensorRepresentation
10
- from tests.statespace.utilities.shared_fixtures import TEST_SEED
11
- from tests.statespace.utilities.test_helpers import fast_eval, make_test_inputs
12
-
13
- floatX = pytensor.config.floatX
14
- atol = 1e-12 if floatX == "float64" else 1e-6
15
-
16
-
17
- def unpack_ssm_dims(ssm):
18
- p = ssm.k_endog
19
- m = ssm.k_states
20
- r = ssm.k_posdef
21
-
22
- return p, m, r
23
-
24
-
25
- class BasicFunctionality(unittest.TestCase):
26
- def setUp(self):
27
- self.rng = np.random.default_rng(TEST_SEED)
28
-
29
- def test_numpy_to_pytensor(self):
30
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1)
31
- X = np.eye(5)
32
- X_pt = ssm._numpy_to_pytensor("transition", X)
33
- self.assertTrue(isinstance(X_pt, pt.TensorVariable))
34
- assert_allclose(ssm["transition"].type.shape, X.shape)
35
-
36
- assert ssm["transition"].name == "transition"
37
-
38
- def test_default_shapes_full_rank(self):
39
- ssm = PytensorRepresentation(k_endog=5, k_states=5, k_posdef=5)
40
- p, m, r = unpack_ssm_dims(ssm)
41
-
42
- assert_allclose(ssm["design"].type.shape, (p, m))
43
- assert_allclose(ssm["transition"].type.shape, (m, m))
44
- assert_allclose(ssm["selection"].type.shape, (m, r))
45
- assert_allclose(ssm["state_cov"].type.shape, (r, r))
46
- assert_allclose(ssm["obs_cov"].type.shape, (p, p))
47
-
48
- def test_default_shapes_low_rank(self):
49
- ssm = PytensorRepresentation(k_endog=5, k_states=5, k_posdef=2)
50
- p, m, r = unpack_ssm_dims(ssm)
51
-
52
- assert_allclose(ssm["design"].type.shape, (p, m))
53
- assert_allclose(ssm["transition"].type.shape, (m, m))
54
- assert_allclose(ssm["selection"].type.shape, (m, r))
55
- assert_allclose(ssm["state_cov"].type.shape, (r, r))
56
- assert_allclose(ssm["obs_cov"].type.shape, (p, p))
57
-
58
- def test_matrix_assignment(self):
59
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=2)
60
-
61
- ssm["design", 0, 0] = 3.0
62
- ssm["transition", 0, :] = 2.7
63
- ssm["selection", -1, -1] = 9.9
64
-
65
- assert_allclose(fast_eval(ssm["design"][0, 0]), 3.0, atol=atol)
66
- assert_allclose(fast_eval(ssm["transition"][0, :]), 2.7, atol=atol)
67
- assert_allclose(fast_eval(ssm["selection"][-1, -1]), 9.9, atol=atol)
68
-
69
- assert ssm["design"].name == "design"
70
- assert ssm["transition"].name == "transition"
71
- assert ssm["selection"].name == "selection"
72
-
73
- def test_build_representation_from_data(self):
74
- p, m, r, n = 3, 6, 1, 10
75
- inputs = [data, a0, P0, c, d, T, Z, R, H, Q] = make_test_inputs(
76
- p, m, r, n, self.rng, missing_data=0
77
- )
78
-
79
- ssm = PytensorRepresentation(
80
- k_endog=p,
81
- k_states=m,
82
- k_posdef=r,
83
- design=Z,
84
- transition=T,
85
- selection=R,
86
- state_cov=Q,
87
- obs_cov=H,
88
- initial_state=a0,
89
- initial_state_cov=P0,
90
- state_intercept=c,
91
- obs_intercept=d,
92
- )
93
-
94
- names = [
95
- "initial_state",
96
- "initial_state_cov",
97
- "state_intercept",
98
- "obs_intercept",
99
- "transition",
100
- "design",
101
- "selection",
102
- "obs_cov",
103
- "state_cov",
104
- ]
105
-
106
- for name, X in zip(names, inputs[1:]):
107
- assert_allclose(X, fast_eval(ssm[name]), err_msg=name)
108
-
109
- for name, X in zip(names, inputs[1:]):
110
- assert ssm[name].name == name
111
- assert_allclose(ssm[name].type.shape, X.shape, err_msg=f"{name} shape test")
112
-
113
- def test_assign_time_varying_matrices(self):
114
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=2)
115
- n = 10
116
-
117
- ssm["design", 0, 0] = 3.0
118
- ssm["transition", 0, :] = 2.7
119
- ssm["selection", -1, -1] = 9.9
120
-
121
- ssm["state_intercept"] = np.zeros((n, 5))
122
- ssm["state_intercept", :, 0] = np.arange(n)
123
-
124
- assert_allclose(fast_eval(ssm["design"][0, 0]), 3.0, atol=atol)
125
- assert_allclose(fast_eval(ssm["transition"][0, :]), 2.7, atol=atol)
126
- assert_allclose(fast_eval(ssm["selection"][-1, -1]), 9.9, atol=atol)
127
- assert_allclose(fast_eval(ssm["state_intercept"][:, 0]), np.arange(n), atol=atol)
128
-
129
- def test_invalid_key_name_raises(self):
130
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1)
131
- with self.assertRaises(IndexError) as e:
132
- X = ssm["invalid_key"]
133
- msg = str(e.exception)
134
- self.assertEqual(msg, "invalid_key is an invalid state space matrix name")
135
-
136
- def test_non_string_key_raises(self):
137
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1)
138
- with self.assertRaises(IndexError) as e:
139
- X = ssm[0]
140
- msg = str(e.exception)
141
- self.assertEqual(msg, "First index must the name of a valid state space matrix.")
142
-
143
- def test_invalid_key_tuple_raises(self):
144
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1)
145
- with self.assertRaises(IndexError) as e:
146
- X = ssm[0, 1, 1]
147
- msg = str(e.exception)
148
- self.assertEqual(msg, "First index must the name of a valid state space matrix.")
149
-
150
- def test_slice_statespace_matrix(self):
151
- T = np.eye(5)
152
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1, transition=T)
153
- T_out = ssm["transition", :3, :]
154
- assert_allclose(T[:3], fast_eval(T_out))
155
-
156
- def test_update_matrix_via_key(self):
157
- T = np.eye(5)
158
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1)
159
- ssm["transition"] = T
160
-
161
- assert_allclose(T, fast_eval(ssm["transition"]))
162
-
163
- def test_update_matrix_with_invalid_shape_raises(self):
164
- T = np.eye(10)
165
- ssm = PytensorRepresentation(k_endog=3, k_states=5, k_posdef=1)
166
- with self.assertRaises(ValueError) as e:
167
- ssm["transition"] = T
168
- msg = str(e.exception)
169
- self.assertEqual(
170
- msg, "The last two dimensions of transition must be (5, 5), found (10, 10)"
171
- )
172
-
173
-
174
- if __name__ == "__main__":
175
- unittest.main()