CUQIpy 1.1.0.post0.dev47__tar.gz → 1.1.1.post0.dev7__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.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/CUQIpy.egg-info/PKG-INFO +1 -1
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/PKG-INFO +1 -1
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/_version.py +3 -3
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_joint_distribution.py +21 -5
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_gibbs.py +5 -5
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_sampler.py +5 -5
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_joint_distribution.py +83 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/CUQIpy.egg-info/SOURCES.txt +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/CUQIpy.egg-info/dependency_links.txt +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/CUQIpy.egg-info/requires.txt +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/CUQIpy.egg-info/top_level.txt +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/LICENSE +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/README.md +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/_messages.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/array/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/array/_array.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/config.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/_data.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/astronaut.npz +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/camera.npz +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/cat.npz +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/cookie.png +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/data/satellite.mat +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/density/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/density/_density.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/diagnostics.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_beta.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_cauchy.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_cmrf.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_custom.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_distribution.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_gamma.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_gaussian.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_gmrf.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_inverse_gamma.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_laplace.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_lmrf.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_lognormal.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_modifiedhalfnormal.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_normal.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_posterior.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_smoothed_laplace.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_uniform.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_conjugate.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_conjugate_approx.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_cwmh.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_direct.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_hmc.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_langevin_algorithm.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_laplace_approximation.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_mh.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_pcn.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_rto.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_utilities.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/geometry/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/geometry/_geometry.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/implicitprior/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/implicitprior/_regularizedGMRF.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/implicitprior/_regularizedGaussian.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/implicitprior/_regularizedUnboundedUniform.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/likelihood/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/likelihood/_likelihood.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/model/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/model/_model.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/operator/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/operator/_operator.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/pde/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/pde/_pde.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/problem/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/problem/_problem.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_conjugate.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_conjugate_approx.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_cwmh.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_gibbs.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_hmc.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_langevin_algorithm.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_laplace_approximation.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_mh.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_pcn.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_rto.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/sampler/_sampler.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/samples/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/samples/_samples.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/solver/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/solver/_solver.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/testproblem/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/testproblem/_testproblem.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/utilities/__init__.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/utilities/_get_python_variable_name.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/utilities/_utilities.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/pyproject.toml +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/requirements.txt +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/setup.cfg +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/setup.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_MRFs.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_abstract_distribution_density.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_bayesian_inversion.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_density.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_distribution.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_distributions_shape.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_geometry.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_implicit_priors.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_likelihood.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_model.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_pde.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_posterior.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_problem.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_sampler.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_samples.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_solver.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_testproblem.py +0 -0
- {cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.1.post0.dev7
|
|
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.
|
|
3
|
+
Version: 1.1.1.post0.dev7
|
|
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-09-03T13:01:53+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.1.
|
|
14
|
+
"full-revisionid": "6731d720ebd90ec077628febef51db45ce1738a4",
|
|
15
|
+
"version": "1.1.1.post0.dev7"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
{cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/distribution/_joint_distribution.py
RENAMED
|
@@ -175,6 +175,10 @@ class JointDistribution:
|
|
|
175
175
|
kwargs[ordered_keys[index]] = arg
|
|
176
176
|
return kwargs
|
|
177
177
|
|
|
178
|
+
def _sum_evaluated_densities(self):
|
|
179
|
+
""" Return the sum of the evaluated densities in the joint distribution """
|
|
180
|
+
return sum([density.logd() for density in self._evaluated_densities])
|
|
181
|
+
|
|
178
182
|
def _reduce_to_single_density(self):
|
|
179
183
|
""" Reduce the joint distribution to a single density if possible.
|
|
180
184
|
|
|
@@ -183,7 +187,6 @@ class JointDistribution:
|
|
|
183
187
|
This method is a hack to allow our current samplers to work with
|
|
184
188
|
the joint distribution. It should be removed in the future.
|
|
185
189
|
"""
|
|
186
|
-
|
|
187
190
|
# Count number of distributions and likelihoods
|
|
188
191
|
n_dist = len(self._distributions)
|
|
189
192
|
n_likelihood = len(self._likelihoods)
|
|
@@ -201,16 +204,29 @@ class JointDistribution:
|
|
|
201
204
|
# Ensure parameter names match, otherwise return the joint distribution
|
|
202
205
|
if set(self._likelihoods[0].get_parameter_names()) != set(self._distributions[0].get_parameter_names()):
|
|
203
206
|
return self
|
|
204
|
-
return Posterior(self._likelihoods[0], self._distributions[0])
|
|
205
|
-
|
|
207
|
+
return self._add_constants_to_density(Posterior(self._likelihoods[0], self._distributions[0]))
|
|
208
|
+
|
|
206
209
|
# If exactly one distribution and no likelihoods its a Distribution
|
|
207
210
|
if n_dist == 1 and n_likelihood == 0:
|
|
208
|
-
return self._distributions[0]
|
|
209
|
-
|
|
211
|
+
return self._add_constants_to_density(self._distributions[0])
|
|
212
|
+
|
|
210
213
|
# If no distributions and exactly one likelihood its a Likelihood
|
|
211
214
|
if n_likelihood == 1 and n_dist == 0:
|
|
212
215
|
return self._likelihoods[0]
|
|
213
216
|
|
|
217
|
+
# If only evaluated densities left return joint to ensure logd method is available
|
|
218
|
+
if n_dist == 0 and n_likelihood == 0:
|
|
219
|
+
return self
|
|
220
|
+
|
|
221
|
+
def _add_constants_to_density(self, density: Density):
|
|
222
|
+
""" Add the constants (evaluated densities) to a single density. Used when reducing to single density. """
|
|
223
|
+
|
|
224
|
+
if isinstance(density, EvaluatedDensity):
|
|
225
|
+
raise ValueError("Cannot add the sum of all evaluated densities to an EvaluatedDensity.")
|
|
226
|
+
|
|
227
|
+
density._constant += self._sum_evaluated_densities()
|
|
228
|
+
return density
|
|
229
|
+
|
|
214
230
|
def _as_stacked(self) -> _StackedJointDistribution:
|
|
215
231
|
""" Return a stacked JointDistribution with the same densities. """
|
|
216
232
|
return _StackedJointDistribution(*self._densities)
|
|
@@ -6,10 +6,10 @@ import numpy as np
|
|
|
6
6
|
import warnings
|
|
7
7
|
|
|
8
8
|
try:
|
|
9
|
-
from
|
|
9
|
+
from tqdm import tqdm
|
|
10
10
|
except ImportError:
|
|
11
|
-
def
|
|
12
|
-
warnings.warn("Module mcmc:
|
|
11
|
+
def tqdm(iterable, **kwargs):
|
|
12
|
+
warnings.warn("Module mcmc: tqdm not found. Install tqdm to get sampling progress.")
|
|
13
13
|
return iterable
|
|
14
14
|
|
|
15
15
|
# Not subclassed from Sampler as Gibbs handles multiple samplers and samples multiple parameters
|
|
@@ -152,13 +152,13 @@ class HybridGibbs:
|
|
|
152
152
|
|
|
153
153
|
def sample(self, Ns) -> 'HybridGibbs':
|
|
154
154
|
""" Sample from the joint distribution using Gibbs sampling """
|
|
155
|
-
for _ in
|
|
155
|
+
for _ in tqdm(range(Ns)):
|
|
156
156
|
self.step()
|
|
157
157
|
self._store_samples()
|
|
158
158
|
|
|
159
159
|
def warmup(self, Nb) -> 'HybridGibbs':
|
|
160
160
|
""" Warmup (tune) the Gibbs sampler """
|
|
161
|
-
for idx in
|
|
161
|
+
for idx in tqdm(range(Nb)):
|
|
162
162
|
self.step()
|
|
163
163
|
self.tune(idx)
|
|
164
164
|
self._store_samples()
|
|
@@ -7,10 +7,10 @@ import cuqi
|
|
|
7
7
|
from cuqi.samples import Samples
|
|
8
8
|
|
|
9
9
|
try:
|
|
10
|
-
from
|
|
10
|
+
from tqdm import tqdm
|
|
11
11
|
except ImportError:
|
|
12
|
-
def
|
|
13
|
-
warnings.warn("Module mcmc:
|
|
12
|
+
def tqdm(iterable, **kwargs):
|
|
13
|
+
warnings.warn("Module mcmc: tqdm not found. Install tqdm to get sampling progress.")
|
|
14
14
|
return iterable
|
|
15
15
|
|
|
16
16
|
class Sampler(ABC):
|
|
@@ -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
|
|
223
|
+
for _ in tqdm( range(Ns) ):
|
|
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
|
|
263
|
+
for idx in tqdm(range(Nb)):
|
|
264
264
|
|
|
265
265
|
# Perform one step of the sampler
|
|
266
266
|
acc = self.step()
|
|
@@ -310,3 +310,86 @@ def test_MultipleLikelihoodPosterior_should_raise_if_names_do_not_match():
|
|
|
310
310
|
with pytest.raises(ValueError, match=r"the same parameter name"):
|
|
311
311
|
cuqi.distribution.MultipleLikelihoodPosterior(y.to_likelihood(1), x, z)
|
|
312
312
|
|
|
313
|
+
@pytest.mark.parametrize("joint, variables", [
|
|
314
|
+
(
|
|
315
|
+
cuqi.distribution.JointDistribution(
|
|
316
|
+
cuqi.distribution.Normal(0, 1, name="x"),
|
|
317
|
+
cuqi.distribution.Normal(0, 1, name="y")
|
|
318
|
+
),
|
|
319
|
+
{
|
|
320
|
+
"x": 0,
|
|
321
|
+
"y": 0
|
|
322
|
+
}
|
|
323
|
+
),
|
|
324
|
+
(
|
|
325
|
+
cuqi.distribution.JointDistribution(
|
|
326
|
+
cuqi.distribution.Uniform(0, 10, name="d"),
|
|
327
|
+
cuqi.distribution.Uniform(0, 5, name="s"),
|
|
328
|
+
cuqi.distribution.Gaussian(np.zeros(8), lambda d: d, name="x"),
|
|
329
|
+
cuqi.distribution.Gaussian(
|
|
330
|
+
mean=cuqi.testproblem.Deconvolution1D(dim=8).model,
|
|
331
|
+
cov=lambda s: s,
|
|
332
|
+
name="y"
|
|
333
|
+
)
|
|
334
|
+
),
|
|
335
|
+
{
|
|
336
|
+
"d": 5,
|
|
337
|
+
"s": 2,
|
|
338
|
+
"x": np.zeros(8),
|
|
339
|
+
"y": cuqi.testproblem.Deconvolution1D(dim=8).data
|
|
340
|
+
}
|
|
341
|
+
),
|
|
342
|
+
(
|
|
343
|
+
cuqi.distribution.JointDistribution(
|
|
344
|
+
cuqi.distribution.Uniform(0, 10, name="d"),
|
|
345
|
+
cuqi.distribution.Uniform(0, 5, name="s"),
|
|
346
|
+
cuqi.distribution.Gaussian(np.zeros(8), lambda d: d, name="x"),
|
|
347
|
+
cuqi.distribution.Gaussian(
|
|
348
|
+
mean=cuqi.testproblem.Deconvolution1D(dim=8).model,
|
|
349
|
+
cov=lambda s: s,
|
|
350
|
+
name="y"
|
|
351
|
+
)
|
|
352
|
+
),
|
|
353
|
+
{
|
|
354
|
+
"d": 11, # Out of bounds (all should return -Inf)
|
|
355
|
+
"s": 2,
|
|
356
|
+
"x": np.zeros(8),
|
|
357
|
+
"y": cuqi.testproblem.Deconvolution1D(dim=8).data
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
]
|
|
361
|
+
)
|
|
362
|
+
def test_logd_consistency_when_conditioning(joint, variables):
|
|
363
|
+
""" Test consistency of logd value when conditioning the joint distribution.
|
|
364
|
+
|
|
365
|
+
This ensures we always return the correct value for logd even when reducing to single density.
|
|
366
|
+
|
|
367
|
+
"""
|
|
368
|
+
|
|
369
|
+
# True value of logd by fully evaluating the joint distribution
|
|
370
|
+
true_value = joint.logd(**variables)
|
|
371
|
+
|
|
372
|
+
# Loop over all variables and evaluate the logd value
|
|
373
|
+
# where all previously seen variables are conditioned
|
|
374
|
+
# and not seen variables are given to logd.
|
|
375
|
+
cond_vars = {}
|
|
376
|
+
for key, value in variables.items():
|
|
377
|
+
# Remaining variables are those that are not used for conditioning
|
|
378
|
+
remaining_vars = {k: v for k, v in variables.items() if k not in cond_vars}
|
|
379
|
+
|
|
380
|
+
# Condition the joint distribution
|
|
381
|
+
cond_joint = joint(**cond_vars)
|
|
382
|
+
|
|
383
|
+
# Evaluate the logd value of conditioned joint distribution
|
|
384
|
+
# This may be a single density or a joint distribution since
|
|
385
|
+
# joint can reduce to single density (such as Posterior)
|
|
386
|
+
logd_value = cond_joint.logd(**remaining_vars)
|
|
387
|
+
|
|
388
|
+
# Potential error message if this assert fails:
|
|
389
|
+
msg = f"Evaluated: \n {joint} \n with variables {variables}.\nFailed at {key}={value} for \n {cond_joint} \n with variables {remaining_vars}."
|
|
390
|
+
|
|
391
|
+
# Assert the logd value matches
|
|
392
|
+
assert logd_value == pytest.approx(true_value, rel=1e-6), msg
|
|
393
|
+
|
|
394
|
+
# Add current variable to the variables that need to be conditioned
|
|
395
|
+
cond_vars[key] = value
|
|
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.post0.dev47 → cuqipy-1.1.1.post0.dev7}/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
|
{cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/cuqi/experimental/mcmc/_conjugate_approx.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/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
|
|
File without changes
|
{cuqipy-1.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/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.1.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/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.0.post0.dev47 → cuqipy-1.1.1.post0.dev7}/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
|