CUQIpy 1.3.0.post0.dev5__tar.gz → 1.3.0.post0.dev16__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.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/CUQIpy.egg-info/PKG-INFO +1 -1
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/PKG-INFO +1 -1
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/_version.py +3 -3
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_cwmh.py +3 -6
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_gibbs.py +20 -3
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_hmc.py +3 -7
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_langevin_algorithm.py +12 -22
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_laplace_approximation.py +3 -5
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_rto.py +6 -10
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_sampler.py +7 -9
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/problem/_problem.py +4 -5
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/CUQIpy.egg-info/SOURCES.txt +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/CUQIpy.egg-info/dependency_links.txt +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/CUQIpy.egg-info/requires.txt +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/CUQIpy.egg-info/top_level.txt +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/LICENSE +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/README.md +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/_messages.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/array/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/array/_array.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/config.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/_data.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/astronaut.npz +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/camera.npz +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/cat.npz +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/cookie.png +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/data/satellite.mat +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/density/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/density/_density.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/diagnostics.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_beta.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_cauchy.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_cmrf.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_custom.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_distribution.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_gamma.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_gaussian.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_gmrf.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_inverse_gamma.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_joint_distribution.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_laplace.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_lmrf.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_lognormal.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_modifiedhalfnormal.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_normal.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_posterior.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_smoothed_laplace.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_truncated_normal.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_uniform.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/algebra/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/algebra/_ast.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/algebra/_orderedset.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/algebra/_randomvariable.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/geometry/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/geometry/_productgeometry.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_conjugate.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_conjugate_approx.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_direct.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_mh.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_pcn.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_utilities.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/geometry/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/geometry/_geometry.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/implicitprior/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/implicitprior/_regularizedGMRF.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/implicitprior/_regularizedGaussian.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/implicitprior/_regularizedUnboundedUniform.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/implicitprior/_restorator.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/likelihood/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/likelihood/_likelihood.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/model/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/model/_model.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/operator/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/operator/_operator.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/pde/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/pde/_pde.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/problem/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_conjugate.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_conjugate_approx.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_cwmh.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_gibbs.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_hmc.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_langevin_algorithm.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_laplace_approximation.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_mh.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_pcn.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_rto.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/sampler/_sampler.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/samples/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/samples/_samples.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/solver/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/solver/_solver.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/testproblem/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/testproblem/_testproblem.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/utilities/__init__.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/utilities/_get_python_variable_name.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/utilities/_utilities.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/pyproject.toml +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/requirements.txt +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/setup.cfg +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/setup.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_MRFs.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_abstract_distribution_density.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_bayesian_inversion.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_density.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_distribution.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_distributions_shape.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_geometry.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_implicit_priors.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_joint_distribution.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_likelihood.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_model.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_pde.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_posterior.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_problem.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_sampler.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_samples.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_solver.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_testproblem.py +0 -0
- {cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.3.0.post0.
|
|
3
|
+
Version: 1.3.0.post0.dev16
|
|
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.2
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.3.0.post0.
|
|
3
|
+
Version: 1.3.0.post0.dev16
|
|
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": "2025-02-
|
|
11
|
+
"date": "2025-02-21T15:28:16+0100",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.3.0.post0.
|
|
14
|
+
"full-revisionid": "d6846122ee3d1002dfd199cd586caa4cf3a18188",
|
|
15
|
+
"version": "1.3.0.post0.dev16"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -31,12 +31,9 @@ class CWMH(ProposalBasedSampler):
|
|
|
31
31
|
initial_point : ndarray
|
|
32
32
|
Initial parameters. *Optional*
|
|
33
33
|
|
|
34
|
-
callback : callable,
|
|
35
|
-
|
|
36
|
-
The
|
|
37
|
-
`callback(sample, sample_index)`, where `sample` is the current sample
|
|
38
|
-
and `sample_index` is the index of the sample.
|
|
39
|
-
An example is shown in demos/demo31_callback.py.
|
|
34
|
+
callback : callable, optional
|
|
35
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
36
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
40
37
|
|
|
41
38
|
kwargs : dict
|
|
42
39
|
Additional keyword arguments to be passed to the base class
|
|
@@ -58,6 +58,10 @@ class HybridGibbs:
|
|
|
58
58
|
will call its step method in each Gibbs step.
|
|
59
59
|
Default is 1 for all variables.
|
|
60
60
|
|
|
61
|
+
callback : callable, optional
|
|
62
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
63
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
64
|
+
|
|
61
65
|
Example
|
|
62
66
|
-------
|
|
63
67
|
.. code-block:: python
|
|
@@ -103,7 +107,7 @@ class HybridGibbs:
|
|
|
103
107
|
|
|
104
108
|
"""
|
|
105
109
|
|
|
106
|
-
def __init__(self, target: JointDistribution, sampling_strategy: Dict[str, Sampler], num_sampling_steps: Dict[str, int] = None):
|
|
110
|
+
def __init__(self, target: JointDistribution, sampling_strategy: Dict[str, Sampler], num_sampling_steps: Dict[str, int] = None, callback=None):
|
|
107
111
|
|
|
108
112
|
# Store target and allow conditioning to reduce to a single density
|
|
109
113
|
self.target = target() # Create a copy of target distribution (to avoid modifying the original)
|
|
@@ -120,6 +124,9 @@ class HybridGibbs:
|
|
|
120
124
|
# Initialize sampler (after target is set)
|
|
121
125
|
self._initialize()
|
|
122
126
|
|
|
127
|
+
# Set the callback function
|
|
128
|
+
self.callback = callback
|
|
129
|
+
|
|
123
130
|
def _initialize(self):
|
|
124
131
|
""" Initialize sampler """
|
|
125
132
|
|
|
@@ -158,13 +165,15 @@ class HybridGibbs:
|
|
|
158
165
|
The number of samples to draw.
|
|
159
166
|
|
|
160
167
|
"""
|
|
161
|
-
|
|
162
|
-
for _ in tqdm(range(Ns), "Sample: "):
|
|
168
|
+
for idx in tqdm(range(Ns), "Sample: "):
|
|
163
169
|
|
|
164
170
|
self.step()
|
|
165
171
|
|
|
166
172
|
self._store_samples()
|
|
167
173
|
|
|
174
|
+
# Call callback function if specified
|
|
175
|
+
self._call_callback(idx, Ns)
|
|
176
|
+
|
|
168
177
|
return self
|
|
169
178
|
|
|
170
179
|
def warmup(self, Nb, tune_freq=0.1) -> 'HybridGibbs':
|
|
@@ -192,6 +201,9 @@ class HybridGibbs:
|
|
|
192
201
|
|
|
193
202
|
self._store_samples()
|
|
194
203
|
|
|
204
|
+
# Call callback function if specified
|
|
205
|
+
self._call_callback(idx, Nb)
|
|
206
|
+
|
|
195
207
|
return self
|
|
196
208
|
|
|
197
209
|
def get_samples(self) -> Dict[str, Samples]:
|
|
@@ -263,6 +275,11 @@ class HybridGibbs:
|
|
|
263
275
|
self.samplers[par_name].tune(skip_len=skip_len, update_count=update_count)
|
|
264
276
|
|
|
265
277
|
# ------------ Private methods ------------
|
|
278
|
+
def _call_callback(self, sample_index, num_of_samples):
|
|
279
|
+
""" Calls the callback function. Assumes input is sampler, sample index, and total number of samples """
|
|
280
|
+
if self.callback is not None:
|
|
281
|
+
self.callback(self, sample_index, num_of_samples)
|
|
282
|
+
|
|
266
283
|
def _initialize_samplers(self):
|
|
267
284
|
""" Initialize samplers """
|
|
268
285
|
for sampler in self.samplers.values():
|
|
@@ -38,13 +38,9 @@ class NUTS(Sampler):
|
|
|
38
38
|
opt_acc_rate should be in (0, 1), however, choosing a value that is very
|
|
39
39
|
close to 1 or 0 might lead to poor performance of the sampler.
|
|
40
40
|
|
|
41
|
-
callback : callable,
|
|
42
|
-
|
|
43
|
-
The
|
|
44
|
-
`callback(sample, sample_index)`,
|
|
45
|
-
where `sample` is the current sample and `sample_index` is the index of
|
|
46
|
-
the sample.
|
|
47
|
-
An example is shown in demos/demo31_callback.py.
|
|
41
|
+
callback : callable, optional
|
|
42
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
43
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
48
44
|
|
|
49
45
|
Example
|
|
50
46
|
-------
|
{cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_langevin_algorithm.py
RENAMED
|
@@ -32,11 +32,9 @@ class ULA(Sampler): # Refactor to Proposal-based sampler?
|
|
|
32
32
|
be smaller than 1/L, where L is the Lipschitz of the gradient of the log
|
|
33
33
|
target density, logd).
|
|
34
34
|
|
|
35
|
-
callback : callable,
|
|
36
|
-
|
|
37
|
-
The
|
|
38
|
-
where `sample` is the current sample and `sample_index` is the index of the sample.
|
|
39
|
-
An example is shown in demos/demo31_callback.py.
|
|
35
|
+
callback : callable, optional
|
|
36
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
37
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
40
38
|
|
|
41
39
|
|
|
42
40
|
Example
|
|
@@ -164,11 +162,9 @@ class MALA(ULA): # Refactor to Proposal-based sampler?
|
|
|
164
162
|
be smaller than 1/L, where L is the Lipschitz of the gradient of the log
|
|
165
163
|
target density, logd).
|
|
166
164
|
|
|
167
|
-
callback : callable,
|
|
168
|
-
|
|
169
|
-
The
|
|
170
|
-
where `sample` is the current sample and `sample_index` is the index of the sample.
|
|
171
|
-
An example is shown in demos/demo31_callback.py.
|
|
165
|
+
callback : callable, optional
|
|
166
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
167
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
172
168
|
|
|
173
169
|
|
|
174
170
|
Example
|
|
@@ -288,12 +284,9 @@ class MYULA(ULA):
|
|
|
288
284
|
smoothing_strength : float
|
|
289
285
|
This parameter controls the smoothing strength of MYULA.
|
|
290
286
|
|
|
291
|
-
callback : callable,
|
|
292
|
-
|
|
293
|
-
The
|
|
294
|
-
where `sample` is the current sample and `sample_index` is the index of
|
|
295
|
-
the sample.
|
|
296
|
-
An example is shown in demos/demo31_callback.py.
|
|
287
|
+
callback : callable, optional
|
|
288
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
289
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
297
290
|
|
|
298
291
|
A Deblur example can be found in demos/howtos/myula.py
|
|
299
292
|
# TODO: update demo once sampler merged
|
|
@@ -378,12 +371,9 @@ class PnPULA(MYULA):
|
|
|
378
371
|
This parameter controls the smoothing strength of PnP-ULA.
|
|
379
372
|
|
|
380
373
|
|
|
381
|
-
callback : callable,
|
|
382
|
-
|
|
383
|
-
The
|
|
384
|
-
where `sample` is the current sample and `sample_index` is the index of
|
|
385
|
-
the sample.
|
|
386
|
-
An example is shown in demos/demo31_callback.py.
|
|
374
|
+
callback : callable, optional
|
|
375
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
376
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
387
377
|
|
|
388
378
|
# TODO: update demo once sampler merged
|
|
389
379
|
"""
|
|
@@ -43,11 +43,9 @@ class UGLA(Sampler):
|
|
|
43
43
|
sampling easier but results in a worse approximation. See details in Section 3.3 of the paper.
|
|
44
44
|
If not provided, it defaults to 1e-5.
|
|
45
45
|
|
|
46
|
-
callback : callable,
|
|
47
|
-
|
|
48
|
-
The
|
|
49
|
-
where `sample` is the current sample and `sample_index` is the index of the sample.
|
|
50
|
-
An example is shown in demos/demo31_callback.py.
|
|
46
|
+
callback : callable, optional
|
|
47
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
48
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
51
49
|
"""
|
|
52
50
|
def __init__(self, target=None, initial_point=None, maxit=50, tol=1e-4, beta=1e-5, **kwargs):
|
|
53
51
|
|
|
@@ -36,11 +36,9 @@ class LinearRTO(Sampler):
|
|
|
36
36
|
tol : float
|
|
37
37
|
Tolerance of the inner CGLS solver. *Optional*.
|
|
38
38
|
|
|
39
|
-
callback : callable,
|
|
40
|
-
|
|
41
|
-
The
|
|
42
|
-
where `sample` is the current sample and `sample_index` is the index of the sample.
|
|
43
|
-
An example is shown in demos/demo31_callback.py.
|
|
39
|
+
callback : callable, optional
|
|
40
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
41
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
44
42
|
|
|
45
43
|
"""
|
|
46
44
|
def __init__(self, target=None, initial_point=None, maxit=10, tol=1e-6, **kwargs):
|
|
@@ -204,11 +202,9 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
204
202
|
solver : string
|
|
205
203
|
If set to "ScipyLinearLSQ", solver is set to cuqi.solver.ScipyLinearLSQ, otherwise FISTA/ISTA or ADMM is used. Note "ScipyLinearLSQ" can only be used with `RegularizedGaussian` of `box` or `nonnegativity` constraint. *Optional*.
|
|
206
204
|
|
|
207
|
-
callback : callable,
|
|
208
|
-
|
|
209
|
-
The
|
|
210
|
-
where `sample` is the current sample and `sample_index` is the index of the sample.
|
|
211
|
-
An example is shown in demos/demo31_callback.py.
|
|
205
|
+
callback : callable, optional
|
|
206
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
207
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
212
208
|
|
|
213
209
|
"""
|
|
214
210
|
def __init__(self, target=None, initial_point=None, maxit=100, inner_max_it=10, stepsize="automatic", penalty_parameter=10, abstol=1e-10, adaptive=True, solver=None, inner_abstol=None, **kwargs):
|
|
@@ -59,9 +59,8 @@ class Sampler(ABC):
|
|
|
59
59
|
The initial point for the sampler. If not given, the sampler will choose an initial point.
|
|
60
60
|
|
|
61
61
|
callback : callable, optional
|
|
62
|
-
A function that will be called after each
|
|
63
|
-
The
|
|
64
|
-
|
|
62
|
+
A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling.
|
|
63
|
+
The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: `callback(sampler, sample_index, num_of_samples)`.
|
|
65
64
|
"""
|
|
66
65
|
|
|
67
66
|
self.target = target
|
|
@@ -209,7 +208,6 @@ class Sampler(ABC):
|
|
|
209
208
|
The path to save the samples. If not specified, the samples are saved to the current working directory under a folder called 'CUQI_samples'.
|
|
210
209
|
|
|
211
210
|
"""
|
|
212
|
-
|
|
213
211
|
self._ensure_initialized()
|
|
214
212
|
|
|
215
213
|
# Initialize batch handler
|
|
@@ -235,7 +233,7 @@ class Sampler(ABC):
|
|
|
235
233
|
batch_handler.add_sample(self.current_point)
|
|
236
234
|
|
|
237
235
|
# Call callback function if specified
|
|
238
|
-
self._call_callback(
|
|
236
|
+
self._call_callback(idx, Ns)
|
|
239
237
|
|
|
240
238
|
return self
|
|
241
239
|
|
|
@@ -276,7 +274,7 @@ class Sampler(ABC):
|
|
|
276
274
|
pbar.set_postfix_str(f"acc rate: {np.mean(self._acc[-1-idx:]):.2%}")
|
|
277
275
|
|
|
278
276
|
# Call callback function if specified
|
|
279
|
-
self._call_callback(
|
|
277
|
+
self._call_callback(idx, Nb)
|
|
280
278
|
|
|
281
279
|
return self
|
|
282
280
|
|
|
@@ -367,10 +365,10 @@ class Sampler(ABC):
|
|
|
367
365
|
raise ValueError(f"Key {key} not recognized in history dictionary of sampler {self.__class__.__name__}.")
|
|
368
366
|
|
|
369
367
|
# ------------ Private methods ------------
|
|
370
|
-
def _call_callback(self,
|
|
371
|
-
""" Calls the callback function. Assumes input is sample and
|
|
368
|
+
def _call_callback(self, sample_index, num_of_samples):
|
|
369
|
+
""" Calls the callback function. Assumes input is sampler, sample index, and total number of samples """
|
|
372
370
|
if self.callback is not None:
|
|
373
|
-
self.callback(
|
|
371
|
+
self.callback(self, sample_index, num_of_samples)
|
|
374
372
|
|
|
375
373
|
def _validate_initialization(self):
|
|
376
374
|
""" Validate the initialization of the sampler by checking all state and history keys are set. """
|
|
@@ -304,6 +304,7 @@ class BayesianProblem(object):
|
|
|
304
304
|
The signature of the callback function is `callback(sample, sample_index)`,
|
|
305
305
|
where `sample` is the current sample and `sample_index` is the index of the sample.
|
|
306
306
|
An example is shown in demos/demo31_callback.py.
|
|
307
|
+
Note: if the parameter `experimental` is set to True, the callback function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature in the case is: `callback(sampler, sample_index, num_of_samples)`.
|
|
307
308
|
|
|
308
309
|
experimental : bool, *Optional*
|
|
309
310
|
If set to True, the sampler selection will use the samplers from the :mod:`cuqi.experimental.mcmc` module.
|
|
@@ -848,16 +849,14 @@ class BayesianProblem(object):
|
|
|
848
849
|
print(f"burn-in: {Nb/Ns*100:g}%")
|
|
849
850
|
print("")
|
|
850
851
|
|
|
851
|
-
if callback is not None:
|
|
852
|
-
raise NotImplementedError("Callback not implemented for Gibbs sampler")
|
|
853
|
-
|
|
854
852
|
# Start timing
|
|
855
853
|
ti = time.time()
|
|
856
854
|
|
|
857
855
|
# Sampling strategy
|
|
858
856
|
sampling_strategy = self._determine_sampling_strategy(experimental=True)
|
|
859
857
|
|
|
860
|
-
sampler = cuqi.experimental.mcmc.HybridGibbs(
|
|
858
|
+
sampler = cuqi.experimental.mcmc.HybridGibbs(
|
|
859
|
+
self._target, sampling_strategy, callback=callback)
|
|
861
860
|
sampler.warmup(Nb)
|
|
862
861
|
sampler.sample(Ns)
|
|
863
862
|
samples = sampler.get_samples()
|
|
@@ -876,7 +875,7 @@ class BayesianProblem(object):
|
|
|
876
875
|
print("")
|
|
877
876
|
|
|
878
877
|
if callback is not None:
|
|
879
|
-
raise NotImplementedError("Callback not implemented for Gibbs sampler")
|
|
878
|
+
raise NotImplementedError("Callback not implemented for Gibbs sampler. It is only implemented for experimental Gibbs sampler.")
|
|
880
879
|
|
|
881
880
|
# Start timing
|
|
882
881
|
ti = time.time()
|
|
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.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_joint_distribution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/distribution/_modifiedhalfnormal.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.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/algebra/_orderedset.py
RENAMED
|
File without changes
|
{cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/algebra/_randomvariable.py
RENAMED
|
File without changes
|
|
File without changes
|
{cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/geometry/_productgeometry.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/cuqi/experimental/mcmc/_conjugate_approx.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.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/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
|
|
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.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/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.3.0.post0.dev5 → cuqipy-1.3.0.post0.dev16}/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
|