pylgm 0.3.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.
Files changed (220) hide show
  1. pylgm-0.3.0/.github/workflows/docs.yml +42 -0
  2. pylgm-0.3.0/.github/workflows/publish.yml +23 -0
  3. pylgm-0.3.0/.github/workflows/test.yml +53 -0
  4. pylgm-0.3.0/.gitignore +7 -0
  5. pylgm-0.3.0/LICENSE +21 -0
  6. pylgm-0.3.0/PKG-INFO +114 -0
  7. pylgm-0.3.0/README.md +78 -0
  8. pylgm-0.3.0/docs/design/plans/2026-07-22-pylgm-gaussian-foundation.md +1204 -0
  9. pylgm-0.3.0/docs/design/plans/2026-07-22-pylgm-predictive-selection.md +914 -0
  10. pylgm-0.3.0/docs/design/plans/2026-08-08-pylgm-general-lgm-foundation.md +540 -0
  11. pylgm-0.3.0/docs/design/plans/2026-08-17-pylgm-pyspark-adapter.md +362 -0
  12. pylgm-0.3.0/docs/design/plans/2026-08-19-pylgm-declarative-empirical-bayes.md +793 -0
  13. pylgm-0.3.0/docs/design/plans/2026-08-19-pylgm-non-gaussian-laplace.md +1151 -0
  14. pylgm-0.3.0/docs/design/plans/2026-08-20-pylgm-inla-criteria.md +496 -0
  15. pylgm-0.3.0/docs/design/plans/2026-08-20-pylgm-inla-integration.md +672 -0
  16. pylgm-0.3.0/docs/design/plans/2026-08-20-pylgm-penalized-map-ii.md +313 -0
  17. pylgm-0.3.0/docs/design/plans/2026-08-21-pylgm-inla-full-laplace.md +324 -0
  18. pylgm-0.3.0/docs/design/plans/2026-08-21-pylgm-inla-simplified-laplace.md +414 -0
  19. pylgm-0.3.0/docs/design/plans/2026-08-23-pylgm-besag-icar.md +801 -0
  20. pylgm-0.3.0/docs/design/plans/2026-08-23-pylgm-bounded-hyperparameter-inference.md +941 -0
  21. pylgm-0.3.0/docs/design/plans/2026-08-23-pylgm-bym2.md +900 -0
  22. pylgm-0.3.0/docs/design/plans/2026-08-23-pylgm-proper-car.md +590 -0
  23. pylgm-0.3.0/docs/design/plans/2026-08-24-pylgm-ar1.md +536 -0
  24. pylgm-0.3.0/docs/design/plans/2026-08-24-pylgm-followups.md +255 -0
  25. pylgm-0.3.0/docs/design/plans/2026-08-24-pylgm-out-of-sample-prediction.md +518 -0
  26. pylgm-0.3.0/docs/design/plans/2026-08-24-pylgm-result-unification.md +372 -0
  27. pylgm-0.3.0/docs/design/specs/2026-07-22-pylgm-design.md +515 -0
  28. pylgm-0.3.0/docs/design/specs/2026-07-22-pylgm-predictive-selection-design.md +224 -0
  29. pylgm-0.3.0/docs/design/specs/2026-08-08-pylgm-latte-pyspark-architecture.md +619 -0
  30. pylgm-0.3.0/docs/design/specs/2026-08-17-pylgm-pyspark-adapter-design.md +186 -0
  31. pylgm-0.3.0/docs/design/specs/2026-08-19-pylgm-declarative-empirical-bayes-design.md +228 -0
  32. pylgm-0.3.0/docs/design/specs/2026-08-19-pylgm-non-gaussian-laplace-design.md +272 -0
  33. pylgm-0.3.0/docs/design/specs/2026-08-20-pylgm-inla-criteria-design.md +194 -0
  34. pylgm-0.3.0/docs/design/specs/2026-08-20-pylgm-inla-integration-design.md +215 -0
  35. pylgm-0.3.0/docs/design/specs/2026-08-20-pylgm-penalized-map-ii-design.md +163 -0
  36. pylgm-0.3.0/docs/design/specs/2026-08-21-pylgm-inla-full-laplace-design.md +163 -0
  37. pylgm-0.3.0/docs/design/specs/2026-08-21-pylgm-inla-simplified-laplace-design.md +186 -0
  38. pylgm-0.3.0/docs/design/specs/2026-08-23-pylgm-besag-icar-design.md +237 -0
  39. pylgm-0.3.0/docs/design/specs/2026-08-23-pylgm-bounded-hyperparameter-inference-design.md +268 -0
  40. pylgm-0.3.0/docs/design/specs/2026-08-23-pylgm-bym2-design.md +240 -0
  41. pylgm-0.3.0/docs/design/specs/2026-08-23-pylgm-proper-car-design.md +182 -0
  42. pylgm-0.3.0/docs/design/specs/2026-08-24-pylgm-ar1-design.md +179 -0
  43. pylgm-0.3.0/docs/design/specs/2026-08-24-pylgm-newton-stall-rescue-design.md +149 -0
  44. pylgm-0.3.0/docs/design/specs/2026-08-24-pylgm-out-of-sample-prediction-design.md +217 -0
  45. pylgm-0.3.0/docs/design/specs/2026-08-24-pylgm-result-unification-design.md +184 -0
  46. pylgm-0.3.0/docs/development.md +8 -0
  47. pylgm-0.3.0/docs/effects.md +96 -0
  48. pylgm-0.3.0/docs/empirical-bayes.md +91 -0
  49. pylgm-0.3.0/docs/examples-count-regression.md +89 -0
  50. pylgm-0.3.0/docs/examples-disease-mapping.md +81 -0
  51. pylgm-0.3.0/docs/img/crabs_fit.png +0 -0
  52. pylgm-0.3.0/docs/img/crabs_prediction.png +0 -0
  53. pylgm-0.3.0/docs/img/scotland_fit.png +0 -0
  54. pylgm-0.3.0/docs/img/scotland_shrinkage.png +0 -0
  55. pylgm-0.3.0/docs/index.md +64 -0
  56. pylgm-0.3.0/docs/inla.md +209 -0
  57. pylgm-0.3.0/docs/internals.md +100 -0
  58. pylgm-0.3.0/docs/likelihoods.md +158 -0
  59. pylgm-0.3.0/docs/prediction.md +142 -0
  60. pylgm-0.3.0/docs/roadmap.md +51 -0
  61. pylgm-0.3.0/docs/spark.md +57 -0
  62. pylgm-0.3.0/docs/spatial-effects.md +296 -0
  63. pylgm-0.3.0/docs/theory.md +205 -0
  64. pylgm-0.3.0/examples/count_glm/README.md +31 -0
  65. pylgm-0.3.0/examples/count_glm/config.yaml +11 -0
  66. pylgm-0.3.0/examples/count_glm/data.csv +9 -0
  67. pylgm-0.3.0/examples/count_glm/run.py +22 -0
  68. pylgm-0.3.0/examples/count_regression/README.md +19 -0
  69. pylgm-0.3.0/examples/count_regression/data.csv +174 -0
  70. pylgm-0.3.0/examples/count_regression/run.py +155 -0
  71. pylgm-0.3.0/examples/disease_mapping/README.md +19 -0
  72. pylgm-0.3.0/examples/disease_mapping/data.csv +57 -0
  73. pylgm-0.3.0/examples/disease_mapping/graph.json +1 -0
  74. pylgm-0.3.0/examples/disease_mapping/run.py +134 -0
  75. pylgm-0.3.0/examples/empirical_bayes/README.md +42 -0
  76. pylgm-0.3.0/examples/empirical_bayes/data.csv +81 -0
  77. pylgm-0.3.0/examples/empirical_bayes/run.py +33 -0
  78. pylgm-0.3.0/examples/general_lgm/README.md +41 -0
  79. pylgm-0.3.0/examples/general_lgm/config.yaml +18 -0
  80. pylgm-0.3.0/examples/general_lgm/data.csv +7 -0
  81. pylgm-0.3.0/examples/general_lgm/run.py +40 -0
  82. pylgm-0.3.0/examples/general_lgm/run_spark.py +32 -0
  83. pylgm-0.3.0/examples/inla/README.md +59 -0
  84. pylgm-0.3.0/examples/inla/data.csv +145 -0
  85. pylgm-0.3.0/examples/inla/run.py +43 -0
  86. pylgm-0.3.0/examples/inla_criteria/README.md +64 -0
  87. pylgm-0.3.0/examples/inla_criteria/data.csv +145 -0
  88. pylgm-0.3.0/examples/inla_criteria/run.py +40 -0
  89. pylgm-0.3.0/examples/inla_full_laplace/README.md +78 -0
  90. pylgm-0.3.0/examples/inla_full_laplace/data.csv +133 -0
  91. pylgm-0.3.0/examples/inla_full_laplace/run.py +69 -0
  92. pylgm-0.3.0/examples/inla_sla/README.md +68 -0
  93. pylgm-0.3.0/examples/inla_sla/data.csv +133 -0
  94. pylgm-0.3.0/examples/inla_sla/run.py +52 -0
  95. pylgm-0.3.0/examples/map_ii/README.md +53 -0
  96. pylgm-0.3.0/examples/map_ii/data.csv +81 -0
  97. pylgm-0.3.0/examples/map_ii/run.py +37 -0
  98. pylgm-0.3.0/examples/nic_backtest/README.md +25 -0
  99. pylgm-0.3.0/examples/nic_backtest/config.yaml +38 -0
  100. pylgm-0.3.0/examples/predictive_selection/README.md +20 -0
  101. pylgm-0.3.0/examples/predictive_selection/config.yaml +36 -0
  102. pylgm-0.3.0/examples/predictive_selection/data.csv +31 -0
  103. pylgm-0.3.0/examples/synthetic_panel/README.md +23 -0
  104. pylgm-0.3.0/examples/synthetic_panel/config.yaml +13 -0
  105. pylgm-0.3.0/examples/synthetic_panel/data.csv +9 -0
  106. pylgm-0.3.0/mkdocs.yml +52 -0
  107. pylgm-0.3.0/pyproject.toml +68 -0
  108. pylgm-0.3.0/src/pylgm/__init__.py +37 -0
  109. pylgm-0.3.0/src/pylgm/artifacts/__init__.py +6 -0
  110. pylgm-0.3.0/src/pylgm/artifacts/experiment.py +206 -0
  111. pylgm-0.3.0/src/pylgm/artifacts/run.py +252 -0
  112. pylgm-0.3.0/src/pylgm/cli.py +49 -0
  113. pylgm-0.3.0/src/pylgm/compiler.py +667 -0
  114. pylgm-0.3.0/src/pylgm/config/__init__.py +15 -0
  115. pylgm-0.3.0/src/pylgm/config/experiment.py +271 -0
  116. pylgm-0.3.0/src/pylgm/config/load.py +57 -0
  117. pylgm-0.3.0/src/pylgm/config/model.py +151 -0
  118. pylgm-0.3.0/src/pylgm/config/schema.py +79 -0
  119. pylgm-0.3.0/src/pylgm/data/__init__.py +3 -0
  120. pylgm-0.3.0/src/pylgm/data/fingerprint.py +215 -0
  121. pylgm-0.3.0/src/pylgm/data/panel.py +126 -0
  122. pylgm-0.3.0/src/pylgm/data/scalars.py +69 -0
  123. pylgm-0.3.0/src/pylgm/data/spark.py +114 -0
  124. pylgm-0.3.0/src/pylgm/effects/__init__.py +31 -0
  125. pylgm-0.3.0/src/pylgm/effects/ar1.py +58 -0
  126. pylgm-0.3.0/src/pylgm/effects/besag.py +71 -0
  127. pylgm-0.3.0/src/pylgm/effects/bym2.py +58 -0
  128. pylgm-0.3.0/src/pylgm/effects/fixed.py +19 -0
  129. pylgm-0.3.0/src/pylgm/effects/graph.py +144 -0
  130. pylgm-0.3.0/src/pylgm/effects/iid.py +22 -0
  131. pylgm-0.3.0/src/pylgm/effects/proper_car.py +88 -0
  132. pylgm-0.3.0/src/pylgm/effects/random_walk.py +55 -0
  133. pylgm-0.3.0/src/pylgm/effects/spec.py +236 -0
  134. pylgm-0.3.0/src/pylgm/evaluation/__init__.py +21 -0
  135. pylgm-0.3.0/src/pylgm/evaluation/availability.py +30 -0
  136. pylgm-0.3.0/src/pylgm/evaluation/folds.py +297 -0
  137. pylgm-0.3.0/src/pylgm/evaluation/metrics.py +304 -0
  138. pylgm-0.3.0/src/pylgm/evaluation/persistence.py +89 -0
  139. pylgm-0.3.0/src/pylgm/evaluation/selection.py +174 -0
  140. pylgm-0.3.0/src/pylgm/exceptions.py +105 -0
  141. pylgm-0.3.0/src/pylgm/experiment.py +479 -0
  142. pylgm-0.3.0/src/pylgm/inference/__init__.py +26 -0
  143. pylgm-0.3.0/src/pylgm/inference/gaussian.py +174 -0
  144. pylgm-0.3.0/src/pylgm/inference/laplace.py +171 -0
  145. pylgm-0.3.0/src/pylgm/inference/prediction.py +232 -0
  146. pylgm-0.3.0/src/pylgm/inference/result.py +990 -0
  147. pylgm-0.3.0/src/pylgm/ir/__init__.py +25 -0
  148. pylgm-0.3.0/src/pylgm/ir/family.py +462 -0
  149. pylgm-0.3.0/src/pylgm/ir/model.py +275 -0
  150. pylgm-0.3.0/src/pylgm/likelihoods.py +198 -0
  151. pylgm-0.3.0/src/pylgm/links.py +38 -0
  152. pylgm-0.3.0/src/pylgm/model.py +350 -0
  153. pylgm-0.3.0/src/pylgm/optimization/__init__.py +16 -0
  154. pylgm-0.3.0/src/pylgm/optimization/empirical_bayes.py +322 -0
  155. pylgm-0.3.0/src/pylgm/optimization/inla.py +504 -0
  156. pylgm-0.3.0/src/pylgm/optimization/result.py +92 -0
  157. pylgm-0.3.0/src/pylgm/optimization/transforms.py +83 -0
  158. pylgm-0.3.0/src/pylgm/parameters.py +95 -0
  159. pylgm-0.3.0/src/pylgm/pipeline.py +28 -0
  160. pylgm-0.3.0/src/pylgm/priors.py +223 -0
  161. pylgm-0.3.0/tests/artifacts/test_experiment_artifacts.py +317 -0
  162. pylgm-0.3.0/tests/config/__init__.py +1 -0
  163. pylgm-0.3.0/tests/config/test_experiment.py +395 -0
  164. pylgm-0.3.0/tests/config/test_load.py +137 -0
  165. pylgm-0.3.0/tests/config/test_model.py +223 -0
  166. pylgm-0.3.0/tests/conftest.py +17 -0
  167. pylgm-0.3.0/tests/data/test_panel.py +101 -0
  168. pylgm-0.3.0/tests/data/test_spark.py +260 -0
  169. pylgm-0.3.0/tests/effects/test_ar1.py +69 -0
  170. pylgm-0.3.0/tests/effects/test_besag.py +107 -0
  171. pylgm-0.3.0/tests/effects/test_bym2.py +74 -0
  172. pylgm-0.3.0/tests/effects/test_graph.py +94 -0
  173. pylgm-0.3.0/tests/effects/test_proper_car.py +85 -0
  174. pylgm-0.3.0/tests/effects/test_spec.py +239 -0
  175. pylgm-0.3.0/tests/effects/test_structured.py +71 -0
  176. pylgm-0.3.0/tests/evaluation/test_folds.py +442 -0
  177. pylgm-0.3.0/tests/evaluation/test_metrics.py +318 -0
  178. pylgm-0.3.0/tests/evaluation/test_persistence.py +143 -0
  179. pylgm-0.3.0/tests/evaluation/test_selection.py +189 -0
  180. pylgm-0.3.0/tests/inference/result_surface_baseline.json +4318 -0
  181. pylgm-0.3.0/tests/inference/test_gaussian.py +470 -0
  182. pylgm-0.3.0/tests/inference/test_laplace.py +152 -0
  183. pylgm-0.3.0/tests/inference/test_prediction.py +106 -0
  184. pylgm-0.3.0/tests/inference/test_predictive_variance_convention.py +93 -0
  185. pylgm-0.3.0/tests/inference/test_result.py +554 -0
  186. pylgm-0.3.0/tests/inference/test_result_surface.py +798 -0
  187. pylgm-0.3.0/tests/inference/test_tabulated_marginals.py +33 -0
  188. pylgm-0.3.0/tests/integration/test_nic_shaped_backtest.py +81 -0
  189. pylgm-0.3.0/tests/integration/test_predictive_selection.py +23 -0
  190. pylgm-0.3.0/tests/integration/test_synthetic_example.py +15 -0
  191. pylgm-0.3.0/tests/ir/test_compiled_family.py +54 -0
  192. pylgm-0.3.0/tests/ir/test_fixed.py +94 -0
  193. pylgm-0.3.0/tests/ir/test_gaussian_family.py +432 -0
  194. pylgm-0.3.0/tests/ir/test_model_validation.py +288 -0
  195. pylgm-0.3.0/tests/ir/test_parametric_block.py +140 -0
  196. pylgm-0.3.0/tests/optimization/test_empirical_bayes.py +965 -0
  197. pylgm-0.3.0/tests/optimization/test_full_laplace.py +131 -0
  198. pylgm-0.3.0/tests/optimization/test_inla.py +193 -0
  199. pylgm-0.3.0/tests/optimization/test_inla_criteria.py +100 -0
  200. pylgm-0.3.0/tests/optimization/test_simplified_laplace.py +86 -0
  201. pylgm-0.3.0/tests/optimization/test_skew_normal.py +33 -0
  202. pylgm-0.3.0/tests/optimization/test_transforms.py +67 -0
  203. pylgm-0.3.0/tests/test_ar1_fit.py +120 -0
  204. pylgm-0.3.0/tests/test_besag_fit.py +155 -0
  205. pylgm-0.3.0/tests/test_bym2_fit.py +95 -0
  206. pylgm-0.3.0/tests/test_cli.py +110 -0
  207. pylgm-0.3.0/tests/test_compiler.py +691 -0
  208. pylgm-0.3.0/tests/test_experiment.py +366 -0
  209. pylgm-0.3.0/tests/test_links.py +22 -0
  210. pylgm-0.3.0/tests/test_model.py +750 -0
  211. pylgm-0.3.0/tests/test_model_spark.py +78 -0
  212. pylgm-0.3.0/tests/test_modeling_vocabulary.py +214 -0
  213. pylgm-0.3.0/tests/test_package.py +142 -0
  214. pylgm-0.3.0/tests/test_parameters.py +28 -0
  215. pylgm-0.3.0/tests/test_pc_bym2_phi.py +87 -0
  216. pylgm-0.3.0/tests/test_pipeline.py +382 -0
  217. pylgm-0.3.0/tests/test_predict.py +217 -0
  218. pylgm-0.3.0/tests/test_proper_car_fit.py +96 -0
  219. pylgm-0.3.0/tests/test_proper_car_rho_estimation.py +103 -0
  220. pylgm-0.3.0/tests/test_public_exports.py +28 -0
