Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyMC implementation of M0 model #266

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions posterior_database/models/info/M0_model.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"stan": {
"model_code": "models/stan/M0_model.stan",
"stan_version": ">=2.26.0"
},
"pymc": {
"model_code": "models/pymc/M0_model.py",
"pymc_version": ">=5.16.0"
}
}
}
25 changes: 25 additions & 0 deletions posterior_database/models/pymc/M0_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import pymc as pm

def model(data):
y = np.array(data["y"]) # capture history matrix
T = np.array(data["T"]) # time periods
coords = {"individual": np.arange(data["M"]),
"capture_period": np.arange(data["T"])}
with pm.Model(coords=coords) as pymc_model:

# Inclusion probability
omega = pm.Uniform("omega", 0, 1)
# Capture probability
p = pm.Uniform("p", 0, 1)

# Inclusion indicator
z = pm.Bernoulli("z", p=omega, dims="individual")

y_obs = pm.Bernoulli("y_obs", p=z[:, None]*p, observed=y, dims=("individual", "capture_period"))

N = pm.Deterministic("N", pm.math.sum(z))

omega_nd = pm.Deterministic("omega_nd", (omega * (1 -p)**T) / (omega * (1 - p)**T + (1 - omega)))

return pymc_model
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "M0", "inference": {"method": "pymc_sampling", "method_arguments": {"chains": 10, "iter": 3000, "warmup": 1000, "thin": 1, "seed": 4711, "control": {"adapt_delta": 0.95}}}, "diagnostics": {"diagnostic_information": {"names": ["N", "omega", "omega_nd", "p"]}, "ndraws": 20000, "nchains": 10, "effective_sample_size_bulk": [4150.0, 5378.0, 4048.0, 4964.0], "effective_sample_size_tail": [7490.0, 7239.0, 6248.0, 7974.0], "r_hat": [1.0, 1.0, 1.0, 1.0], "divergent_transitions": [0, 0, 0, 0], "expected_fraction_of_missing_information": [0, 0, 0, 0]}, "checks_made": {"ndraws_is_10k": true, "nchains_is_gte_4": true, "ess_within_bounds": true, "r_hat_below_1_01": true, "efmi_above_0_2": false}, "comments": "", "added_by": "Chris Fonnesbeck", "added_date": "2024-08-12", "versions": {"pymc_version": "5.16.2+11.gb407c01ac.dirty", "python_version": "3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0]", "python_environment": "['Babel==2.14.0', 'Brotli==1.1.0', 'MarkupSafe==2.1.5', 'PySocks==1.7.1', 'PyYAML==6.0.1', 'SQLAlchemy==2.0.31', 'absl-py==2.1.0', 'accessible-pygments==0.0.5', 'alabaster==0.7.16', 'arviz==0.18.0', 'asttokens==2.4.1', 'attrs==23.2.0', 'beautifulsoup4==4.12.3', 'betterproto==2.0.0b6', 'blackjax==0.0.0', 'bleach==6.1.0', 'cached-property==1.5.2', 'cachetools==5.3.3', 'certifi==2024.7.4', 'cffi==1.16.0', 'cfgv==3.3.1', 'charset-normalizer==3.3.2', 'chex==0.1.86', 'click==8.1.7', 'cloudpickle==3.0.0', 'colorama==0.4.6', 'comm==0.2.2', 'cons==0.4.6', 'contourpy==1.2.1', 'coverage==7.5.4', 'cycler==0.12.1', 'debugpy==1.8.2', 'decorator==5.1.1', 'defusedxml==0.7.1', 'distlib==0.3.8', 'dm-tree==0.1.8', 'docutils==0.21.2', 'entrypoints==0.4', 'etils==1.9.2', 'etuples==0.3.9', 'exceptiongroup==1.2.0', 'executing==2.0.1', 'fastjsonschema==2.20.0', 'fastprogress==1.0.3', 'filelock==3.15.4', 'fonttools==4.53.0', 'graphviz==0.20.3', 'greenlet==3.0.3', 'grpclib==0.4.7', 'h2==4.1.0', 'h5netcdf==1.3.0', 'h5py==3.11.0', 'hagelkorn==1.2.3', 'hpack==4.0.0', 'hyperframe==6.0.1', 'identify==2.5.36', 'idna==3.7', 'imagesize==1.4.1', 'importlib-metadata==8.0.0', 'importlib-resources==6.4.0', 'iniconfig==2.0.0', 'ipykernel==6.29.4', 'ipython==8.25.0', 'ipywidgets==8.1.3', 'jax==0.4.28', 'jaxlib==0.4.28.dev20240710', 'jaxopt==0.8.3', 'jedi==0.19.1', 'jinja2==3.1.4', 'joblib==1.4.2', 'jsonschema==4.22.0', 'jsonschema-specifications==2023.12.1', 'jupyter-cache==1.0.0', 'jupyter-client==8.6.2', 'jupyter-core==5.7.2', 'jupyter-sphinx==0.5.3', 'jupyterlab-pygments==0.3.0', 'jupyterlab-widgets==3.0.11', 'kiwisolver==1.4.5', 'logical-unification==0.4.6', 'markdown-it-py==3.0.0', 'matplotlib==3.8.4', 'matplotlib-inline==0.1.7', 'mcbackend==0.5.2', 'mdit-py-plugins==0.4.1', 'mdurl==0.1.2', 'miniKanren==1.0.3', 'mistune==3.0.2', 'mkl-service==2.4.1', 'ml-dtypes==0.4.0', 'multidict==6.0.5', 'multipledispatch==0.6.0', 'munkres==1.1.4', 'mypy==1.5.1', 'mypy-extensions==1.0.0', 'myst-nb==1.1.0', 'myst-parser==3.0.1', 'nbclient==0.10.0', 'nbconvert==7.16.4', 'nbformat==5.10.4', 'nest-asyncio==1.6.0', 'networkx==3.3', 'nodeenv==1.9.1', 'numdifftools==0.9.41', 'numpy==1.26.4', 'numpydoc==1.7.0', 'numpyro==0.15.1', 'opt-einsum==3.3.0', 'optax==0.2.2', 'packaging==24.1', 'pandas==2.2.2', 'pandocfilters==1.5.0', 'parso==0.8.4', 'pexpect==4.9.0', 'pickleshare==0.7.5', 'pillow==10.3.0', 'pip==24.0', 'pkgutil-resolve-name==1.3.10', 'platformdirs==4.2.2', 'pluggy==1.5.0', 'polyagamma==1.3.6', 'pre-commit==3.7.1', 'prompt-toolkit==3.0.47', 'psutil==6.0.0', 'ptyprocess==0.7.0', 'pure-eval==0.2.2', 'pycparser==2.22', 'pydata-sphinx-theme==0.14.4', 'pygments==2.18.0', 'pymc==5.16.2+11.gb407c01ac.dirty', 'pymc-experimental==0.1.1', 'pymc-sphinx-theme==0.14.0', 'pyparsing==3.1.2', 'pytensor==2.25.2', 'pytest==8.2.2', 'pytest-cov==5.0.0', 'python-dateutil==2.9.0', 'pytz==2024.1', 'pyzmq==26.0.3', 'referencing==0.35.1', 'requests==2.32.3', 'rich==13.7.1', 'rpds-py==0.18.1', 'scikit-learn==1.5.1', 'scipy==1.13.1', 'setuptools==70.1.1', 'six==1.16.0', 'snowballstemmer==2.2.0', 'soupsieve==2.5', 'sphinx==7.3.7', 'sphinx-copybutton==0.5.2', 'sphinx-design==0.6.0', 'sphinx-notfound-page==1.0.2', 'sphinx-remove-toctrees==1.0.0.post1', 'sphinxcontrib-applehelp==1.0.8', 'sphinxcontrib-devhelp==1.0.6', 'sphinxcontrib-htmlhelp==2.0.5', 'sphinxcontrib-jsmath==1.0.1', 'sphinxcontrib-qthelp==1.0.7', 'sphinxcontrib-serializinghtml==1.1.10', 'sphinxext-rediraffe==0.2.7', 'stack-data==0.6.2', 'tabulate==0.9.0', 'threadpoolctl==3.5.0', 'tinycss2==1.3.0', 'toml==0.10.2', 'tomli==2.0.1', 'toolz==0.12.1', 'tornado==6.4.1', 'tqdm==4.66.4', 'traitlets==5.14.3', 'types-cachetools==5.3.0.7', 'typing-extensions==4.12.2', 'tzdata==2024.1', 'ukkonen==1.0.1', 'urllib3==2.2.2', 'virtualenv==20.26.3', 'watermark==2.4.3', 'wcwidth==0.2.13', 'webencodings==0.5.1', 'wheel==0.43.0', 'widgetsnbextension==4.0.11', 'xarray==2024.6.0', 'xarray-einstats==0.7.0', 'zipp==3.19.2', 'zstandard==0.22.0']"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"names": ["N", "omega", "omega_nd", "p"], "mean": [100.349, 0.424, 0.089, 0.496], "sd": [5.263, 0.039, 0.026, 0.038], "mcse_mean": [0.082, 0.001, 0.0, 0.001]}