-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b3a95db
Showing
69 changed files
with
15,729 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Saved archives | ||
*.npz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Adrien Corenflos | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Auxiliary Kalman and particle Gibbs samplers for generalised Feynman-Kac models | ||
|
||
This is the companion code for the paper [Auxiliary MCMC and particle Gibbs samplers for parallelisable | ||
inference in latent dynamical systems](TODO) by Adrien Corenflos and Simo Särkkä. | ||
|
||
The models considered here are of the form | ||
|
||
```math | ||
\pi(x_{0:T}) \propto p_0(x_0) \prod_{t=1}^T p_t(x_t | x_{t-1}) g(x_{0:T}) | ||
``` | ||
|
||
for which the auxiliary Kalman sampler can be implemented as long as $g$ is differentiable and Gaussian approximations of | ||
$p_t(x_t | x_{t-1})$ can be computed. | ||
|
||
For separable potentials, for example, $g(x_{0:T}) = \prod_{t=0}^T g_t(x_t)$, the second order auxiliary Kalman sampler can be implemented. This | ||
is the case for the following models: | ||
|
||
```math | ||
g(x_{0:T}) = \prod_{t=0}^T g_t(x_t) = \prod_{t=0}^T p(y_t | x_t) | ||
``` | ||
|
||
Particle Gibbs samplers can be implemented for models of the form | ||
|
||
```math | ||
\pi(x_{0:T}) \propto p_0(x_0)g_0(x_0) \prod_{t=1}^T p_t(x_t | x_{t-1}) g(x_t, x_{t-1}). | ||
``` | ||
|
||
When $p_t(x_t | x_{t-1})$ is approximated by a Gaussian, and/or when $g$ is differentiable, improvements can be achieved as explained in the paper. | ||
|
||
To install this, be sure to follow the official JAX installation instructions, and then run | ||
```bash | ||
pip install -e . | ||
``` | ||
or any other way of installing a Python package from source of your preference. | ||
|
||
Examples can be found in the `examples` folder, together with scripts to reproduce the results described in the paper. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ._primitives.base import SamplerState | ||
from ._primitives.linearisation import extended, gauss_hermite, cubature | ||
from ._primitives.math import mvn | ||
from .common import delta_adaptation |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Union | ||
|
||
from chex import Array, ArrayNumpy, dataclass, ArrayTree | ||
|
||
Array = Union[ArrayNumpy, Array, ArrayTree] | ||
|
||
|
||
@dataclass | ||
class SamplerState: | ||
x: Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .csmc import get_kernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import abc | ||
from typing import Optional | ||
|
||
import chex | ||
from chex import ArrayTree, dataclass, Array | ||
|
||
from aux_samplers._primitives.base import SamplerState | ||
|
||
_MSG = """ | ||
The logpdf is not implemented for this {type(self).__name__} but was called. | ||
If you see this message, you likely are using a cSMC method relying on it. | ||
Please implement this function or choose the standard cSMC with no backward pass. | ||
""" | ||
|
||
_EPS = 1e-10 | ||
|
||
|
||
@dataclass | ||
class CSMCState(SamplerState): | ||
x: ArrayTree | ||
updated: Array | ||
|
||
|
||
@chex.dataclass | ||
class UnivariatePotential(abc.ABC): | ||
""" | ||
Abstract class for univariate potential functions. | ||
This is just a callable, but may have parameters. | ||
""" | ||
|
||
def __call__(self, x): | ||
raise NotImplementedError | ||
|
||
|
||
@chex.dataclass | ||
class Distribution(abc.ABC): | ||
""" | ||
Abstract class for densities. | ||
""" | ||
|
||
def sample(self, key, N): | ||
raise NotImplementedError | ||
|
||
def logpdf(self, x): | ||
return NotImplemented(_MSG.format(type(self).__name__)) | ||
|
||
|
||
@chex.dataclass | ||
class Potential(abc.ABC): | ||
""" | ||
Abstract class for potential functions. | ||
This is just a callable, but may have parameters. | ||
""" | ||
params: Optional[ArrayTree] = None | ||
|
||
def __call__(self, x_t_p_1, x_t, params): | ||
raise NotImplementedError | ||
|
||
|
||
@chex.dataclass | ||
class Dynamics(abc.ABC): | ||
""" | ||
Abstract class for conditional densities. | ||
""" | ||
params: Optional[ArrayTree] = None | ||
|
||
def sample(self, key, x_t, params): | ||
raise NotImplementedError | ||
|
||
def logpdf(self, x_t_p_1, x_t, params): | ||
return NotImplemented(_MSG.format(type(self).__name__)) |
Oops, something went wrong.