CUQIpy 1.0.0.post0.dev352__tar.gz → 1.0.0.post0.dev371__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.

Files changed (120) hide show
  1. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/CUQIpy.egg-info/PKG-INFO +1 -1
  2. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/CUQIpy.egg-info/SOURCES.txt +2 -0
  3. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/PKG-INFO +1 -1
  4. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/_version.py +3 -3
  5. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/__init__.py +1 -0
  6. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_cwmh.py +3 -0
  7. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_mh.py +3 -1
  8. cuqipy-1.0.0.post0.dev371/cuqi/experimental/mcmc/_utilities.py +17 -0
  9. cuqipy-1.0.0.post0.dev371/cuqi/implicitprior/__init__.py +3 -0
  10. cuqipy-1.0.0.post0.dev371/cuqi/implicitprior/_regularizedGMRF.py +152 -0
  11. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/implicitprior/_regularizedGaussian.py +87 -0
  12. cuqipy-1.0.0.post0.dev371/cuqi/implicitprior/_regularizedUnboundedUniform.py +66 -0
  13. cuqipy-1.0.0.post0.dev371/tests/test_implicit_priors.py +70 -0
  14. cuqipy-1.0.0.post0.dev352/cuqi/implicitprior/__init__.py +0 -2
  15. cuqipy-1.0.0.post0.dev352/cuqi/implicitprior/_regularizedGMRF.py +0 -70
  16. cuqipy-1.0.0.post0.dev352/tests/test_implicit_priors.py +0 -30
  17. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/CUQIpy.egg-info/dependency_links.txt +0 -0
  18. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/CUQIpy.egg-info/requires.txt +0 -0
  19. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/CUQIpy.egg-info/top_level.txt +0 -0
  20. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/LICENSE +0 -0
  21. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/README.md +0 -0
  22. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/__init__.py +0 -0
  23. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/_messages.py +0 -0
  24. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/array/__init__.py +0 -0
  25. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/array/_array.py +0 -0
  26. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/config.py +0 -0
  27. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/__init__.py +0 -0
  28. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/_data.py +0 -0
  29. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/astronaut.npz +0 -0
  30. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/camera.npz +0 -0
  31. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/cat.npz +0 -0
  32. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/cookie.png +0 -0
  33. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/data/satellite.mat +0 -0
  34. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/density/__init__.py +0 -0
  35. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/density/_density.py +0 -0
  36. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/diagnostics.py +0 -0
  37. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/__init__.py +0 -0
  38. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_beta.py +0 -0
  39. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_cauchy.py +0 -0
  40. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_cmrf.py +0 -0
  41. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_custom.py +0 -0
  42. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_distribution.py +0 -0
  43. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_gamma.py +0 -0
  44. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_gaussian.py +0 -0
  45. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_gmrf.py +0 -0
  46. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_inverse_gamma.py +0 -0
  47. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_joint_distribution.py +0 -0
  48. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_laplace.py +0 -0
  49. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_lmrf.py +0 -0
  50. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_lognormal.py +0 -0
  51. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_modifiedhalfnormal.py +0 -0
  52. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_normal.py +0 -0
  53. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_posterior.py +0 -0
  54. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/distribution/_uniform.py +0 -0
  55. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/__init__.py +0 -0
  56. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_conjugate.py +0 -0
  57. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_conjugate_approx.py +0 -0
  58. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_direct.py +0 -0
  59. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_gibbs.py +0 -0
  60. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_hmc.py +0 -0
  61. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_langevin_algorithm.py +0 -0
  62. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_laplace_approximation.py +0 -0
  63. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_pcn.py +0 -0
  64. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_rto.py +0 -0
  65. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/experimental/mcmc/_sampler.py +0 -0
  66. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/geometry/__init__.py +0 -0
  67. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/geometry/_geometry.py +0 -0
  68. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/likelihood/__init__.py +0 -0
  69. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/likelihood/_likelihood.py +0 -0
  70. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/model/__init__.py +0 -0
  71. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/model/_model.py +0 -0
  72. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/operator/__init__.py +0 -0
  73. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/operator/_operator.py +0 -0
  74. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/pde/__init__.py +0 -0
  75. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/pde/_pde.py +0 -0
  76. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/problem/__init__.py +0 -0
  77. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/problem/_problem.py +0 -0
  78. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/__init__.py +0 -0
  79. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_conjugate.py +0 -0
  80. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_conjugate_approx.py +0 -0
  81. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_cwmh.py +0 -0
  82. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_gibbs.py +0 -0
  83. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_hmc.py +0 -0
  84. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_langevin_algorithm.py +0 -0
  85. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_laplace_approximation.py +0 -0
  86. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_mh.py +0 -0
  87. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_pcn.py +0 -0
  88. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_rto.py +0 -0
  89. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/sampler/_sampler.py +0 -0
  90. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/samples/__init__.py +0 -0
  91. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/samples/_samples.py +0 -0
  92. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/solver/__init__.py +0 -0
  93. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/solver/_solver.py +0 -0
  94. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/testproblem/__init__.py +0 -0
  95. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/testproblem/_testproblem.py +0 -0
  96. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/utilities/__init__.py +0 -0
  97. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/utilities/_get_python_variable_name.py +0 -0
  98. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/cuqi/utilities/_utilities.py +0 -0
  99. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/pyproject.toml +0 -0
  100. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/requirements.txt +0 -0
  101. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/setup.cfg +0 -0
  102. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/setup.py +0 -0
  103. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_MRFs.py +0 -0
  104. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_abstract_distribution_density.py +0 -0
  105. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_bayesian_inversion.py +0 -0
  106. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_density.py +0 -0
  107. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_distribution.py +0 -0
  108. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_distributions_shape.py +0 -0
  109. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_geometry.py +0 -0
  110. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_joint_distribution.py +0 -0
  111. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_likelihood.py +0 -0
  112. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_model.py +0 -0
  113. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_pde.py +0 -0
  114. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_posterior.py +0 -0
  115. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_problem.py +0 -0
  116. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_sampler.py +0 -0
  117. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_samples.py +0 -0
  118. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_solver.py +0 -0
  119. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_testproblem.py +0 -0
  120. {cuqipy-1.0.0.post0.dev352 → cuqipy-1.0.0.post0.dev371}/tests/test_utilities.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CUQIpy