@@ -0,0 +1,42 @@
1
+ name: docs
2
+
3
+ # Builds the MkDocs site and deploys it to GitHub Pages on every push to main.
4
+ # One-time setup: enable Pages for the repo with "GitHub Actions" as the source
5
+ # (Settings -> Pages). Site URL: https://ardea00.github.io/pylgm/
6
+ on:
7
+ push:
8
+ branches: [main]
9
+
10
+ permissions:
11
+ contents: read
12
+ pages: write
13
+ id-token: write
14
+
15
+ # Allow one concurrent deployment; don't cancel an in-progress one.
16
+ concurrency:
17
+ group: pages
18
+ cancel-in-progress: false
19
+
20
+ jobs:
21
+ build:
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.11"
28
+ - run: python -m pip install .[docs]
29
+ - run: mkdocs build --strict
30
+ - uses: actions/upload-pages-artifact@v3
31
+ with:
32
+ path: site
33
+
34
+ deploy:
35
+ needs: build
36
+ runs-on: ubuntu-latest
37
+ environment:
38
+ name: github-pages
39
+ url: ${{ steps.deployment.outputs.page_url }}
40
+ steps:
41
+ - id: deployment
42
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,23 @@
1
+ name: publish
2
+
3
+ # Publishes to PyPI when a GitHub Release is published. Uses Trusted
4
+ # Publishing (OIDC) -- no API token is stored; PyPI must have a trusted
5
+ # publisher configured for this repo/workflow (one-time setup on pypi.org).
6
+ on:
7
+ release:
8
+ types: [published]
9
+
10
+ jobs:
11
+ pypi:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ permissions:
15
+ id-token: write # required for Trusted Publishing
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.11"
21
+ - run: python -m pip install --upgrade build
22
+ - run: python -m build
23
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,53 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ core:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, windows-latest, macos-latest]
15
+ python-version: ["3.11", "3.12", "3.13"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+ - run: python -m pip install --upgrade pip
22
+ - run: python -m pip install -e ".[dev]"
23
+ - run: ruff check src tests
24
+ - run: pytest -q
25
+
26
+ release-gate:
27
+ # Non-editable install exercises the real hatchling build and the console
28
+ # entry point exactly as `pip install pylgm` would for a released user.
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: "3.11"
35
+ - run: python -m pip install --upgrade pip
36
+ - run: python -m pip install .
37
+ - run: pylgm --help
38
+
39
+ spark:
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+ - uses: actions/setup-python@v5
44
+ with:
45
+ python-version: "3.11"
46
+ - uses: actions/setup-java@v4
47
+ with:
48
+ distribution: temurin
49
+ java-version: "17"
50
+ - run: python -m pip install --upgrade pip
51
+ - run: python -m pip install -e ".[dev,spark]"
52
+ # Spark and Java are provisioned here, so these tests must run unskipped.
53
+ - run: pytest tests/data/test_spark.py tests/test_model_spark.py -q
pylgm-0.3.0/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .superpowers/
4
+ .worktrees/
5
+ site/
6
+ dist/
7
+ validation/
pylgm-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrea Panozzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pylgm-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.5
2
+ Name: pylgm
3
+ Version: 0.3.0
4
+ Summary: General-purpose latent Gaussian models for Python
5
+ Project-URL: Homepage, https://github.com/Ardea00/pylgm
6
+ Project-URL: Repository, https://github.com/Ardea00/pylgm
7
+ Project-URL: Issues, https://github.com/Ardea00/pylgm/issues
8
+ Author: Andrea Panozzo
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: bayesian,inla,laplace approximation,latent gaussian models,statistics
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: formulaic>=1.1
21
+ Requires-Dist: numpy>=2.0
22
+ Requires-Dist: pandas>=2.2
23
+ Requires-Dist: pyarrow>=17
24
+ Requires-Dist: pydantic>=2.8
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: scipy>=1.14
27
+ Requires-Dist: typer>=0.15
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.3; extra == 'dev'
30
+ Requires-Dist: ruff>=0.9; extra == 'dev'
31
+ Provides-Extra: docs
32
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
33
+ Provides-Extra: spark
34
+ Requires-Dist: pyspark>=3.5; extra == 'spark'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # pyLGM
38
+
39
+ General-purpose **latent Gaussian models** for Python — the model class behind
40
+ INLA. Fit fixed effects, random effects, temporal (RW/AR1) and spatial (CAR)
41
+ structure under Gaussian, Poisson, or Bernoulli likelihoods, from a Pandas (or
42
+ Spark) DataFrame, with exact-Gaussian and Laplace inference engines, empirical
43
+ Bayes / MAP-II hyperparameter estimation, and INLA-style posterior integration.
44
+
45
+ ## Install
46
+
47
+ ```bash
48
+ pip install pylgm
49
+ pip install "pylgm[spark]" # optional: Spark data boundary
50
+ ```
51
+
52
+ Requires Python ≥ 3.11.
53
+
54
+ ## 30-second example
55
+
56
+ A Poisson model with a per-region random intercept, fit with the Laplace engine:
57
+
58
+ ```python
59
+ import pandas as pd
60
+ from pylgm import Fixed, IID, LGM, Poisson
61
+
62
+ # Counts of events per region over time, with a covariate x.
63
+ frame = pd.DataFrame({
64
+ "region": ["north", "north", "north", "south", "south", "south"],
65
+ "time": [1, 2, 3, 1, 2, 3],
66
+ "x": [0.0, 0.5, 1.0, 0.0, 0.5, 1.0],
67
+ "count": [3, 5, 8, 2, 3, 5],
68
+ })
69
+
70
+ model = LGM(
71
+ response="count",
72
+ likelihood=Poisson(), # canonical log link
73
+ predictor=Fixed("1 + x") # fixed effects
74
+ + IID("region", index="region", precision=2.0), # random intercept per region
75
+ panel=("region",),
76
+ time="time",
77
+ )
78
+
79
+ result = model.fit(frame, engine="laplace")
80
+ print("fitted_mean:", result.fitted_mean.round(3).tolist())
81
+ # fitted_mean: [3.254, 4.986, 8.15, 2.201, 3.373, 5.513]
82
+ ```
83
+
84
+ The same model can be declared in YAML and loaded with `pylgm.config.load_model`.
85
+ See the [general LGM example](examples/general_lgm/README.md), which fits the
86
+ same data through both the Python and YAML frontends, and the other 13 runnable
87
+ scripts under [`examples/`](examples/).
88
+
89
+ ## What's in the box
90
+
91
+ | Area | What you get | Docs |
92
+ |---|---|---|
93
+ | **Likelihoods** | Gaussian (exact), Poisson & Bernoulli (Laplace) | [likelihoods](docs/likelihoods.md) |
94
+ | **Effects** | `Fixed`, `IID`, `RW1`/`RW2`, stationary `AR1` | [effects](docs/effects.md) |
95
+ | **Spatial** | `Besag` (ICAR), `ProperCAR` (with ρ), `BYM2` (with φ) | [spatial effects](docs/spatial-effects.md) |
96
+ | **Hyperparameters** | Empirical Bayes (type-II ML), MAP-II priors, bounds | [empirical bayes](docs/empirical-bayes.md) |
97
+ | **Integration** | INLA-style grid quadrature, simplified/full-Laplace marginals, DIC/WAIC/CPO/PIT | [INLA](docs/inla.md) |
98
+ | **Prediction** | fit-row and out-of-sample `result.predict(new_data)` | [prediction](docs/prediction.md) |
99
+ | **Data boundary** | Pandas, or Spark / Databricks | [spark](docs/spark.md) |
100
+
101
+ ## Documentation
102
+
103
+ Full docs: **https://ardea00.github.io/pylgm/** — or browse the
104
+ [`docs/`](docs/) folder. Start with the [index](docs/index.md).
105
+
106
+ ## Scope and roadmap
107
+
108
+ pyLGM 0.3 is a bounded foundation release. What is and isn't in it, and where
109
+ it's going, are documented in the [roadmap](docs/roadmap.md) and the
110
+ [internals / release policy](docs/internals.md) page.
111
+
112
+ ## Development
113
+
114
+ See [docs/development.md](docs/development.md). License: [MIT](LICENSE).
pylgm-0.3.0/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # pyLGM
2
+
3
+ General-purpose **latent Gaussian models** for Python — the model class behind
4
+ INLA. Fit fixed effects, random effects, temporal (RW/AR1) and spatial (CAR)
5
+ structure under Gaussian, Poisson, or Bernoulli likelihoods, from a Pandas (or
6
+ Spark) DataFrame, with exact-Gaussian and Laplace inference engines, empirical
7
+ Bayes / MAP-II hyperparameter estimation, and INLA-style posterior integration.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install pylgm
13
+ pip install "pylgm[spark]" # optional: Spark data boundary
14
+ ```
15
+
16
+ Requires Python ≥ 3.11.
17
+
18
+ ## 30-second example
19
+
20
+ A Poisson model with a per-region random intercept, fit with the Laplace engine:
21
+
22
+ ```python
23
+ import pandas as pd
24
+ from pylgm import Fixed, IID, LGM, Poisson
25
+
26
+ # Counts of events per region over time, with a covariate x.
27
+ frame = pd.DataFrame({
28
+ "region": ["north", "north", "north", "south", "south", "south"],
29
+ "time": [1, 2, 3, 1, 2, 3],
30
+ "x": [0.0, 0.5, 1.0, 0.0, 0.5, 1.0],
31
+ "count": [3, 5, 8, 2, 3, 5],
32
+ })
33
+
34
+ model = LGM(
35
+ response="count",
36
+ likelihood=Poisson(), # canonical log link
37
+ predictor=Fixed("1 + x") # fixed effects
38
+ + IID("region", index="region", precision=2.0), # random intercept per region
39
+ panel=("region",),
40
+ time="time",
41
+ )
42
+
43
+ result = model.fit(frame, engine="laplace")
44
+ print("fitted_mean:", result.fitted_mean.round(3).tolist())
45
+ # fitted_mean: [3.254, 4.986, 8.15, 2.201, 3.373, 5.513]
46
+ ```
47
+
48
+ The same model can be declared in YAML and loaded with `pylgm.config.load_model`.
49
+ See the [general LGM example](examples/general_lgm/README.md), which fits the
50
+ same data through both the Python and YAML frontends, and the other 13 runnable
51
+ scripts under [`examples/`](examples/).
52
+
53
+ ## What's in the box
54
+
55
+ | Area | What you get | Docs |
56
+ |---|---|---|
57
+ | **Likelihoods** | Gaussian (exact), Poisson & Bernoulli (Laplace) | [likelihoods](docs/likelihoods.md) |
58
+ | **Effects** | `Fixed`, `IID`, `RW1`/`RW2`, stationary `AR1` | [effects](docs/effects.md) |
59
+ | **Spatial** | `Besag` (ICAR), `ProperCAR` (with ρ), `BYM2` (with φ) | [spatial effects](docs/spatial-effects.md) |
60
+ | **Hyperparameters** | Empirical Bayes (type-II ML), MAP-II priors, bounds | [empirical bayes](docs/empirical-bayes.md) |
61
+ | **Integration** | INLA-style grid quadrature, simplified/full-Laplace marginals, DIC/WAIC/CPO/PIT | [INLA](docs/inla.md) |
62
+ | **Prediction** | fit-row and out-of-sample `result.predict(new_data)` | [prediction](docs/prediction.md) |
63
+ | **Data boundary** | Pandas, or Spark / Databricks | [spark](docs/spark.md) |
64
+
65
+ ## Documentation
66
+
67
+ Full docs: **https://ardea00.github.io/pylgm/** — or browse the
68
+ [`docs/`](docs/) folder. Start with the [index](docs/index.md).
69
+
70
+ ## Scope and roadmap
71
+
72
+ pyLGM 0.3 is a bounded foundation release. What is and isn't in it, and where
73
+ it's going, are documented in the [roadmap](docs/roadmap.md) and the
74
+ [internals / release policy](docs/internals.md) page.
75
+
76
+ ## Development
77
+
78
+ See [docs/development.md](docs/development.md). License: [MIT](LICENSE).