CUQIpy 1.1.1.post0.dev78__tar.gz → 1.1.1.post0.dev88__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.
Potentially problematic release.
This version of CUQIpy might be problematic. Click here for more details.
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/CUQIpy.egg-info/PKG-INFO +1 -1
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/PKG-INFO +1 -1
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/_version.py +3 -3
- cuqipy-1.1.1.post0.dev88/cuqi/experimental/mcmc/__init__.py +123 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_gibbs.py +4 -4
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_sampler.py +2 -2
- cuqipy-1.1.1.post0.dev88/cuqi/samples/__init__.py +1 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/samples/_samples.py +20 -0
- cuqipy-1.1.1.post0.dev78/cuqi/experimental/mcmc/__init__.py +0 -15
- cuqipy-1.1.1.post0.dev78/cuqi/samples/__init__.py +0 -1
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/CUQIpy.egg-info/SOURCES.txt +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/CUQIpy.egg-info/dependency_links.txt +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/CUQIpy.egg-info/requires.txt +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/CUQIpy.egg-info/top_level.txt +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/LICENSE +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/README.md +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/_messages.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/array/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/array/_array.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/config.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/_data.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/astronaut.npz +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/camera.npz +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/cat.npz +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/cookie.png +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/data/satellite.mat +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/density/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/density/_density.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/diagnostics.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_beta.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_cauchy.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_cmrf.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_custom.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_distribution.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_gamma.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_gaussian.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_gmrf.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_inverse_gamma.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_joint_distribution.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_laplace.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_lmrf.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_lognormal.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_modifiedhalfnormal.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_normal.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_posterior.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_smoothed_laplace.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_uniform.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_conjugate.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_conjugate_approx.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_cwmh.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_direct.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_hmc.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_langevin_algorithm.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_laplace_approximation.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_mh.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_pcn.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_rto.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_utilities.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/geometry/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/geometry/_geometry.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/implicitprior/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/implicitprior/_regularizedGMRF.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/implicitprior/_regularizedGaussian.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/implicitprior/_regularizedUnboundedUniform.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/likelihood/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/likelihood/_likelihood.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/model/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/model/_model.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/operator/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/operator/_operator.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/pde/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/pde/_pde.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/problem/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/problem/_problem.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_conjugate.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_conjugate_approx.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_cwmh.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_gibbs.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_hmc.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_langevin_algorithm.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_laplace_approximation.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_mh.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_pcn.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_rto.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_sampler.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/solver/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/solver/_solver.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/testproblem/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/testproblem/_testproblem.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/utilities/__init__.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/utilities/_get_python_variable_name.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/utilities/_utilities.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/pyproject.toml +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/requirements.txt +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/setup.cfg +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/setup.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_MRFs.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_abstract_distribution_density.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_bayesian_inversion.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_density.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_distribution.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_distributions_shape.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_geometry.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_implicit_priors.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_joint_distribution.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_likelihood.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_model.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_pde.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_posterior.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_problem.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_sampler.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_samples.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_solver.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_testproblem.py +0 -0
- {cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.1.1.post0.
|
|
3
|
+
Version: 1.1.1.post0.dev88
|
|
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.1.post0.
|
|
3
|
+
Version: 1.1.1.post0.dev88
|
|
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-09-
|
|
11
|
+
"date": "2024-09-12T22:06:24+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.1.1.post0.
|
|
14
|
+
"full-revisionid": "f2fb34068f8c84bf37b3e4049a8a77391d3c432e",
|
|
15
|
+
"version": "1.1.1.post0.dev88"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Re-implementation of sampler module in a more object-oriented way.
|
|
3
|
+
|
|
4
|
+
Main changes for users
|
|
5
|
+
----------------------
|
|
6
|
+
|
|
7
|
+
1. Sampling API
|
|
8
|
+
^^^^^^^^^^^^
|
|
9
|
+
|
|
10
|
+
Previously one would call the `.sample` or `sample_adapt` methods of a sampler instance at :py:mod:`cuqi.sampler` to sample from a target distribution and store the samples as the output as follows:
|
|
11
|
+
|
|
12
|
+
.. code-block:: python
|
|
13
|
+
|
|
14
|
+
from cuqi.sampler import MH
|
|
15
|
+
from cuqi.distribution import DistributionGallery
|
|
16
|
+
|
|
17
|
+
# Target distribution
|
|
18
|
+
target = DistributionGallery("donut")
|
|
19
|
+
|
|
20
|
+
# Set up sampler
|
|
21
|
+
sampler = MH(target)
|
|
22
|
+
|
|
23
|
+
# Sample from the target distribution (Alternatively calling sample with explicit scale parameter set in sampler)
|
|
24
|
+
samples = sampler.sample_adapt(Ns=100, Nb=100) # Burn-in (Nb) removed by default
|
|
25
|
+
|
|
26
|
+
This has now changed to to a more object-oriented API which provides more flexibility and control over the sampling process.
|
|
27
|
+
|
|
28
|
+
For example one can now more explicitly control when the sampler is tuned (warmup) and when it is sampling with fixed parameters.
|
|
29
|
+
|
|
30
|
+
.. code-block:: python
|
|
31
|
+
|
|
32
|
+
from cuqi.experimental.mcmc import MH
|
|
33
|
+
from cuqi.distribution import DistributionGallery
|
|
34
|
+
|
|
35
|
+
# Target distribution
|
|
36
|
+
target = DistributionGallery("donut")
|
|
37
|
+
|
|
38
|
+
# Set up sampler
|
|
39
|
+
sampler = MH(target)
|
|
40
|
+
|
|
41
|
+
# Sample from the target distribution
|
|
42
|
+
sampler.warmup(Nb=100) # Explicit warmup (tuning) of sampler
|
|
43
|
+
sampler.sample(Ns=100) # Sampling with fixed parameters
|
|
44
|
+
samples = sampler.get_samples().burnthin(Nb=100) # Getting samples and removing burn-in from warmup
|
|
45
|
+
|
|
46
|
+
Importantly, the removal of burn-in from e.g. warmup is now a separate step that is done after the sampling process is complete.
|
|
47
|
+
|
|
48
|
+
2. Sampling API for BayesianProblem
|
|
49
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
50
|
+
|
|
51
|
+
:py:class:`cuqi.problem.BayesianProblem` continues to have the same API for `sample_posterior` and the `UQ` method.
|
|
52
|
+
|
|
53
|
+
There is now a flag `experimental` that can be set to `True` to use the new MCMC samplers.
|
|
54
|
+
|
|
55
|
+
By default, the flag is set to `False` and the old samplers are used.
|
|
56
|
+
|
|
57
|
+
For this more high-level interface, burn-in is automatically removed from the samples as was the case before.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
3. More options for Gibbs sampling
|
|
61
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
62
|
+
|
|
63
|
+
There are now more options for Gibbs sampling. Previously it was only possible to sample with Gibbs for samplers :py:class:`cuqi.sampler.LinearRTO`, :py:class:`cuqi.sampler.RegularizedLinearRTO`, :py:class:`cuqi.sampler.Conjugate`, and :py:class:`cuqi.sampler.ConjugateApprox`.
|
|
64
|
+
|
|
65
|
+
Now, it is possible to define a Gibbs sampling scheme using any sampler from the :py:mod:`cuqi.experimental.mcmc` module.
|
|
66
|
+
|
|
67
|
+
**Example using a NUTS-within-Gibbs scheme for a 1D deconvolution problem:**
|
|
68
|
+
|
|
69
|
+
.. code-block:: python
|
|
70
|
+
|
|
71
|
+
import cuqi
|
|
72
|
+
import numpy as np
|
|
73
|
+
from cuqi.distribution import Gamma, Gaussian, GMRF, JointDistribution
|
|
74
|
+
from cuqi.experimental.mcmc import NUTS, HybridGibbs, Conjugate
|
|
75
|
+
from cuqi.testproblem import Deconvolution1D
|
|
76
|
+
|
|
77
|
+
# Forward problem
|
|
78
|
+
A, y_data, info = Deconvolution1D(dim=128, phantom='sinc', noise_std=0.001).get_components()
|
|
79
|
+
|
|
80
|
+
# Bayesian Inverse Problem
|
|
81
|
+
s = Gamma(1, 1e-4)
|
|
82
|
+
x = GMRF(np.zeros(A.domain_dim), 50)
|
|
83
|
+
y = Gaussian(A @ x, lambda s: 1 / s)
|
|
84
|
+
|
|
85
|
+
# Posterior
|
|
86
|
+
target = JointDistribution(y, x, s)(y=y_data)
|
|
87
|
+
|
|
88
|
+
# Gibbs sampling strategy. Note we can define initial_points and various parameters for each sampler
|
|
89
|
+
sampling_strategy = {
|
|
90
|
+
"x": NUTS(max_depth=10, initial_point=np.zeros(A.domain_dim)),
|
|
91
|
+
"s": Conjugate()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Here we do 10 internal steps with NUTS for each Gibbs step
|
|
95
|
+
num_sampling_steps = {
|
|
96
|
+
"x": 10,
|
|
97
|
+
"s": 1
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
sampler = HybridGibbs(target, sampling_strategy, num_sampling_steps)
|
|
101
|
+
|
|
102
|
+
sampler.warmup(50)
|
|
103
|
+
sampler.sample(200)
|
|
104
|
+
samples = sampler.get_samples().burnthin(Nb=50)
|
|
105
|
+
|
|
106
|
+
samples["x"].plot_ci(exact=info.exactSolution)
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
from ._sampler import Sampler, ProposalBasedSampler
|
|
112
|
+
from ._langevin_algorithm import ULA, MALA
|
|
113
|
+
from ._mh import MH
|
|
114
|
+
from ._pcn import PCN
|
|
115
|
+
from ._rto import LinearRTO, RegularizedLinearRTO
|
|
116
|
+
from ._cwmh import CWMH
|
|
117
|
+
from ._laplace_approximation import UGLA
|
|
118
|
+
from ._hmc import NUTS
|
|
119
|
+
from ._gibbs import HybridGibbs
|
|
120
|
+
from ._conjugate import Conjugate
|
|
121
|
+
from ._conjugate_approx import ConjugateApprox
|
|
122
|
+
from ._direct import Direct
|
|
123
|
+
from ._utilities import find_valid_samplers
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from cuqi.distribution import JointDistribution
|
|
2
2
|
from cuqi.experimental.mcmc import Sampler
|
|
3
|
-
from cuqi.samples import Samples
|
|
3
|
+
from cuqi.samples import Samples, JointSamples
|
|
4
4
|
from cuqi.experimental.mcmc import NUTS
|
|
5
5
|
from typing import Dict
|
|
6
6
|
import numpy as np
|
|
@@ -161,7 +161,7 @@ class HybridGibbs:
|
|
|
161
161
|
|
|
162
162
|
"""
|
|
163
163
|
|
|
164
|
-
for _ in tqdm(range(Ns)):
|
|
164
|
+
for _ in tqdm(range(Ns), "Sample: "):
|
|
165
165
|
|
|
166
166
|
self.step()
|
|
167
167
|
|
|
@@ -184,7 +184,7 @@ class HybridGibbs:
|
|
|
184
184
|
|
|
185
185
|
tune_interval = max(int(tune_freq * Nb), 1)
|
|
186
186
|
|
|
187
|
-
for idx in tqdm(range(Nb)):
|
|
187
|
+
for idx in tqdm(range(Nb), "Warmup: "):
|
|
188
188
|
|
|
189
189
|
self.step()
|
|
190
190
|
|
|
@@ -197,7 +197,7 @@ class HybridGibbs:
|
|
|
197
197
|
return self
|
|
198
198
|
|
|
199
199
|
def get_samples(self) -> Dict[str, Samples]:
|
|
200
|
-
samples_object =
|
|
200
|
+
samples_object = JointSamples()
|
|
201
201
|
for par_name in self.par_names:
|
|
202
202
|
samples_array = np.array(self.samples[par_name]).T
|
|
203
203
|
samples_object[par_name] = Samples(samples_array, self.target.get_density(par_name).geometry)
|
|
@@ -220,7 +220,7 @@ class Sampler(ABC):
|
|
|
220
220
|
if hasattr(self, "_pre_sample"): self._pre_sample()
|
|
221
221
|
|
|
222
222
|
# Draw samples
|
|
223
|
-
for _ in tqdm( range(Ns) ):
|
|
223
|
+
for _ in tqdm( range(Ns), "Sample: "):
|
|
224
224
|
|
|
225
225
|
# Perform one step of the sampler
|
|
226
226
|
acc = self.step()
|
|
@@ -260,7 +260,7 @@ class Sampler(ABC):
|
|
|
260
260
|
if hasattr(self, "_pre_warmup"): self._pre_warmup()
|
|
261
261
|
|
|
262
262
|
# Draw warmup samples with tuning
|
|
263
|
-
for idx in tqdm(range(Nb)):
|
|
263
|
+
for idx in tqdm(range(Nb), "Warmup: "):
|
|
264
264
|
|
|
265
265
|
# Perform one step of the sampler
|
|
266
266
|
acc = self.step()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ._samples import Samples, JointSamples
|
|
@@ -867,3 +867,23 @@ class Samples(object):
|
|
|
867
867
|
"Geometry:\n {}\n\n".format(self.geometry) + \
|
|
868
868
|
"Shape:\n {}\n\n".format(self.shape) + \
|
|
869
869
|
"Samples:\n {}\n\n".format(self.samples)
|
|
870
|
+
|
|
871
|
+
class JointSamples(dict):
|
|
872
|
+
""" An object used to store samples from :class:`cuqi.distribution.JointDistribution`.
|
|
873
|
+
|
|
874
|
+
This object is a simple overload of the dictionary class to allow easy access to certain methods
|
|
875
|
+
of Samples objects without having to iterate over each key in the dictionary.
|
|
876
|
+
|
|
877
|
+
"""
|
|
878
|
+
|
|
879
|
+
def burnthin(self, Nb, Nt=1):
|
|
880
|
+
""" Remove burn-in and thin samples for all samples in the dictionary. Returns a copy of the samples stored in the dictionary. """
|
|
881
|
+
return JointSamples({key: samples.burnthin(Nb, Nt) for key, samples in self.items()})
|
|
882
|
+
|
|
883
|
+
def __repr__(self) -> str:
|
|
884
|
+
return "CUQIpy JointSamples Dict:\n" + \
|
|
885
|
+
"-------------------------\n\n" + \
|
|
886
|
+
"Keys:\n {}\n\n".format(list(self.keys())) + \
|
|
887
|
+
"Ns (number of samples):\n {}\n\n".format({key: samples.Ns for key, samples in self.items()}) + \
|
|
888
|
+
"Geometry:\n {}\n\n".format({key: samples.geometry for key, samples in self.items()}) + \
|
|
889
|
+
"Shape:\n {}\n\n".format({key: samples.shape for key, samples in self.items()})
|
|
@@ -1,15 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
from ._samples import Samples
|
|
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.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_joint_distribution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_modifiedhalfnormal.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/distribution/_smoothed_laplace.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_conjugate_approx.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/experimental/mcmc/_langevin_algorithm.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
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/implicitprior/_regularizedGMRF.py
RENAMED
|
File without changes
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/implicitprior/_regularizedGaussian.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
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/sampler/_laplace_approximation.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
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/cuqi/utilities/_get_python_variable_name.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.1.post0.dev78 → cuqipy-1.1.1.post0.dev88}/tests/test_abstract_distribution_density.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
|