3
- Version: 1.0.0.post0.dev352
3
+ Version: 1.0.0.post0.dev371
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
@@ -56,11 +56,13 @@ cuqi/experimental/mcmc/_mh.py
56
56
  cuqi/experimental/mcmc/_pcn.py
57
57
  cuqi/experimental/mcmc/_rto.py
58
58
  cuqi/experimental/mcmc/_sampler.py
59
+ cuqi/experimental/mcmc/_utilities.py
59
60
  cuqi/geometry/__init__.py
60
61
  cuqi/geometry/_geometry.py
61
62
  cuqi/implicitprior/__init__.py
62
63
  cuqi/implicitprior/_regularizedGMRF.py
63
64
  cuqi/implicitprior/_regularizedGaussian.py
65
+ cuqi/implicitprior/_regularizedUnboundedUniform.py
64
66
  cuqi/likelihood/__init__.py
65
67
  cuqi/likelihood/_likelihood.py
66
68
  cuqi/model/__init__.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CUQIpy
3
- Version: 1.0.0.post0.dev352
3
+ Version: 1.0.0.post0.dev371
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-06-19T09:05:37+0200",
11
+ "date": "2024-07-05T10:04:17+0300",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "1e1deddbe7925206fdaef6a2d9bf8ce9e33ad73d",
15
- "version": "1.0.0.post0.dev352"
14
+ "full-revisionid": "62f642d707e561a7c9deb0006625b11866043b81",
15
+ "version": "1.0.0.post0.dev371"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -12,3 +12,4 @@ from ._gibbs import HybridGibbsNew
12
12
  from ._conjugate import ConjugateNew
