pymc-extras 0.3.1__tar.gz → 0.4.0__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.
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/PKG-INFO +5 -4
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/_version.py +2 -2
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/conda-envs/environment-test.yml +4 -3
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/laplace_approx/find_map.py +12 -5
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/laplace_approx/idata.py +4 -3
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/laplace_approx/laplace.py +6 -4
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/pathfinder/pathfinder.py +1 -2
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/__init__.py +21 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components/autoregressive.py +188 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components/cycle.py +305 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components/level_trend.py +257 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components/measurement_error.py +137 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components/regression.py +228 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components/seasonality.py +445 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/core.py +900 -0
- pymc_extras-0.4.0/pymc_extras/statespace/models/structural/utils.py +16 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/models/utilities.py +285 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/utils/constants.py +4 -4
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/utils/data_tools.py +3 -2
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pyproject.toml +4 -3
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/inference/laplace_approx/test_find_map.py +34 -7
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/inference/laplace_approx/test_laplace.py +76 -1
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/core/test_statespace.py +240 -13
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/core/test_statespace_JAX.py +1 -1
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/filters/test_distributions.py +6 -6
- pymc_extras-0.4.0/tests/statespace/models/structural/components/__init__.py +0 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/components/test_autoregressive.py +132 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/components/test_cycle.py +288 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/components/test_level_trend.py +158 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/components/test_measurement_error.py +32 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/components/test_regression.py +237 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/components/test_seasonality.py +439 -0
- pymc_extras-0.4.0/tests/statespace/models/structural/conftest.py +29 -0
- pymc_extras-0.3.1/tests/statespace/models/test_structural.py → pymc_extras-0.4.0/tests/statespace/models/structural/test_against_statsmodels.py +27 -332
- pymc_extras-0.4.0/tests/statespace/models/structural/test_core.py +190 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/models/test_SARIMAX.py +6 -6
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/models/test_VARMAX.py +1 -1
- pymc_extras-0.4.0/tests/statespace/models/test_utilities.py +298 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/test_utilities.py +3 -2
- pymc_extras-0.4.0/tests/statespace/utils/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/utils/test_coord_assignment.py +6 -6
- pymc_extras-0.4.0/tests/utils.py +0 -0
- pymc_extras-0.3.1/pymc_extras/statespace/models/structural.py +0 -1679
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/.gitignore +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/.gitpod.yml +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/.pre-commit-config.yaml +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/.readthedocs.yaml +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/CODE_OF_CONDUCT.md +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/CONTRIBUTING.md +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/LICENSE +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/README.md +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/codecov.yml +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/.nojekyll +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/Makefile +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/_templates/autosummary/base.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/_templates/autosummary/class.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/api_reference.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/conf.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/index.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/make.bat +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/statespace/core.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/statespace/filters.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/statespace/models/structural.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/docs/statespace/models.rst +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/deserialize.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/continuous.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/discrete.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/histogram_utils.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/multivariate/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/multivariate/r2d2m2cp.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/timeseries.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/transforms/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/distributions/transforms/partial_order.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/gp/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/gp/latent_approx.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/fit.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/laplace_approx/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/laplace_approx/scipy_interface.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/pathfinder/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/pathfinder/importance_sampling.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/pathfinder/lbfgs.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/smc/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/inference/smc/sampling.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/linearmodel.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/marginal/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/marginal/distributions.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/marginal/graph_analysis.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/marginal/marginal_model.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/model_api.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/transforms/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model/transforms/autoreparam.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/model_builder.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/preprocessing/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/preprocessing/standard_scaler.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/printing.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/prior.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/core/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/core/compile.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/core/representation.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/core/statespace.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/filters/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/filters/distributions.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/filters/kalman_filter.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/filters/kalman_smoother.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/filters/utilities.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/models/ETS.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/models/SARIMAX.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/models/VARMAX.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/models/__init__.py +0 -0
- {pymc_extras-0.3.1/pymc_extras/statespace/utils → pymc_extras-0.4.0/pymc_extras/statespace/models/structural/components}/__init__.py +0 -0
- {pymc_extras-0.3.1/tests/inference → pymc_extras-0.4.0/pymc_extras/statespace/utils}/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/statespace/utils/coord_tools.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/utils/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/utils/linear_cg.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/utils/model_equivalence.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/utils/prior.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/pymc_extras/utils/spline.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/conftest.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/distributions/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/distributions/test_continuous.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/distributions/test_discrete.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/distributions/test_discrete_markov_chain.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/distributions/test_multivariate.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/distributions/test_transform.py +0 -0
- {pymc_extras-0.3.1/tests/inference/laplace_approx → pymc_extras-0.4.0/tests/inference}/__init__.py +0 -0
- {pymc_extras-0.3.1/tests/model → pymc_extras-0.4.0/tests/inference/laplace_approx}/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/inference/laplace_approx/test_idata.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/inference/laplace_approx/test_scipy_interface.py +0 -0
- {pymc_extras-0.3.1/tests/model/marginal → pymc_extras-0.4.0/tests/model}/__init__.py +0 -0
- {pymc_extras-0.3.1/tests/statespace → pymc_extras-0.4.0/tests/model/marginal}/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/model/marginal/test_distributions.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/model/marginal/test_graph_analysis.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/model/marginal/test_marginal_model.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/model/test_model_api.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/model/transforms/test_autoreparam.py +0 -0
- {pymc_extras-0.3.1/tests/statespace/core → pymc_extras-0.4.0/tests/statespace}/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/_data/airpass.csv +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/_data/airpassangers.csv +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/_data/nile.csv +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/_data/statsmodels_macrodata_processed.csv +0 -0
- {pymc_extras-0.3.1/tests/statespace/filters → pymc_extras-0.4.0/tests/statespace/core}/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/core/test_representation.py +0 -0
- {pymc_extras-0.3.1/tests/statespace/models → pymc_extras-0.4.0/tests/statespace/filters}/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/filters/test_kalman_filter.py +0 -0
- {pymc_extras-0.3.1/tests/statespace/utils → pymc_extras-0.4.0/tests/statespace/models}/__init__.py +0 -0
- /pymc_extras-0.3.1/tests/utils.py → /pymc_extras-0.4.0/tests/statespace/models/structural/__init__.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/models/test_ETS.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/shared_fixtures.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/statespace/statsmodel_local_level.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_blackjax_smc.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_deserialize.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_histogram_approximation.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_linearmodel.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_model_builder.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_pathfinder.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_printing.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_prior.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_prior_from_trace.py +0 -0
- {pymc_extras-0.3.1 → pymc_extras-0.4.0}/tests/test_splines.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pymc-extras
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: A home for new additions to PyMC, which may include unusual probability distribitions, advanced model fitting algorithms, or any code that may be inappropriate to include in the pymc repository, but may want to be made available to users.
|
|
5
5
|
Project-URL: Documentation, https://pymc-extras.readthedocs.io/
|
|
6
6
|
Project-URL: Repository, https://github.com/pymc-devs/pymc-extras.git
|
|
@@ -232,9 +232,11 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
232
232
|
Classifier: Topic :: Scientific/Engineering
|
|
233
233
|
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
234
234
|
Requires-Python: >=3.11
|
|
235
|
-
Requires-Dist: better-optimize>=0.1.
|
|
235
|
+
Requires-Dist: better-optimize>=0.1.5
|
|
236
|
+
Requires-Dist: preliz>=0.20.0
|
|
236
237
|
Requires-Dist: pydantic>=2.0.0
|
|
237
|
-
Requires-Dist: pymc>=5.
|
|
238
|
+
Requires-Dist: pymc>=5.24.1
|
|
239
|
+
Requires-Dist: pytensor>=2.31.4
|
|
238
240
|
Requires-Dist: scikit-learn
|
|
239
241
|
Provides-Extra: complete
|
|
240
242
|
Requires-Dist: dask[complete]<2025.1.1; extra == 'complete'
|
|
@@ -245,7 +247,6 @@ Requires-Dist: xhistogram; extra == 'dask-histogram'
|
|
|
245
247
|
Provides-Extra: dev
|
|
246
248
|
Requires-Dist: blackjax; extra == 'dev'
|
|
247
249
|
Requires-Dist: dask[all]<2025.1.1; extra == 'dev'
|
|
248
|
-
Requires-Dist: preliz>=0.5.0; extra == 'dev'
|
|
249
250
|
Requires-Dist: pytest-mock; extra == 'dev'
|
|
250
251
|
Requires-Dist: pytest>=6.0; extra == 'dev'
|
|
251
252
|
Requires-Dist: statsmodels; extra == 'dev'
|
|
@@ -3,9 +3,10 @@ channels:
|
|
|
3
3
|
- conda-forge
|
|
4
4
|
- nodefaults
|
|
5
5
|
dependencies:
|
|
6
|
-
- pymc>=5.
|
|
6
|
+
- pymc>=5.24.1
|
|
7
|
+
- pytensor>=2.31.4
|
|
7
8
|
- scikit-learn
|
|
8
|
-
- better-optimize>=0.1.
|
|
9
|
+
- better-optimize>=0.1.5
|
|
9
10
|
- dask<2025.1.1
|
|
10
11
|
- xhistogram
|
|
11
12
|
- statsmodels
|
|
@@ -13,7 +14,7 @@ dependencies:
|
|
|
13
14
|
- pytest
|
|
14
15
|
- pytest-cov
|
|
15
16
|
- pydantic>=2.0.0
|
|
16
|
-
- preliz>=0.
|
|
17
|
+
- preliz>=0.20.0
|
|
17
18
|
- pip
|
|
18
19
|
- pip:
|
|
19
20
|
- jax
|
|
@@ -326,7 +326,7 @@ def find_MAP(
|
|
|
326
326
|
)
|
|
327
327
|
|
|
328
328
|
raveled_optimized = RaveledVars(optimizer_result.x, initial_params.point_map_info)
|
|
329
|
-
unobserved_vars = get_default_varnames(model.unobserved_value_vars, include_transformed)
|
|
329
|
+
unobserved_vars = get_default_varnames(model.unobserved_value_vars, include_transformed=True)
|
|
330
330
|
unobserved_vars_values = model.compile_fn(unobserved_vars, mode="FAST_COMPILE")(
|
|
331
331
|
DictToArrayBijection.rmap(raveled_optimized)
|
|
332
332
|
)
|
|
@@ -335,13 +335,20 @@ def find_MAP(
|
|
|
335
335
|
var.name: value for var, value in zip(unobserved_vars, unobserved_vars_values)
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
idata = map_results_to_inference_data(
|
|
339
|
-
|
|
338
|
+
idata = map_results_to_inference_data(
|
|
339
|
+
map_point=optimized_point, model=frozen_model, include_transformed=include_transformed
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
idata = add_fit_to_inference_data(
|
|
343
|
+
idata=idata, mu=raveled_optimized, H_inv=H_inv, model=frozen_model
|
|
344
|
+
)
|
|
345
|
+
|
|
340
346
|
idata = add_optimizer_result_to_inference_data(
|
|
341
|
-
idata, optimizer_result, method, raveled_optimized, model
|
|
347
|
+
idata=idata, result=optimizer_result, method=method, mu=raveled_optimized, model=model
|
|
342
348
|
)
|
|
349
|
+
|
|
343
350
|
idata = add_data_to_inference_data(
|
|
344
|
-
idata, progressbar=False, model=model, compile_kwargs=compile_kwargs
|
|
351
|
+
idata=idata, progressbar=False, model=model, compile_kwargs=compile_kwargs
|
|
345
352
|
)
|
|
346
353
|
|
|
347
354
|
return idata
|
|
@@ -59,6 +59,7 @@ def make_unpacked_variable_names(names: list[str], model: pm.Model) -> list[str]
|
|
|
59
59
|
def map_results_to_inference_data(
|
|
60
60
|
map_point: dict[str, float | int | np.ndarray],
|
|
61
61
|
model: pm.Model | None = None,
|
|
62
|
+
include_transformed: bool = True,
|
|
62
63
|
):
|
|
63
64
|
"""
|
|
64
65
|
Add the MAP point to an InferenceData object in the posterior group.
|
|
@@ -68,13 +69,13 @@ def map_results_to_inference_data(
|
|
|
68
69
|
|
|
69
70
|
Parameters
|
|
70
71
|
----------
|
|
71
|
-
idata: az.InferenceData
|
|
72
|
-
An InferenceData object to which the MAP point will be added.
|
|
73
72
|
map_point: dict
|
|
74
73
|
A dictionary containing the MAP point estimates for each variable. The keys should be the variable names, and
|
|
75
74
|
the values should be the corresponding MAP estimates.
|
|
76
75
|
model: Model, optional
|
|
77
76
|
A PyMC model. If None, the model is taken from the current model context.
|
|
77
|
+
include_transformed: bool
|
|
78
|
+
Whether to return transformed (unconstrained) variables in the constrained_posterior group. Default is True.
|
|
78
79
|
|
|
79
80
|
Returns
|
|
80
81
|
-------
|
|
@@ -118,7 +119,7 @@ def map_results_to_inference_data(
|
|
|
118
119
|
dims=dims,
|
|
119
120
|
)
|
|
120
121
|
|
|
121
|
-
if unconstrained_names:
|
|
122
|
+
if unconstrained_names and include_transformed:
|
|
122
123
|
unconstrained_posterior = az.from_dict(
|
|
123
124
|
posterior={
|
|
124
125
|
k: np.expand_dims(v, (0, 1))
|
|
@@ -302,7 +302,7 @@ def fit_laplace(
|
|
|
302
302
|
----------
|
|
303
303
|
model : pm.Model
|
|
304
304
|
The PyMC model to be fit. If None, the current model context is used.
|
|
305
|
-
|
|
305
|
+
optimize_method : str
|
|
306
306
|
The optimization method to use. Valid choices are: Nelder-Mead, Powell, CG, BFGS, L-BFGS-B, TNC, SLSQP,
|
|
307
307
|
trust-constr, dogleg, trust-ncg, trust-exact, trust-krylov, and basinhopping.
|
|
308
308
|
|
|
@@ -441,9 +441,11 @@ def fit_laplace(
|
|
|
441
441
|
.rename({"temp_chain": "chain", "temp_draw": "draw"})
|
|
442
442
|
)
|
|
443
443
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
444
|
+
if include_transformed:
|
|
445
|
+
idata.unconstrained_posterior = unstack_laplace_draws(
|
|
446
|
+
new_posterior.laplace_approximation.values, model, chains=chains, draws=draws
|
|
447
|
+
)
|
|
448
|
+
|
|
447
449
|
idata.posterior = new_posterior.drop_vars(
|
|
448
450
|
["laplace_approximation", "unpacked_variable_names"]
|
|
449
451
|
)
|
|
@@ -38,16 +38,15 @@ from pymc.blocking import DictToArrayBijection, RaveledVars
|
|
|
38
38
|
from pymc.initial_point import make_initial_point_fn
|
|
39
39
|
from pymc.model import modelcontext
|
|
40
40
|
from pymc.model.core import Point
|
|
41
|
+
from pymc.progress_bar import CustomProgress, default_progress_theme
|
|
41
42
|
from pymc.pytensorf import (
|
|
42
43
|
compile,
|
|
43
44
|
find_rng_nodes,
|
|
44
45
|
reseed_rngs,
|
|
45
46
|
)
|
|
46
47
|
from pymc.util import (
|
|
47
|
-
CustomProgress,
|
|
48
48
|
RandomSeed,
|
|
49
49
|
_get_seeds_per_chain,
|
|
50
|
-
default_progress_theme,
|
|
51
50
|
get_default_varnames,
|
|
52
51
|
)
|
|
53
52
|
from pytensor.compile.function.types import Function
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from pymc_extras.statespace.models.structural.components.autoregressive import (
|
|
2
|
+
AutoregressiveComponent,
|
|
3
|
+
)
|
|
4
|
+
from pymc_extras.statespace.models.structural.components.cycle import CycleComponent
|
|
5
|
+
from pymc_extras.statespace.models.structural.components.level_trend import LevelTrendComponent
|
|
6
|
+
from pymc_extras.statespace.models.structural.components.measurement_error import MeasurementError
|
|
7
|
+
from pymc_extras.statespace.models.structural.components.regression import RegressionComponent
|
|
8
|
+
from pymc_extras.statespace.models.structural.components.seasonality import (
|
|
9
|
+
FrequencySeasonality,
|
|
10
|
+
TimeSeasonality,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"LevelTrendComponent",
|
|
15
|
+
"MeasurementError",
|
|
16
|
+
"AutoregressiveComponent",
|
|
17
|
+
"TimeSeasonality",
|
|
18
|
+
"FrequencySeasonality",
|
|
19
|
+
"RegressionComponent",
|
|
20
|
+
"CycleComponent",
|
|
21
|
+
]
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytensor.tensor as pt
|
|
3
|
+
|
|
4
|
+
from pymc_extras.statespace.models.structural.core import Component
|
|
5
|
+
from pymc_extras.statespace.models.structural.utils import order_to_mask
|
|
6
|
+
from pymc_extras.statespace.utils.constants import AR_PARAM_DIM
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AutoregressiveComponent(Component):
|
|
10
|
+
r"""
|
|
11
|
+
Autoregressive timeseries component
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
order: int or sequence of int
|
|
16
|
+
|
|
17
|
+
If int, the number of lags to include in the model.
|
|
18
|
+
If a sequence, an array-like of zeros and ones indicating which lags to include in the model.
|
|
19
|
+
|
|
20
|
+
name: str, default "auto_regressive"
|
|
21
|
+
A name for this autoregressive component. Used to label dimensions and coordinates.
|
|
22
|
+
|
|
23
|
+
observed_state_names: list[str] | None, default None
|
|
24
|
+
List of strings for observed state labels. If None, defaults to ["data"].
|
|
25
|
+
|
|
26
|
+
Notes
|
|
27
|
+
-----
|
|
28
|
+
An autoregressive component can be thought of as a way o introducing serially correlated errors into the model.
|
|
29
|
+
The process is modeled:
|
|
30
|
+
|
|
31
|
+
.. math::
|
|
32
|
+
x_t = \sum_{i=1}^p \rho_i x_{t-i}
|
|
33
|
+
|
|
34
|
+
Where ``p``, the number of autoregressive terms to model, is the order of the process. By default, all lags up to
|
|
35
|
+
``p`` are included in the model. To disable lags, pass a list of zeros and ones to the ``order`` argumnet. For
|
|
36
|
+
example, ``order=[1, 1, 0, 1]`` would become:
|
|
37
|
+
|
|
38
|
+
.. math::
|
|
39
|
+
x_t = \rho_1 x_{t-1} + \rho_2 x_{t-1} + \rho_4 x_{t-1}
|
|
40
|
+
|
|
41
|
+
The coefficient :math:`\rho_3` has been constrained to zero.
|
|
42
|
+
|
|
43
|
+
.. warning:: This class is meant to be used as a component in a structural time series model. For modeling of
|
|
44
|
+
stationary processes with ARIMA, use ``statespace.BayesianSARIMA``.
|
|
45
|
+
|
|
46
|
+
Examples
|
|
47
|
+
--------
|
|
48
|
+
Model a timeseries as an AR(2) process with non-zero mean:
|
|
49
|
+
|
|
50
|
+
.. code:: python
|
|
51
|
+
|
|
52
|
+
from pymc_extras.statespace import structural as st
|
|
53
|
+
import pymc as pm
|
|
54
|
+
import pytensor.tensor as pt
|
|
55
|
+
|
|
56
|
+
trend = st.LevelTrendComponent(order=1, innovations_order=0)
|
|
57
|
+
ar = st.AutoregressiveComponent(2)
|
|
58
|
+
ss_mod = (trend + ar).build()
|
|
59
|
+
|
|
60
|
+
with pm.Model(coords=ss_mod.coords) as model:
|
|
61
|
+
P0 = pm.Deterministic('P0', pt.eye(ss_mod.k_states) * 10, dims=ss_mod.param_dims['P0'])
|
|
62
|
+
intitial_trend = pm.Normal('initial_trend', sigma=10, dims=ss_mod.param_dims['initial_trend'])
|
|
63
|
+
ar_params = pm.Normal('ar_params', dims=ss_mod.param_dims['ar_params'])
|
|
64
|
+
sigma_ar = pm.Exponential('sigma_ar', 1, dims=ss_mod.param_dims['sigma_ar'])
|
|
65
|
+
|
|
66
|
+
ss_mod.build_statespace_graph(data)
|
|
67
|
+
idata = pm.sample(nuts_sampler='numpyro')
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
order: int = 1,
|
|
74
|
+
name: str = "auto_regressive",
|
|
75
|
+
observed_state_names: list[str] | None = None,
|
|
76
|
+
):
|
|
77
|
+
if observed_state_names is None:
|
|
78
|
+
observed_state_names = ["data"]
|
|
79
|
+
|
|
80
|
+
k_posdef = k_endog = len(observed_state_names)
|
|
81
|
+
|
|
82
|
+
order = order_to_mask(order)
|
|
83
|
+
ar_lags = np.flatnonzero(order).ravel().astype(int) + 1
|
|
84
|
+
k_states = len(order)
|
|
85
|
+
|
|
86
|
+
self.order = order
|
|
87
|
+
self.ar_lags = ar_lags
|
|
88
|
+
|
|
89
|
+
super().__init__(
|
|
90
|
+
name=name,
|
|
91
|
+
k_endog=k_endog,
|
|
92
|
+
k_states=k_states * k_endog,
|
|
93
|
+
k_posdef=k_posdef,
|
|
94
|
+
measurement_error=True,
|
|
95
|
+
combine_hidden_states=True,
|
|
96
|
+
observed_state_names=observed_state_names,
|
|
97
|
+
obs_state_idxs=np.tile(np.r_[[1.0], np.zeros(k_states - 1)], k_endog),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def populate_component_properties(self):
|
|
101
|
+
k_states = self.k_states // self.k_endog # this is also the number of AR lags
|
|
102
|
+
|
|
103
|
+
self.state_names = [
|
|
104
|
+
f"L{i + 1}[{state_name}]"
|
|
105
|
+
for state_name in self.observed_state_names
|
|
106
|
+
for i in range(k_states)
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
self.shock_names = [f"{self.name}[{obs_name}]" for obs_name in self.observed_state_names]
|
|
110
|
+
self.param_names = [f"params_{self.name}", f"sigma_{self.name}"]
|
|
111
|
+
self.param_dims = {f"params_{self.name}": (f"lag_{self.name}",)}
|
|
112
|
+
self.coords = {f"lag_{self.name}": self.ar_lags.tolist()}
|
|
113
|
+
|
|
114
|
+
if self.k_endog > 1:
|
|
115
|
+
self.param_dims[f"params_{self.name}"] = (
|
|
116
|
+
f"endog_{self.name}",
|
|
117
|
+
AR_PARAM_DIM,
|
|
118
|
+
)
|
|
119
|
+
self.param_dims[f"sigma_{self.name}"] = (f"endog_{self.name}",)
|
|
120
|
+
|
|
121
|
+
self.coords[f"endog_{self.name}"] = self.observed_state_names
|
|
122
|
+
|
|
123
|
+
self.param_info = {
|
|
124
|
+
f"params_{self.name}": {
|
|
125
|
+
"shape": (k_states,) if self.k_endog == 1 else (self.k_endog, k_states),
|
|
126
|
+
"constraints": None,
|
|
127
|
+
"dims": (AR_PARAM_DIM,)
|
|
128
|
+
if self.k_endog == 1
|
|
129
|
+
else (
|
|
130
|
+
f"endog_{self.name}",
|
|
131
|
+
f"lag_{self.name}",
|
|
132
|
+
),
|
|
133
|
+
},
|
|
134
|
+
f"sigma_{self.name}": {
|
|
135
|
+
"shape": () if self.k_endog == 1 else (self.k_endog,),
|
|
136
|
+
"constraints": "Positive",
|
|
137
|
+
"dims": None if self.k_endog == 1 else (f"endog_{self.name}",),
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
def make_symbolic_graph(self) -> None:
|
|
142
|
+
k_endog = self.k_endog
|
|
143
|
+
k_states = self.k_states // k_endog
|
|
144
|
+
k_posdef = self.k_posdef
|
|
145
|
+
|
|
146
|
+
k_nonzero = int(sum(self.order))
|
|
147
|
+
ar_params = self.make_and_register_variable(
|
|
148
|
+
f"params_{self.name}", shape=(k_nonzero,) if k_endog == 1 else (k_endog, k_nonzero)
|
|
149
|
+
)
|
|
150
|
+
sigma_ar = self.make_and_register_variable(
|
|
151
|
+
f"sigma_{self.name}", shape=() if k_endog == 1 else (k_endog,)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
if k_endog == 1:
|
|
155
|
+
T = pt.eye(k_states, k=-1)
|
|
156
|
+
ar_idx = (np.zeros(k_nonzero, dtype="int"), np.nonzero(self.order)[0])
|
|
157
|
+
T = T[ar_idx].set(ar_params)
|
|
158
|
+
|
|
159
|
+
else:
|
|
160
|
+
transition_matrices = []
|
|
161
|
+
|
|
162
|
+
for i in range(k_endog):
|
|
163
|
+
T = pt.eye(k_states, k=-1)
|
|
164
|
+
ar_idx = (np.zeros(k_nonzero, dtype="int"), np.nonzero(self.order)[0])
|
|
165
|
+
T = T[ar_idx].set(ar_params[i])
|
|
166
|
+
transition_matrices.append(T)
|
|
167
|
+
T = pt.specify_shape(
|
|
168
|
+
pt.linalg.block_diag(*transition_matrices), (self.k_states, self.k_states)
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
self.ssm["transition", :, :] = T
|
|
172
|
+
|
|
173
|
+
R = np.eye(k_states)
|
|
174
|
+
R_mask = np.full((k_states), False)
|
|
175
|
+
R_mask[0] = True
|
|
176
|
+
R = R[:, R_mask]
|
|
177
|
+
|
|
178
|
+
self.ssm["selection", :, :] = pt.specify_shape(
|
|
179
|
+
pt.linalg.block_diag(*[R for _ in range(k_endog)]), (self.k_states, self.k_posdef)
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
Z = pt.zeros((1, k_states))[0, 0].set(1.0)
|
|
183
|
+
self.ssm["design", :, :] = pt.specify_shape(
|
|
184
|
+
pt.linalg.block_diag(*[Z for _ in range(k_endog)]), (self.k_endog, self.k_states)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
cov_idx = ("state_cov", *np.diag_indices(k_posdef))
|
|
188
|
+
self.ssm[cov_idx] = sigma_ar**2
|