CUQIpy 1.0.0.post0.dev215__tar.gz → 1.0.0.post0.dev229__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 (110) hide show
  1. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/CUQIpy.egg-info/PKG-INFO +1 -1
  2. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/PKG-INFO +1 -1
  3. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/_version.py +3 -3
  4. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/__init__.py +1 -1
  5. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_pcn.py +26 -8
  6. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/CUQIpy.egg-info/SOURCES.txt +0 -0
  7. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/CUQIpy.egg-info/dependency_links.txt +0 -0
  8. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/CUQIpy.egg-info/requires.txt +0 -0
  9. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/CUQIpy.egg-info/top_level.txt +0 -0
  10. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/LICENSE +0 -0
  11. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/README.md +0 -0
  12. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/__init__.py +0 -0
  13. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/_messages.py +0 -0
  14. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/array/__init__.py +0 -0
  15. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/array/_array.py +0 -0
  16. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/config.py +0 -0
  17. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/__init__.py +0 -0
  18. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/_data.py +0 -0
  19. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/astronaut.npz +0 -0
  20. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/camera.npz +0 -0
  21. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/cat.npz +0 -0
  22. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/cookie.png +0 -0
  23. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/data/satellite.mat +0 -0
  24. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/density/__init__.py +0 -0
  25. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/density/_density.py +0 -0
  26. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/diagnostics.py +0 -0
  27. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/__init__.py +0 -0
  28. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_beta.py +0 -0
  29. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_cauchy.py +0 -0
  30. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_cmrf.py +0 -0
  31. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_custom.py +0 -0
  32. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_distribution.py +0 -0
  33. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_gamma.py +0 -0
  34. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_gaussian.py +0 -0
  35. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_gmrf.py +0 -0
  36. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_inverse_gamma.py +0 -0
  37. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_joint_distribution.py +0 -0
  38. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_laplace.py +0 -0
  39. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_lmrf.py +0 -0
  40. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_lognormal.py +0 -0
  41. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_normal.py +0 -0
  42. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_posterior.py +0 -0
  43. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/distribution/_uniform.py +0 -0
  44. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/__init__.py +0 -0
  45. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_cwmh.py +0 -0
  46. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_hmc.py +0 -0
  47. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_langevin_algorithm.py +0 -0
  48. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_laplace_approximation.py +0 -0
  49. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_mh.py +0 -0
  50. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_rto.py +0 -0
  51. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/experimental/mcmc/_sampler.py +0 -0
  52. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/geometry/__init__.py +0 -0
  53. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/geometry/_geometry.py +0 -0
  54. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/implicitprior/__init__.py +0 -0
  55. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/implicitprior/_regularizedGMRF.py +0 -0
  56. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/implicitprior/_regularizedGaussian.py +0 -0
  57. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/likelihood/__init__.py +0 -0
  58. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/likelihood/_likelihood.py +0 -0
  59. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/model/__init__.py +0 -0
  60. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/model/_model.py +0 -0
  61. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/operator/__init__.py +0 -0
  62. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/operator/_operator.py +0 -0
  63. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/pde/__init__.py +0 -0
  64. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/pde/_pde.py +0 -0
  65. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/problem/__init__.py +0 -0
  66. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/problem/_problem.py +0 -0
  67. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/__init__.py +0 -0
  68. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_conjugate.py +0 -0
  69. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_conjugate_approx.py +0 -0
  70. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_cwmh.py +0 -0
  71. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_gibbs.py +0 -0
  72. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_hmc.py +0 -0
  73. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_langevin_algorithm.py +0 -0
  74. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_laplace_approximation.py +0 -0
  75. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_mh.py +0 -0
  76. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_pcn.py +0 -0
  77. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_rto.py +0 -0
  78. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/sampler/_sampler.py +0 -0
  79. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/samples/__init__.py +0 -0
  80. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/samples/_samples.py +0 -0
  81. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/solver/__init__.py +0 -0
  82. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/solver/_solver.py +0 -0
  83. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/testproblem/__init__.py +0 -0
  84. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/testproblem/_testproblem.py +0 -0
  85. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/utilities/__init__.py +0 -0
  86. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/utilities/_get_python_variable_name.py +0 -0
  87. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/cuqi/utilities/_utilities.py +0 -0
  88. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/pyproject.toml +0 -0
  89. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/requirements.txt +0 -0
  90. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/setup.cfg +0 -0
  91. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/setup.py +0 -0
  92. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_MRFs.py +0 -0
  93. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_abstract_distribution_density.py +0 -0
  94. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_bayesian_inversion.py +0 -0
  95. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_density.py +0 -0
  96. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_distribution.py +0 -0
  97. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_distributions_shape.py +0 -0
  98. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_geometry.py +0 -0
  99. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_implicit_priors.py +0 -0
  100. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_joint_distribution.py +0 -0
  101. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_likelihood.py +0 -0
  102. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_model.py +0 -0
  103. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_pde.py +0 -0
  104. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_posterior.py +0 -0
  105. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_problem.py +0 -0
  106. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_sampler.py +0 -0
  107. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_samples.py +0 -0
  108. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_solver.py +0 -0
  109. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/tests/test_testproblem.py +0 -0
  110. {cuqipy-1.0.0.post0.dev215 → cuqipy-1.0.0.post0.dev229}/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.dev215