13
13
  from ._conjugate_approx import ConjugateApproxNew
14
14
  from ._direct import DirectNew
15
+ from ._utilities import find_valid_samplers
@@ -100,6 +100,9 @@ class CWMHNew(ProposalBasedSamplerNew):
100
100
  raise ValueError(
101
101
  "Target should be an instance of "+\
102
102
  f"{cuqi.density.Density.__class__.__name__}")
103
+ # Fail when there is no log density, which is currently assumed to be the case in case NaN is returned.
104
+ if np.isnan(self.target.logd(self._default_initial_point)):
105
+ raise ValueError("Target does not have valid logd")
103
106
 
104
107
  def validate_proposal(self):
105
108
  if not isinstance(self.proposal, cuqi.distribution.Distribution):
@@ -32,7 +32,9 @@ class MHNew(ProposalBasedSamplerNew):
32
32
  self._scale_temp = self.scale
33
33
 
34
34
  def validate_target(self):
35
- pass # All targets are valid
35
+ # Fail only when there is no log density, which is currently assumed to be the case in case NaN is returned.
36
+ if np.isnan(self.target.logd(self._default_initial_point)):
37
+ raise ValueError("Target does not have valid logd")
36
38
 
37
39
  def validate_proposal(self):
38
40
  if not isinstance(self.proposal, cuqi.distribution.Distribution):
