CUQIpy 1.1.0__tar.gz → 1.1.0.post0.dev17__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.
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/CUQIpy.egg-info/PKG-INFO +1 -1
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/PKG-INFO +1 -1
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/_version.py +3 -3
- cuqipy-1.1.0.post0.dev17/cuqi/experimental/mcmc/__init__.py +15 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_conjugate.py +3 -3
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_conjugate_approx.py +3 -3
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_cwmh.py +6 -6
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_direct.py +2 -2
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_gibbs.py +10 -10
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_hmc.py +7 -7
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_langevin_algorithm.py +6 -6
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_laplace_approximation.py +2 -2
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_mh.py +4 -4
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_pcn.py +3 -3
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_rto.py +3 -3
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_sampler.py +7 -7
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/mcmc/_utilities.py +1 -1
- cuqipy-1.1.0/cuqi/experimental/mcmc/__init__.py +0 -15
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/CUQIpy.egg-info/SOURCES.txt +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/CUQIpy.egg-info/dependency_links.txt +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/CUQIpy.egg-info/requires.txt +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/CUQIpy.egg-info/top_level.txt +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/LICENSE +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/README.md +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/_messages.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/array/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/array/_array.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/config.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/_data.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/astronaut.npz +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/camera.npz +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/cat.npz +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/cookie.png +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/data/satellite.mat +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/density/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/density/_density.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/diagnostics.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_beta.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_cauchy.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_cmrf.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_custom.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_distribution.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_gamma.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_gaussian.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_gmrf.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_inverse_gamma.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_joint_distribution.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_laplace.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_lmrf.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_lognormal.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_modifiedhalfnormal.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_normal.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_posterior.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_smoothed_laplace.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/distribution/_uniform.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/experimental/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/geometry/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/geometry/_geometry.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/implicitprior/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/implicitprior/_regularizedGMRF.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/implicitprior/_regularizedGaussian.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/implicitprior/_regularizedUnboundedUniform.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/likelihood/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/likelihood/_likelihood.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/model/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/model/_model.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/operator/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/operator/_operator.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/pde/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/pde/_pde.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/problem/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/problem/_problem.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_conjugate.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_conjugate_approx.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_cwmh.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_gibbs.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_hmc.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_langevin_algorithm.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_laplace_approximation.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_mh.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_pcn.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_rto.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/sampler/_sampler.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/samples/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/samples/_samples.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/solver/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/solver/_solver.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/testproblem/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/testproblem/_testproblem.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/utilities/__init__.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/utilities/_get_python_variable_name.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/utilities/_utilities.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/pyproject.toml +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/requirements.txt +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/setup.cfg +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/setup.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_MRFs.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_abstract_distribution_density.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_bayesian_inversion.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_density.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_distribution.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_distributions_shape.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_geometry.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_implicit_priors.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_joint_distribution.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_likelihood.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_model.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_pde.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_posterior.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_problem.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_sampler.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_samples.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_solver.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_testproblem.py +0 -0
- {cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.1.0
|
|
3
|
+
Version: 1.1.0.post0.dev17
|
|
4
4
|
Summary: Computational Uncertainty Quantification for Inverse problems in Python
|
|
5
5
|
Maintainer-email: "Nicolai A. B. Riis" <nabr@dtu.dk>, "Jakob S. Jørgensen" <jakj@dtu.dk>, "Amal M. Alghamdi" <amaal@dtu.dk>, Chao Zhang <chaz@dtu.dk>
|
|
6
6
|
License: Apache License
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.1.0
|
|
3
|
+
Version: 1.1.0.post0.dev17
|
|
4
4
|
Summary: Computational Uncertainty Quantification for Inverse problems in Python
|
|
5
5
|
Maintainer-email: "Nicolai A. B. Riis" <nabr@dtu.dk>, "Jakob S. Jørgensen" <jakj@dtu.dk>, "Amal M. Alghamdi" <amaal@dtu.dk>, Chao Zhang <chaz@dtu.dk>
|
|
6
6
|
License: Apache License
|
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2024-
|
|
11
|
+
"date": "2024-08-26T08:07:58+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.1.0"
|
|
14
|
+
"full-revisionid": "9d87eb837ab12ccedf61101e396df2ab1cb37764",
|
|
15
|
+
"version": "1.1.0.post0.dev17"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
""" Re-implementation of sampler module in a more object oriented way. """
|
|
2
|
+
|
|
3
|
+
from ._sampler import Sampler, ProposalBasedSampler
|
|
4
|
+
from ._langevin_algorithm import ULA, MALA
|
|
5
|
+
from ._mh import MH
|
|
6
|
+
from ._pcn import PCN
|
|
7
|
+
from ._rto import LinearRTO, RegularizedLinearRTO
|
|
8
|
+
from ._cwmh import CWMH
|
|
9
|
+
from ._laplace_approximation import UGLA
|
|
10
|
+
from ._hmc import NUTS
|
|
11
|
+
from ._gibbs import HybridGibbs
|
|
12
|
+
from ._conjugate import Conjugate
|
|
13
|
+
from ._conjugate_approx import ConjugateApprox
|
|
14
|
+
from ._direct import Direct
|
|
15
|
+
from ._utilities import find_valid_samplers
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
3
|
import math
|
|
4
|
-
from cuqi.experimental.mcmc import
|
|
4
|
+
from cuqi.experimental.mcmc import Sampler
|
|
5
5
|
from cuqi.distribution import Posterior, Gaussian, Gamma, GMRF
|
|
6
6
|
from cuqi.implicitprior import RegularizedGaussian, RegularizedGMRF
|
|
7
7
|
from cuqi.utilities import get_non_default_args
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class Conjugate(Sampler):
|
|
10
10
|
""" Conjugate sampler
|
|
11
11
|
|
|
12
12
|
Sampler for sampling a posterior distribution which is a so-called "conjugate" distribution, i.e., where the likelihood and prior are conjugate to each other - denoted as a conjugate pair.
|
|
@@ -34,7 +34,7 @@ class ConjugateNew(SamplerNew):
|
|
|
34
34
|
def _initialize(self):
|
|
35
35
|
pass
|
|
36
36
|
|
|
37
|
-
@
|
|
37
|
+
@Sampler.target.setter # Overwrite the target setter to set the conjugate pair
|
|
38
38
|
def target(self, value):
|
|
39
39
|
""" Set the target density. Runs validation of the target. """
|
|
40
40
|
self._target = value
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
-
from cuqi.experimental.mcmc import
|
|
2
|
+
from cuqi.experimental.mcmc import Conjugate
|
|
3
3
|
from cuqi.experimental.mcmc._conjugate import _ConjugatePair, _get_conjugate_parameter, _check_conjugate_parameter_is_scalar_reciprocal
|
|
4
4
|
from cuqi.distribution import LMRF, Gamma
|
|
5
5
|
import scipy as sp
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class ConjugateApprox(Conjugate):
|
|
8
8
|
""" Approximate Conjugate sampler
|
|
9
9
|
|
|
10
10
|
Sampler for sampling a posterior distribution where the likelihood and prior can be approximated
|
|
@@ -17,7 +17,7 @@ class ConjugateApproxNew(ConjugateNew):
|
|
|
17
17
|
|
|
18
18
|
LMRF likelihood must have zero mean.
|
|
19
19
|
|
|
20
|
-
For more details on conjugacy see :class:`
|
|
20
|
+
For more details on conjugacy see :class:`Conjugate`.
|
|
21
21
|
|
|
22
22
|
"""
|
|
23
23
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import cuqi
|
|
3
|
-
from cuqi.experimental.mcmc import
|
|
3
|
+
from cuqi.experimental.mcmc import ProposalBasedSampler
|
|
4
4
|
from cuqi.array import CUQIarray
|
|
5
5
|
from numbers import Number
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class CWMH(ProposalBasedSampler):
|
|
8
8
|
"""Component-wise Metropolis Hastings sampler.
|
|
9
9
|
|
|
10
10
|
Allows sampling of a target distribution by a component-wise random-walk
|
|
@@ -40,7 +40,7 @@ class CWMHNew(ProposalBasedSamplerNew):
|
|
|
40
40
|
|
|
41
41
|
kwargs : dict
|
|
42
42
|
Additional keyword arguments to be passed to the base class
|
|
43
|
-
:class:`
|
|
43
|
+
:class:`ProposalBasedSampler`.
|
|
44
44
|
|
|
45
45
|
Example
|
|
46
46
|
-------
|
|
@@ -61,14 +61,14 @@ class CWMHNew(ProposalBasedSamplerNew):
|
|
|
61
61
|
dim=dim, logpdf_func=logpdf_func)
|
|
62
62
|
|
|
63
63
|
# Set up sampler
|
|
64
|
-
sampler = cuqi.experimental.mcmc.
|
|
64
|
+
sampler = cuqi.experimental.mcmc.CWMH(target, scale=1)
|
|
65
65
|
|
|
66
66
|
# Sample
|
|
67
67
|
samples = sampler.sample(2000).get_samples()
|
|
68
68
|
|
|
69
69
|
"""
|
|
70
70
|
|
|
71
|
-
_STATE_KEYS =
|
|
71
|
+
_STATE_KEYS = ProposalBasedSampler._STATE_KEYS.union(['_scale_temp'])
|
|
72
72
|
|
|
73
73
|
def __init__(self, target:cuqi.density.Density=None, proposal=None, scale=1,
|
|
74
74
|
initial_point=None, **kwargs):
|
|
@@ -78,7 +78,7 @@ class CWMHNew(ProposalBasedSamplerNew):
|
|
|
78
78
|
def _initialize(self):
|
|
79
79
|
if isinstance(self.scale, Number):
|
|
80
80
|
self.scale = np.ones(self.dim)*self.scale
|
|
81
|
-
self._acc = [np.ones((self.dim))] # Overwrite acc from
|
|
81
|
+
self._acc = [np.ones((self.dim))] # Overwrite acc from ProposalBasedSampler with list of arrays
|
|
82
82
|
|
|
83
83
|
# Handling of temporary scale parameter due to possible bug in old CWMH
|
|
84
84
|
self._scale_temp = self.scale.copy()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from cuqi.experimental.mcmc import
|
|
1
|
+
from cuqi.experimental.mcmc import Sampler
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class Direct(Sampler):
|
|
4
4
|
""" Direct sampler
|
|
5
5
|
|
|
6
6
|
This sampler is used to sample from a target distribution directly. It simply calls the sample method of the target object to generate a sample.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from cuqi.distribution import JointDistribution
|
|
2
|
-
from cuqi.experimental.mcmc import
|
|
2
|
+
from cuqi.experimental.mcmc import Sampler
|
|
3
3
|
from cuqi.samples import Samples
|
|
4
4
|
from typing import Dict
|
|
5
5
|
import numpy as np
|
|
@@ -12,9 +12,9 @@ except ImportError:
|
|
|
12
12
|
warnings.warn("Module mcmc: Progressbar not found. Install progressbar2 to get sampling progress.")
|
|
13
13
|
return iterable
|
|
14
14
|
|
|
15
|
-
# Not subclassed from
|
|
15
|
+
# Not subclassed from Sampler as Gibbs handles multiple samplers and samples multiple parameters
|
|
16
16
|
# Similar approach as for JointDistribution
|
|
17
|
-
class
|
|
17
|
+
class HybridGibbs:
|
|
18
18
|
"""
|
|
19
19
|
Hybrid Gibbs sampler for sampling a joint distribution.
|
|
20
20
|
|
|
@@ -80,13 +80,13 @@ class HybridGibbsNew:
|
|
|
80
80
|
|
|
81
81
|
# Define sampling strategy
|
|
82
82
|
sampling_strategy = {
|
|
83
|
-
'x': cuqi.experimental.mcmc.
|
|
84
|
-
'd': cuqi.experimental.mcmc.
|
|
85
|
-
'l': cuqi.experimental.mcmc.
|
|
83
|
+
'x': cuqi.experimental.mcmc.LinearRTO(maxit=15),
|
|
84
|
+
'd': cuqi.experimental.mcmc.Conjugate(),
|
|
85
|
+
'l': cuqi.experimental.mcmc.Conjugate(),
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
# Define Gibbs sampler
|
|
89
|
-
sampler = cuqi.experimental.mcmc.
|
|
89
|
+
sampler = cuqi.experimental.mcmc.HybridGibbs(posterior, sampling_strategy)
|
|
90
90
|
|
|
91
91
|
# Run sampler
|
|
92
92
|
samples = sampler.sample(Ns=1000, Nb=200)
|
|
@@ -98,7 +98,7 @@ class HybridGibbsNew:
|
|
|
98
98
|
|
|
99
99
|
"""
|
|
100
100
|
|
|
101
|
-
def __init__(self, target: JointDistribution, sampling_strategy: Dict[str,
|
|
101
|
+
def __init__(self, target: JointDistribution, sampling_strategy: Dict[str, Sampler], num_sampling_steps: Dict[str, int] = None):
|
|
102
102
|
|
|
103
103
|
# Store target and allow conditioning to reduce to a single density
|
|
104
104
|
self.target = target() # Create a copy of target distribution (to avoid modifying the original)
|
|
@@ -150,13 +150,13 @@ class HybridGibbsNew:
|
|
|
150
150
|
for sampler in self.samplers.values():
|
|
151
151
|
sampler.validate_target()
|
|
152
152
|
|
|
153
|
-
def sample(self, Ns) -> '
|
|
153
|
+
def sample(self, Ns) -> 'HybridGibbs':
|
|
154
154
|
""" Sample from the joint distribution using Gibbs sampling """
|
|
155
155
|
for _ in progressbar(range(Ns)):
|
|
156
156
|
self.step()
|
|
157
157
|
self._store_samples()
|
|
158
158
|
|
|
159
|
-
def warmup(self, Nb) -> '
|
|
159
|
+
def warmup(self, Nb) -> 'HybridGibbs':
|
|
160
160
|
""" Warmup (tune) the Gibbs sampler """
|
|
161
161
|
for idx in progressbar(range(Nb)):
|
|
162
162
|
self.step()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import numpy as np
|
|
3
|
-
from cuqi.experimental.mcmc import
|
|
3
|
+
from cuqi.experimental.mcmc import Sampler
|
|
4
4
|
from cuqi.array import CUQIarray
|
|
5
5
|
from numbers import Number
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class NUTS(Sampler):
|
|
8
8
|
"""No-U-Turn Sampler (Hoffman and Gelman, 2014).
|
|
9
9
|
|
|
10
10
|
Samples a distribution given its logpdf and gradient using a Hamiltonian
|
|
@@ -58,7 +58,7 @@ class NUTSNew(SamplerNew):
|
|
|
58
58
|
target = tp.posterior
|
|
59
59
|
|
|
60
60
|
# Set up sampler
|
|
61
|
-
sampler = cuqi.experimental.mcmc.
|
|
61
|
+
sampler = cuqi.experimental.mcmc.NUTS(target)
|
|
62
62
|
|
|
63
63
|
# Sample
|
|
64
64
|
sampler.warmup(5000)
|
|
@@ -87,11 +87,11 @@ class NUTSNew(SamplerNew):
|
|
|
87
87
|
|
|
88
88
|
"""
|
|
89
89
|
|
|
90
|
-
_STATE_KEYS =
|
|
90
|
+
_STATE_KEYS = Sampler._STATE_KEYS.union({'_epsilon', '_epsilon_bar',
|
|
91
91
|
'_H_bar', '_mu',
|
|
92
92
|
'_alpha', '_n_alpha'})
|
|
93
93
|
|
|
94
|
-
_HISTORY_KEYS =
|
|
94
|
+
_HISTORY_KEYS = Sampler._HISTORY_KEYS.union({'num_tree_node_list',
|
|
95
95
|
'epsilon_list',
|
|
96
96
|
'epsilon_bar_list'})
|
|
97
97
|
|
|
@@ -120,7 +120,7 @@ class NUTSNew(SamplerNew):
|
|
|
120
120
|
def _initialize(self):
|
|
121
121
|
|
|
122
122
|
# Arrays to store acceptance rate
|
|
123
|
-
self._acc = [None] # Overwrites acc from
|
|
123
|
+
self._acc = [None] # Overwrites acc from Sampler. TODO. Check if this is necessary
|
|
124
124
|
|
|
125
125
|
self._alpha = 0 # check if meaningful value
|
|
126
126
|
self._n_alpha = 0 # check if meaningful value
|
|
@@ -188,7 +188,7 @@ class NUTSNew(SamplerNew):
|
|
|
188
188
|
self._opt_acc_rate = value
|
|
189
189
|
|
|
190
190
|
#=========================================================================
|
|
191
|
-
#================== Implement methods required by
|
|
191
|
+
#================== Implement methods required by Sampler =============
|
|
192
192
|
#=========================================================================
|
|
193
193
|
def validate_target(self):
|
|
194
194
|
# Check if the target has logd and gradient methods
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import cuqi
|
|
3
|
-
from cuqi.experimental.mcmc import
|
|
3
|
+
from cuqi.experimental.mcmc import Sampler
|
|
4
4
|
from cuqi.array import CUQIarray
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class ULA(Sampler): # Refactor to Proposal-based sampler?
|
|
7
7
|
"""Unadjusted Langevin algorithm (ULA) (Roberts and Tweedie, 1996)
|
|
8
8
|
|
|
9
9
|
Samples a distribution given its logpdf and gradient (up to a constant) based on
|
|
@@ -52,7 +52,7 @@ class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
|
|
|
52
52
|
gradient_func=gradient_func)
|
|
53
53
|
|
|
54
54
|
# Set up sampler
|
|
55
|
-
sampler = cuqi.experimental.mcmc.
|
|
55
|
+
sampler = cuqi.experimental.mcmc.ULA(target, scale=1/dim**2)
|
|
56
56
|
|
|
57
57
|
# Sample
|
|
58
58
|
sampler.sample(2000)
|
|
@@ -61,7 +61,7 @@ class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
|
|
|
61
61
|
# TODO: update demo once sampler merged
|
|
62
62
|
"""
|
|
63
63
|
|
|
64
|
-
_STATE_KEYS =
|
|
64
|
+
_STATE_KEYS = Sampler._STATE_KEYS.union({'current_target_logd', 'scale', 'current_target_grad'})
|
|
65
65
|
|
|
66
66
|
def __init__(self, target=None, scale=1.0, **kwargs):
|
|
67
67
|
|
|
@@ -125,7 +125,7 @@ class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
|
|
|
125
125
|
pass
|
|
126
126
|
|
|
127
127
|
|
|
128
|
-
class
|
|
128
|
+
class MALA(ULA): # Refactor to Proposal-based sampler?
|
|
129
129
|
""" Metropolis-adjusted Langevin algorithm (MALA) (Roberts and Tweedie, 1996)
|
|
130
130
|
|
|
131
131
|
Samples a distribution given its logd and gradient (up to a constant) based on
|
|
@@ -174,7 +174,7 @@ class MALANew(ULANew): # Refactor to Proposal-based sampler?
|
|
|
174
174
|
gradient_func=gradient_func)
|
|
175
175
|
|
|
176
176
|
# Set up sampler
|
|
177
|
-
sampler = cuqi.experimental.mcmc.
|
|
177
|
+
sampler = cuqi.experimental.mcmc.MALA(target, scale=1/5**2)
|
|
178
178
|
|
|
179
179
|
# Sample
|
|
180
180
|
sampler.sample(2000)
|
|
@@ -2,9 +2,9 @@ import scipy as sp
|
|
|
2
2
|
import numpy as np
|
|
3
3
|
import cuqi
|
|
4
4
|
from cuqi.solver import CGLS
|
|
5
|
-
from cuqi.experimental.mcmc import
|
|
5
|
+
from cuqi.experimental.mcmc import Sampler
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class UGLA(Sampler):
|
|
8
8
|
""" Unadjusted (Gaussian) Laplace Approximation sampler
|
|
9
9
|
|
|
10
10
|
Samples an approximate posterior where the prior is approximated
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import cuqi
|
|
3
|
-
from cuqi.experimental.mcmc import
|
|
3
|
+
from cuqi.experimental.mcmc import ProposalBasedSampler
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class MH(ProposalBasedSampler):
|
|
7
7
|
""" Metropolis-Hastings (MH) sampler.
|
|
8
8
|
|
|
9
9
|
Parameters
|
|
@@ -18,11 +18,11 @@ class MHNew(ProposalBasedSamplerNew):
|
|
|
18
18
|
Scaling parameter for the proposal distribution.
|
|
19
19
|
|
|
20
20
|
kwargs : dict
|
|
21
|
-
Additional keyword arguments to be passed to the base class :class:`
|
|
21
|
+
Additional keyword arguments to be passed to the base class :class:`ProposalBasedSampler`.
|
|
22
22
|
|
|
23
23
|
"""
|
|
24
24
|
|
|
25
|
-
_STATE_KEYS =
|
|
25
|
+
_STATE_KEYS = ProposalBasedSampler._STATE_KEYS.union({'scale', '_scale_temp'})
|
|
26
26
|
|
|
27
27
|
def __init__(self, target=None, proposal=None, scale=1, **kwargs):
|
|
28
28
|
super().__init__(target, proposal=proposal, scale=scale, **kwargs)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import cuqi
|
|
3
|
-
from cuqi.experimental.mcmc import
|
|
3
|
+
from cuqi.experimental.mcmc import Sampler
|
|
4
4
|
from cuqi.array import CUQIarray
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class PCN(Sampler): # Refactor to Proposal-based sampler?
|
|
7
7
|
|
|
8
|
-
_STATE_KEYS =
|
|
8
|
+
_STATE_KEYS = Sampler._STATE_KEYS.union({'scale', 'current_likelihood_logd', 'lambd'})
|
|
9
9
|
|
|
10
10
|
def __init__(self, target=None, scale=1.0, **kwargs):
|
|
11
11
|
|
|
@@ -4,10 +4,10 @@ from scipy.sparse.linalg import LinearOperator as scipyLinearOperator
|
|
|
4
4
|
import numpy as np
|
|
5
5
|
import cuqi
|
|
6
6
|
from cuqi.solver import CGLS, FISTA
|
|
7
|
-
from cuqi.experimental.mcmc import
|
|
7
|
+
from cuqi.experimental.mcmc import Sampler
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class LinearRTO(Sampler):
|
|
11
11
|
"""
|
|
12
12
|
Linear RTO (Randomize-Then-Optimize) sampler.
|
|
13
13
|
|
|
@@ -155,7 +155,7 @@ class LinearRTONew(SamplerNew):
|
|
|
155
155
|
""" Get the default initial point for the sampler. Defaults to an array of zeros. """
|
|
156
156
|
return np.zeros(self.dim)
|
|
157
157
|
|
|
158
|
-
class
|
|
158
|
+
class RegularizedLinearRTO(LinearRTO):
|
|
159
159
|
"""
|
|
160
160
|
Regularized Linear RTO (Randomize-Then-Optimize) sampler.
|
|
161
161
|
|
|
@@ -13,7 +13,7 @@ except ImportError:
|
|
|
13
13
|
warnings.warn("Module mcmc: Progressbar not found. Install progressbar2 to get sampling progress.")
|
|
14
14
|
return iterable
|
|
15
15
|
|
|
16
|
-
class
|
|
16
|
+
class Sampler(ABC):
|
|
17
17
|
""" Abstract base class for all samplers.
|
|
18
18
|
|
|
19
19
|
Provides a common interface for all samplers. The interface includes methods for sampling, warmup and getting the samples in an object oriented way.
|
|
@@ -194,7 +194,7 @@ class SamplerNew(ABC):
|
|
|
194
194
|
|
|
195
195
|
self.set_state(state)
|
|
196
196
|
|
|
197
|
-
def sample(self, Ns, batch_size=0, sample_path='./CUQI_samples/') -> '
|
|
197
|
+
def sample(self, Ns, batch_size=0, sample_path='./CUQI_samples/') -> 'Sampler':
|
|
198
198
|
""" Sample Ns samples from the target density.
|
|
199
199
|
|
|
200
200
|
Parameters
|
|
@@ -239,7 +239,7 @@ class SamplerNew(ABC):
|
|
|
239
239
|
return self
|
|
240
240
|
|
|
241
241
|
|
|
242
|
-
def warmup(self, Nb, tune_freq=0.1) -> '
|
|
242
|
+
def warmup(self, Nb, tune_freq=0.1) -> 'Sampler':
|
|
243
243
|
""" Warmup the sampler by drawing Nb samples.
|
|
244
244
|
|
|
245
245
|
Parameters
|
|
@@ -407,10 +407,10 @@ class SamplerNew(ABC):
|
|
|
407
407
|
msg += f"\t {key}: {value} \n"
|
|
408
408
|
return msg
|
|
409
409
|
|
|
410
|
-
class
|
|
410
|
+
class ProposalBasedSampler(Sampler, ABC):
|
|
411
411
|
""" Abstract base class for samplers that use a proposal distribution. """
|
|
412
412
|
|
|
413
|
-
_STATE_KEYS =
|
|
413
|
+
_STATE_KEYS = Sampler._STATE_KEYS.union({'current_target_logd', 'scale'})
|
|
414
414
|
|
|
415
415
|
def __init__(self, target=None, proposal=None, scale=1, **kwargs):
|
|
416
416
|
""" Initializer for abstract base class for samplers that use a proposal distribution.
|
|
@@ -419,7 +419,7 @@ class ProposalBasedSamplerNew(SamplerNew, ABC):
|
|
|
419
419
|
|
|
420
420
|
Initialization of the sampler should be done in the _initialize method.
|
|
421
421
|
|
|
422
|
-
See :class:`
|
|
422
|
+
See :class:`Sampler` for additional details.
|
|
423
423
|
|
|
424
424
|
Parameters
|
|
425
425
|
----------
|
|
@@ -433,7 +433,7 @@ class ProposalBasedSamplerNew(SamplerNew, ABC):
|
|
|
433
433
|
The scale parameter for the proposal distribution.
|
|
434
434
|
|
|
435
435
|
**kwargs : dict
|
|
436
|
-
Additional keyword arguments passed to the :class:`
|
|
436
|
+
Additional keyword arguments passed to the :class:`Sampler` initializer.
|
|
437
437
|
|
|
438
438
|
"""
|
|
439
439
|
|
|
@@ -4,7 +4,7 @@ import inspect
|
|
|
4
4
|
def find_valid_samplers(target):
|
|
5
5
|
""" Finds all samplers in the cuqi.experimental.mcmc module that accept the provided target. """
|
|
6
6
|
|
|
7
|
-
all_samplers = [(name, cls) for name, cls in inspect.getmembers(cuqi.experimental.mcmc, inspect.isclass) if issubclass(cls, cuqi.experimental.mcmc.
|
|
7
|
+
all_samplers = [(name, cls) for name, cls in inspect.getmembers(cuqi.experimental.mcmc, inspect.isclass) if issubclass(cls, cuqi.experimental.mcmc.Sampler)]
|
|
8
8
|
valid_samplers = []
|
|
9
9
|
|
|
10
10
|
for name, sampler in all_samplers:
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
""" Re-implementation of sampler module in a more object oriented way. """
|
|
2
|
-
|
|
3
|
-
from ._sampler import SamplerNew, ProposalBasedSamplerNew
|
|
4
|
-
from ._langevin_algorithm import ULANew, MALANew
|
|
5
|
-
from ._mh import MHNew
|
|
6
|
-
from ._pcn import PCNNew
|
|
7
|
-
from ._rto import LinearRTONew, RegularizedLinearRTONew
|
|
8
|
-
from ._cwmh import CWMHNew
|
|
9
|
-
from ._laplace_approximation import UGLANew
|
|
10
|
-
from ._hmc import NUTSNew
|
|
11
|
-
from ._gibbs import HybridGibbsNew
|
|
12
|
-
from ._conjugate import ConjugateNew
|
|
13
|
-
from ._conjugate_approx import ConjugateApproxNew
|
|
14
|
-
from ._direct import DirectNew
|
|
15
|
-
from ._utilities import find_valid_samplers
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.0 → cuqipy-1.1.0.post0.dev17}/cuqi/implicitprior/_regularizedUnboundedUniform.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|