3
+ Version: 1.0.0.post0.dev229
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.0.0.post0.dev215
3
+ Version: 1.0.0.post0.dev229
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-05-16T11:29:50+0200",
11
+ "date": "2024-05-21T12:48:50+0200",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "b713d6478d33977b12342e4bcb29968a95ee5973",
15
- "version": "1.0.0.post0.dev215"
14
+ "full-revisionid": "eb9519734f2558f66772895e41f2cd0c3cd61767",
15
+ "version": "1.0.0.post0.dev229"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -3,7 +3,7 @@
3
3
  from ._sampler import SamplerNew, ProposalBasedSamplerNew
4
4
  from ._langevin_algorithm import ULANew, MALANew
5
5
  from ._mh import MHNew
6
- from ._pcn import pCNNew
6
+ from ._pcn import PCNNew
7
7
  from ._rto import LinearRTONew, RegularizedLinearRTONew
8
8
  from ._cwmh import CWMHNew
9
9
  from ._laplace_approximation import UGLANew
@@ -3,9 +3,9 @@ import cuqi
3
3
  from cuqi.experimental.mcmc import SamplerNew
4
4
  from cuqi.array import CUQIarray
5
5
 
6
- class pCNNew(SamplerNew): # Refactor to Proposal-based sampler?
6
+ class PCNNew(SamplerNew): # Refactor to Proposal-based sampler?
7
7
 
8
- _STATE_KEYS = SamplerNew._STATE_KEYS.union({'scale', 'current_likelihood_logd'})
8
+ _STATE_KEYS = SamplerNew._STATE_KEYS.union({'scale', 'current_likelihood_logd', 'lambd'})
9
9
 
10
10
  def __init__(self, target, scale=1.0, **kwargs):
11
11
 
@@ -17,6 +17,11 @@ class pCNNew(SamplerNew): # Refactor to Proposal-based sampler?
17
17
 
18
18
  self._acc = [1] # TODO. Check if we need this
19
19
 
20
+ # parameters used in the Robbins-Monro recursion for tuning the scale parameter
21
+ # see details and reference in the tune method
22
+ self.lambd = self.scale
23
+ self.star_acc = 0.44 #TODO: 0.234 # target acceptance rate
24
+
20
25
  def validate_target(self):
21
26
  try:
22
27
  if isinstance(self.prior, (cuqi.distribution.Gaussian, cuqi.distribution.Normal)):
@@ -29,7 +34,7 @@ class pCNNew(SamplerNew): # Refactor to Proposal-based sampler?
29
34
  def step(self):
30
35
  # propose state
31
36
  xi = self.prior.sample(1).flatten() # sample from the prior
32
- x_star = np.sqrt(1-self.scale**2)*self.current_point + self.scale*xi # pCN proposal
37
+ x_star = np.sqrt(1-self.scale**2)*self.current_point + self.scale*xi # PCN proposal
33
38
 
34
39
  # evaluate target
35
40
  loglike_eval_star = self._loglikelihood(x_star)
@@ -74,10 +79,6 @@ class pCNNew(SamplerNew): # Refactor to Proposal-based sampler?
74
79
  self._loglikelihood = lambda x : self.likelihood.logd(x)
75
80
  else:
76
81
  raise ValueError(f"To initialize an object of type {self.__class__}, 'target' need to be of type 'cuqi.distribution.Posterior'.")
77
-
78
- #TODO:
79
- #if not isinstance(self.prior,(cuqi.distribution.Gaussian, cuqi.distribution.Normal)):
80
- # raise ValueError("The prior distribution of the target need to be Gaussian")
81
82
 
82
83
  @property
83
84
  def dim(self): # TODO. Check if we need this. Implemented in base class
@@ -88,4 +89,21 @@ class pCNNew(SamplerNew): # Refactor to Proposal-based sampler?
88
89
  return self._dim
89
90
 
90
91
  def tune(self, skip_len, update_count):
91
- pass
92
+ """
93
+ Tune the scale parameter of the PCN sampler.
94
+ The tuning is based on algorithm 4 in Andrieu, Christophe, and Johannes Thoms.
95
+ "A tutorial on adaptive MCMC." Statistics and computing 18 (2008): 343-373.
96
+ Note: the tuning algorithm here is the same as the one used in MH sampler.
97
+ """
98
+
99
+ # average acceptance rate in the past skip_len iterations
100
+ hat_acc = np.mean(self._acc[-skip_len:])
101
+
102
+ # new scaling parameter zeta to be used in the Robbins-Monro recursion
103
+ zeta = 1/np.sqrt(update_count+1)
104
+
105
+ # Robbins-Monro recursion to ensure that the variation of lambd vanishes
106
+ self.lambd = np.exp(np.log(self.lambd) + zeta*(hat_acc-self.star_acc))
107
+
108
+ # update scale parameter
109
+ self.scale = min(self.lambd, 1)