@@ -0,0 +1,17 @@
1
+ import cuqi
2
+ import inspect
3
+
4
+ def find_valid_samplers(target):
5
+ """ Finds all samplers in the cuqi.experimental.mcmc module that accept the provided target. """
6
+
7
+ all_samplers = [(name, cls) for name, cls in inspect.getmembers(cuqi.experimental.mcmc, inspect.isclass) if issubclass(cls, cuqi.experimental.mcmc.SamplerNew)]
8
+ valid_samplers = []
9
+
10
+ for name, sampler in all_samplers:
11
+ try:
12
+ sampler(target)
13
+ valid_samplers += [name]
14
+ except:
15
+ pass
16
+
17
+ return valid_samplers
@@ -0,0 +1,3 @@
1
+ from ._regularizedGaussian import RegularizedGaussian, ConstrainedGaussian, NonnegativeGaussian
2
+ from ._regularizedGMRF import RegularizedGMRF, ConstrainedGMRF, NonnegativeGMRF
3
+ from ._regularizedUnboundedUniform import RegularizedUnboundedUniform
@@ -0,0 +1,152 @@
1
+ from cuqi.implicitprior import RegularizedGaussian
2
+ from cuqi.distribution import Distribution, GMRF
3
+
4
+ class RegularizedGMRF(RegularizedGaussian):
5
+ """ Implicit Regularized GMRF (Gaussian Markov Random Field).
6
+
7
+ Defines a so-called implicit prior based on a GMRF distribution with implicit regularization.
8
+ The regularization can be defined in the form of a proximal operator or a projector.
9
+ Alternatively, preset constraints and regularization can be used.
10
+
11
+ Only one of proximal, projector, constraint or regularization can be provided. Otherwise, an error is raised.
12
+
13
+ Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
14
+
15
+
16
+ For more details on implicit regularized Gaussian see the following paper:
17
+
18
+ [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
19
+ Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
20
+
21
+ Parameters
22
+ ----------
23
+ mean
24
+ See :class:`~cuqi.distribution.GMRF` for details.
25
+
26
+ prec
27
+ See :class:`~cuqi.distribution.GMRF` for details.
28
+
29
+ bc_type
30
+ See :class:`~cuqi.distribution.GMRF` for details.
31
+
32
+ order
33
+ See :class:`~cuqi.distribution.GMRF` for details.
34
+
35
+ proximal : callable f(x, scale) or None
36
+ Euclidean proximal operator f of the regularization function g, that is, a solver for the optimization problem
37
+ min_z 0.5||x-z||_2^2+scale*g(x).
38
+
39
+ projector : callable f(x) or None
40
+ Euclidean projection onto the constraint C, that is, a solver for the optimization problem
41
+ min_(z in C) 0.5||x-z||_2^2.
42
+
43
+ constraint : string or None
44
+ Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
45
+ For "box", the following additional parameters can be passed:
46
+ lower_bound : array_like or None
47
+ Lower bound of box, defaults to zero
48
+ upper_bound : array_like
49
+ Upper bound of box, defaults to one
50
+
51
+ regularization : string or None
52
+ Preset regularization. Can be set to "l1". Required for use in Gibbs in future update.
53
+ For "l1", the following additional parameters can be passed:
54
+ strength : scalar
55
+ Regularization parameter, i.e., strength*||x||_1 , defaults to one
56
+
57
+ """
58
+ def __init__(self, mean=None, prec=None, bc_type='zero', order=1, proximal = None, projector = None, constraint = None, regularization = None, **kwargs):
59
+
60
+ args = {"lower_bound" : kwargs.pop("lower_bound", None),
61
+ "upper_bound" : kwargs.pop("upper_bound", None),
62
+ "strength" : kwargs.pop("strength", None)}
63
+
64
+ # Underlying explicit GMRF
65
+ self._gaussian = GMRF(mean, prec, bc_type=bc_type, order=order, **kwargs)
66
+
67
+ # Init from abstract distribution class
68
+ super(Distribution, self).__init__(**kwargs)
69
+
70
+ self._parse_regularization_input_arguments(proximal, projector, constraint, regularization, args)
71
+
72
+
73
+
74
+ class ConstrainedGMRF(RegularizedGMRF):
75
+ """ Implicit Constrained GMRF (Gaussian Markov Random Field).
76
+
77
+ Defines a so-called implicit prior based on a GMRF distribution with implicit constraints.
78
+ The constraint can be defined as a preset or in the form of a projector.
79
+
80
+ Precisely one of projector or constraint needs to be provided. Otherwise, an error is raised.
81
+
82
+ Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
83
+
84
+ Alias for :class:`~cuqi.implicitprior.RegularizedGMRF` with only constraints available.
85
+
86
+ For more details on implicit regularized Gaussian see the following paper:
87
+
88
+ [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
89
+ Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
90
+
91
+ Parameters
92
+ ----------
93
+ mean
94
+ See :class:`~cuqi.distribution.GMRF` for details.
95
+
96
+ prec
97
+ See :class:`~cuqi.distribution.GMRF` for details.
98
+
99
+ bc_type
100
+ See :class:`~cuqi.distribution.GMRF` for details.
101
+
102
+ order
103
+ See :class:`~cuqi.distribution.GMRF` for details.
104
+
105
+ projector : callable f(x) or None
106
+ Euclidean projection onto the constraint C, that is, a solver for the optimization problem
107
+ min_(z in C) 0.5||x-z||_2^2.
108
+
109
+ constraint : string or None
110
+ Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
111
+ For "box", the following additional parameters can be passed:
112
+ lower_bound : array_like or None
113
+ Lower bound of box, defaults to zero
114
+ upper_bound : array_like
115
+ Upper bound of box, defaults to one
116
+
117
+ """
118
+ def __init__(self, mean=None, prec=None, bc_type='zero', order=1, projector=None, constraint=None, **kwargs):
119
+ super().__init__(mean=mean, prec=prec, bc_type=bc_type, order=order, projector=projector, constraint=constraint, **kwargs)
120
+
121
+
122
+ class NonnegativeGMRF(RegularizedGMRF):
123
+ """ Implicit Nonnegative GMRF (Gaussian Markov Random Field).
124
+
125
+ Defines a so-called implicit prior based on a GMRF distribution with implicit nonnegativity constraints.
126
+
127
+ Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
128
+
129
+ Alias for :class:`~cuqi.implicitprior.RegularizedGMRF` with only nonnegativity constraints.
130
+
131
+ For more details on implicit regularized Gaussian see the following paper:
132
+
133
+ [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
134
+ Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
135
+
136
+ Parameters
137
+ ----------
138
+ mean
139
+ See :class:`~cuqi.distribution.GMRF` for details.
140
+
141
+ prec
142
+ See :class:`~cuqi.distribution.GMRF` for details.
143
+
144
+ bc_type
145
+ See :class:`~cuqi.distribution.GMRF` for details.
146
+
147
+ order
148
+ See :class:`~cuqi.distribution.GMRF` for details.
149
+
150
+ """
151
+ def __init__(self, mean=None, prec=None, bc_type='zero', order=1, **kwargs):
152
+ super().__init__(mean=mean, prec=prec, bc_type=bc_type, order=order, constraint="nonnegativity", **kwargs)
@@ -234,3 +234,90 @@ class RegularizedGaussian(Distribution):
234
234
  new_density = new_density.to_likelihood(value)
