Skip to content

Commit

Permalink
Arxiv cut
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCorenflos committed Mar 1, 2023
0 parents commit b3a95db
Show file tree
Hide file tree
Showing 69 changed files with 15,729 additions and 0 deletions.
132 changes: 132 additions & 0 deletions .gitignore
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
21 changes: 21 additions & 0 deletions LICENSE
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.
36 changes: 36 additions & 0 deletions README.md
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.
4 changes: 4 additions & 0 deletions aux_samplers/__init__.py
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.
10 changes: 10 additions & 0 deletions aux_samplers/_primitives/base.py
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
1 change: 1 addition & 0 deletions aux_samplers/_primitives/csmc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .csmc import get_kernel
71 changes: 71 additions & 0 deletions aux_samplers/_primitives/csmc/base.py
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__))
Loading

0 comments on commit b3a95db

Please sign in to comment.