235
235
 
236
236
  return new_density
237
+
238
+
239
+ class ConstrainedGaussian(RegularizedGaussian):
240
+ """ Implicit Constrained Gaussian.
241
+
242
+ Defines a so-called implicit prior based on a Gaussian distribution with implicit constraints.
243
+ The constraint can be defined as a preset or in the form of a projector.
244
+
245
+ Precisely one of projector or constraint needs to be provided. Otherwise, an error is raised.
246
+
247
+ Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
248
+
249
+ Alias for :class:`~cuqi.implicitprior.RegularizedGaussian` with only constraints available.
250
+
251
+ For more details on implicit regularized Gaussian see the following paper:
252
+
253
+ [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
254
+ Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
255
+
256
+ Parameters
257
+ ----------
258
+ mean
259
+ See :class:`~cuqi.distribution.Gaussian` for details.
260
+
261
+ cov
262
+ See :class:`~cuqi.distribution.Gaussian` for details.
263
+
264
+ prec
265
+ See :class:`~cuqi.distribution.Gaussian` for details.
266
+
267
+ sqrtcov
268
+ See :class:`~cuqi.distribution.Gaussian` for details.
269
+
270
+ sqrtprec
271
+ See :class:`~cuqi.distribution.Gaussian` for details.
272
+
273
+ projector : callable f(x) or None
274
+ Euclidean projection onto the constraint C, that is, a solver for the optimization problem
275
+ min_(z in C) 0.5||x-z||_2^2.
276
+
277
+ constraint : string or None
278
+ Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
279
+ For "box", the following additional parameters can be passed:
280
+ lower_bound : array_like or None
281
+ Lower bound of box, defaults to zero
282
+ upper_bound : array_like
283
+ Upper bound of box, defaults to one
284
+
285
+ """
286
+ def __init__(self, mean=None, cov=None, prec=None, sqrtcov=None,sqrtprec=None, projector=None, constraint=None, **kwargs):
287
+ super().__init__(mean=mean, cov=cov, prec=prec, sqrtcov=sqrtcov, sqrtprec=sqrtprec, projector=projector, constraint=constraint, **kwargs)
288
+
289
+
290
+ class NonnegativeGaussian(RegularizedGaussian):
291
+ """ Implicit Nonnegative Gaussian.
292
+
293
+ Defines a so-called implicit prior based on a Gaussian distribution with implicit nonnegativity constraints.
294
+
295
+ Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
296
+
297
+ Alias for :class:`~cuqi.implicitprior.RegularizedGaussian` with only nonnegativity constraints.
298
+
299
+ For more details on implicit regularized Gaussian see the following paper:
300
+
301
+ [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
302
+ Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
303
+
304
+ Parameters
305
+ ----------
306
+ mean
307
+ See :class:`~cuqi.distribution.Gaussian` for details.
308
+
309
+ cov
310
+ See :class:`~cuqi.distribution.Gaussian` for details.
311
+
312
+ prec
313
+ See :class:`~cuqi.distribution.Gaussian` for details.
314
+
315
+ sqrtcov
316
+ See :class:`~cuqi.distribution.Gaussian` for details.
317
+
318
+ sqrtprec
319
+ See :class:`~cuqi.distribution.Gaussian` for details.
320
+
321
+ """
322
+ def __init__(self, mean=None, cov=None, prec=None, sqrtcov=None,sqrtprec=None, **kwargs):
323
+ super().__init__(mean=mean, cov=cov, prec=prec, sqrtcov=sqrtcov, sqrtprec=sqrtprec, constraint="nonnegativity", **kwargs)
@@ -0,0 +1,66 @@
1
+ from cuqi.implicitprior import RegularizedGaussian
2
+ from cuqi.distribution import Distribution, Gaussian
3
+
4
+ import numpy as np
5
+
6
+
7
+ class RegularizedUnboundedUniform(RegularizedGaussian):
8
+ """ Implicit Regularized Unbounded Uniform.
9
+
10
+ Defines a so-called implicit prior with implicit regularization on a Gaussian distribution with zero precision.
11
+ The regularization can be defined in the form of a proximal operator or a projector.
12
+ Alternatively, preset constraints and regularization can be used.
13
+
14
+ For regularization of the form f(x), provide a single proximal operator.
15
+
16
+ Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
17
+
18
+ Alias for :class:`~cuqi.implicitprior.RegularizedGaussian` with zero mean and zero sqrtprec.
19
+
20
+ For more details on implicit regularized Gaussian see the following paper:
21
+
22
+ [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
23
+ Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
24
+
25
+ Parameters
26
+ ----------
27
+ geometry : :class:`~cuqi.geometry.Geometry` or integer
28
+ The geometry of the underlying variable. Defines the dimension of the distribution.
29
+
30
+ proximal : callable f(x, scale) or None
31
+ Euclidean proximal operator f of the regularization function g, that is, a solver for the optimization problem
32
+ min_z 0.5||x-z||_2^2+scale*g(x).
33
+
34
+ projector : callable f(x) or None
35
+ Euclidean projection onto the constraint C, that is, a solver for the optimization problem
36
+ min_(z in C) 0.5||x-z||_2^2.
37
+
38
+ constraint : string or None
39
+ Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
40
+ For "box", the following additional parameters can be passed:
41
+ lower_bound : array_like or None
42
+ Lower bound of box, defaults to zero
43
+ upper_bound : array_like
44
+ Upper bound of box, defaults to one
45
+
46
+ regularization : string or None
47
+ Preset regularization. Can be set to "l1". Required for use in Gibbs in future update.
48
+ For "l1", the following additional parameters can be passed:
49
+ strength : scalar
50
+ Regularization parameter, i.e., strength*||x||_1 , defaults to one
51
+
52
+ """
53
+ def __init__(self, geometry, proximal = None, projector = None, constraint = None, regularization = None, **kwargs):
54
+
55
+ args = {"lower_bound" : kwargs.pop("lower_bound", None),
56
+ "upper_bound" : kwargs.pop("upper_bound", None),
57
+ "strength" : kwargs.pop("strength", None)}
58
+
59
+ # Underlying explicit Gaussian
60
+ # This line throws a warning due trying to applying get_sqrtprec_from_sqrtprec to an all zero matrix
61
+ self._gaussian = Gaussian(mean = np.zeros(geometry.par_dim), sqrtprec = np.zeros((geometry.par_dim,geometry.par_dim)), geometry = geometry, **kwargs)
62
+
63
+ # Init from abstract distribution class
64
+ super(Distribution, self).__init__(**kwargs)
65
+
66
+ self._parse_regularization_input_arguments(proximal, projector, constraint, regularization, args)
@@ -0,0 +1,70 @@
1
+ import cuqi
2
+ import numpy as np
3
+ import pytest
4
+
5
+ def test_RegularizedGaussian_default_init():
6
+ """ Test that the implicit regularized Gaussian requires at least 1 regularization argument """
7
+
8
+ with pytest.raises(ValueError, match="Precisely one of "):
9
+ x = cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1)
10
+
11
+ def test_RegularizedGaussian_guarding_statements():
12
+ """ Test that we catch incorrect initialization of RegularizedGaussian """
13
+
14
+ # More than 1 argument
15
+ with pytest.raises(ValueError, match="Precisely one of "):
16
+ cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, proximal=lambda s,z: s, constraint="nonnegativity")
17
+
18
+ # Proximal
19
+ with pytest.raises(ValueError, match="Proximal needs to be callable"):
20
+ cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, proximal=1)
21
+
22
+ with pytest.raises(ValueError, match="Proximal should take 2 arguments"):
23
+ cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, proximal=lambda s: s)
24
+
25
+ # Projector
26
+ with pytest.raises(ValueError, match="Projector needs to be callable"):
27
+ cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, projector=1)
28
+
29
+ with pytest.raises(ValueError, match="Projector should take 1 argument"):
30
+ cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, projector=lambda s,z: s)
31
+
32
+ def test_ConstrainedGaussian_alias():
33
+ """ Test that the implicit constrained Gaussian is a correct allias for an implicit regularized Gaussian """
34
+
35
+ x = cuqi.implicitprior.ConstrainedGaussian(np.zeros(5), 1, constraint="nonnegativity")
36
+
37
+ assert isinstance(x, cuqi.implicitprior.RegularizedGaussian)
38
+ assert x.preset == "nonnegativity"
39
+
40
+ def test_NonnegativeGaussian_alias():
41
+ """ Test that the implicit nonnegative Gaussian is a correct allias for an implicit regularized Gaussian """
42
+
43
+ x = cuqi.implicitprior.NonnegativeGaussian(np.zeros(5), 1)
44
+
45
+ assert isinstance(x, cuqi.implicitprior.RegularizedGaussian)
46
+ assert x.preset == "nonnegativity"
47
+
48
+ def test_ConstrainedGMRF_alias():
49
+ """ Test that the implicit constrained GMRF is a correct allias for an implicit regularized GMRF """
50
+
51
+ x = cuqi.implicitprior.ConstrainedGMRF(np.zeros(5), 1, constraint="nonnegativity")
52
+
53
+ assert isinstance(x, cuqi.implicitprior.RegularizedGMRF)
54
+ assert x.preset == "nonnegativity"
55
+
56
+ def test_NonnegativeGMRF_alias():
57
+ """ Test that the implicit nonnegative GMRF is a correct allias for an implicit regularized GMRF """
58
+
59
+ x = cuqi.implicitprior.NonnegativeGMRF(np.zeros(5), 1)
60
+
61
+ assert isinstance(x, cuqi.implicitprior.RegularizedGMRF)
62
+ assert x.preset == "nonnegativity"
63
+
64
+ def test_RegularizedUnboundedUniform_is_RegularizedGaussian():
65
+ """ Test that the implicit regularized unbounded uniform create a Regularized Gaussian with zero sqrtprec """
66
+ # NOTE: Test is based on the current assumption that the regularized uniform is modeled as a Gaussian with zero precision. This might change in the future.
67
+
68
+ x = cuqi.implicitprior.RegularizedUnboundedUniform(cuqi.geometry.Continuous1D(5), regularization="l1", strength = 5.0)
69
+
70
+ assert np.allclose(x.gaussian.sqrtprec, 0.0)
@@ -1,2 +0,0 @@
1
- from ._regularizedGaussian import RegularizedGaussian
2
- from ._regularizedGMRF import RegularizedGMRF
@@ -1,70 +0,0 @@
1
- from cuqi.implicitprior import RegularizedGaussian
2
- from cuqi.distribution import Distribution, GMRF
3
-
4
- class RegularizedGMRF(RegularizedGaussian):
5
- """ Implicit Regularized GMRF (Gaussian Markov Random Field).
6
-
7
- Defines a so-called implicit prior based on a GMRF distribution with implicit regularization.
8
- The regularization can be defined in the form of a proximal operator or a projector.
9
- Alternatively, preset constraints and regularization can be used.
10
-
11
- Only one of proximal, projector, constraint or regularization can be provided. Otherwise, an error is raised.
12
-
13
- Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
14
-
15
-
16
- For more details on implicit regularized Gaussian see the following paper:
17
-
18
- [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
19
- Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
20
-
21
- Parameters
22
- ----------
23
- mean
24
- See :class:`~cuqi.distribution.GMRF` for details.
25
-
26
- prec
27
- See :class:`~cuqi.distribution.GMRF` for details.
28
-
29
- bc_type
30
- See :class:`~cuqi.distribution.GMRF` for details.
31
-
32
- order
33
- See :class:`~cuqi.distribution.GMRF` for details.
34
-
35
- proximal : callable f(x, scale) or None
36
- Euclidean proximal operator f of the regularization function g, that is, a solver for the optimization problem
37
- min_z 0.5||x-z||_2^2+scale*g(x).
38
-
39
- projector : callable f(x) or None
40
- Euclidean projection onto the constraint C, that is, a solver for the optimization problem
41
- min_(z in C) 0.5||x-z||_2^2.
42
-
43
- constraint : string or None
44
- Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
45
- For "box", the following additional parameters can be passed:
46
- lower_bound : array_like or None
47
- Lower bound of box, defaults to zero
48
- upper_bound : array_like
49
- Upper bound of box, defaults to one
50
-
51
- regularization : string or None
52
- Preset regularization. Can be set to "l1". Required for use in Gibbs in future update.
53
- For "l1", the following additional parameters can be passed:
54
- strength : scalar
55
- Regularization parameter, i.e., strength*||x||_1 , defaults to one
56
-
57
- """
58
- def __init__(self, mean=None, prec=None, bc_type='zero', order=1, proximal = None, projector = None, constraint = None, regularization = None, **kwargs):
59
-
60
- args = {"lower_bound" : kwargs.pop("lower_bound", None),
61
- "upper_bound" : kwargs.pop("upper_bound", None),
62
- "strength" : kwargs.pop("strength", None)}
63
-
64
- # Underlying explicit GMRF
65
- self._gaussian = GMRF(mean, prec, bc_type=bc_type, order=order, **kwargs)
66
-
67
- # Init from abstract distribution class
68
- super(Distribution, self).__init__(**kwargs)
69
-
70
- self._parse_regularization_input_arguments(proximal, projector, constraint, regularization, args)
@@ -1,30 +0,0 @@
1
- import cuqi
2
- import numpy as np
3
- import pytest
4
-
5
- def test_RegularizedGaussian_default_init():
6
- """ Test that the implicit regularized Gaussian requires at least 1 regularization argument """
7
-
8
- with pytest.raises(ValueError, match="Precisely one of "):
9
- x = cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1)
10
-
11
- def test_RegularizedGaussian_guarding_statements():
12
- """ Test that we catch incorrect initialization of RegularizedGaussian """
13
-
14
- # More than 1 argument
15
- with pytest.raises(ValueError, match="Precisely one of "):
16
- cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, proximal=lambda s,z: s, constraint="nonnegativity")
17
-
18
- # Proximal
19
- with pytest.raises(ValueError, match="Proximal needs to be callable"):
20
- cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, proximal=1)
21
-
22
- with pytest.raises(ValueError, match="Proximal should take 2 arguments"):
23
- cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, proximal=lambda s: s)
24
-
25
- # Projector
26
- with pytest.raises(ValueError, match="Projector needs to be callable"):
27
- cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, projector=1)
28
-
29
- with pytest.raises(ValueError, match="Projector should take 1 argument"):
30
- cuqi.implicitprior.RegularizedGaussian(np.zeros(5), 1, projector=lambda s,z: s)