CUQIpy 1.0.0.post0.dev215__py3-none-any.whl → 1.0.0.post0.dev229__py3-none-any.whl
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.0.0.post0.dev215.dist-info → CUQIpy-1.0.0.post0.dev229.dist-info}/METADATA +1 -1
- {CUQIpy-1.0.0.post0.dev215.dist-info → CUQIpy-1.0.0.post0.dev229.dist-info}/RECORD +8 -8
- cuqi/_version.py +3 -3
- cuqi/experimental/mcmc/__init__.py +1 -1
- cuqi/experimental/mcmc/_pcn.py +26 -8
- {CUQIpy-1.0.0.post0.dev215.dist-info → CUQIpy-1.0.0.post0.dev229.dist-info}/LICENSE +0 -0
- {CUQIpy-1.0.0.post0.dev215.dist-info → CUQIpy-1.0.0.post0.dev229.dist-info}/WHEEL +0 -0
- {CUQIpy-1.0.0.post0.dev215.dist-info → CUQIpy-1.0.0.post0.dev229.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.0.0.post0.
|
|
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
|
cuqi/__init__.py,sha256=LsGilhl-hBLEn6Glt8S_l0OJzAA1sKit_rui8h-D-p0,488
|
|
2
2
|
cuqi/_messages.py,sha256=fzEBrZT2kbmfecBBPm7spVu7yHdxGARQB4QzXhJbCJ0,415
|
|
3
|
-
cuqi/_version.py,sha256=
|
|
3
|
+
cuqi/_version.py,sha256=qSCcU546LTLb2CnsgdAFPFHEfSeVUxNMie_SdR9XFeY,510
|
|
4
4
|
cuqi/config.py,sha256=wcYvz19wkeKW2EKCGIKJiTpWt5kdaxyt4imyRkvtTRA,526
|
|
5
5
|
cuqi/diagnostics.py,sha256=5OrbJeqpynqRXOe5MtOKKhe7EAVdOEpHIqHnlMW9G_c,3029
|
|
6
6
|
cuqi/array/__init__.py,sha256=-EeiaiWGNsE3twRS4dD814BIlfxEsNkTCZUc5gjOXb0,30
|
|
@@ -32,13 +32,13 @@ cuqi/distribution/_normal.py,sha256=UeoTtGDT7YSf4ZNo2amlVF9K-YQpYbf8q76jcRJTVFw,
|
|
|
32
32
|
cuqi/distribution/_posterior.py,sha256=zAfL0GECxekZ2lBt1W6_LN0U_xskMwK4VNce5xAF7ig,5018
|
|
33
33
|
cuqi/distribution/_uniform.py,sha256=7xJmCZH_LPhuGkwEDGh-_CTtzcWKrXMOxtTJUFb7Ydo,1607
|
|
34
34
|
cuqi/experimental/__init__.py,sha256=vhZvyMX6rl8Y0haqCzGLPz6PSUKyu75XMQbeDHqTTrw,83
|
|
35
|
-
cuqi/experimental/mcmc/__init__.py,sha256=
|
|
35
|
+
cuqi/experimental/mcmc/__init__.py,sha256=UqoyPWNQt4ZGIgc9Buhl5gf3toAxLjXLyQ7DieDQlRw,384
|
|
36
36
|
cuqi/experimental/mcmc/_cwmh.py,sha256=yRlTk5a1QYfH3JyCecfOOTeDf-4-tmJ3Tl2Bc3pyp1Y,7336
|
|
37
37
|
cuqi/experimental/mcmc/_hmc.py,sha256=qqAyoAajLE_JenYMgAbD3tknuEf75AJu-ufF69GKGk4,19384
|
|
38
38
|
cuqi/experimental/mcmc/_langevin_algorithm.py,sha256=MX48u3GYgCckB6Q5h5kXr_qdIaLQH2toOG5u29OY7gk,8245
|
|
39
39
|
cuqi/experimental/mcmc/_laplace_approximation.py,sha256=7reeOnDY77WnOwqYls5WStftHgylwCNVodudRroApF0,5812
|
|
40
40
|
cuqi/experimental/mcmc/_mh.py,sha256=aIV1Ntq0EAq3QJ1_X-DbP7eDAL-d_Or7d3RUO-R48I4,3090
|
|
41
|
-
cuqi/experimental/mcmc/_pcn.py,sha256=
|
|
41
|
+
cuqi/experimental/mcmc/_pcn.py,sha256=m7pR266uUJQociOe_CpUUlKHkfm8g--JfRWaQA2IKis,4364
|
|
42
42
|
cuqi/experimental/mcmc/_rto.py,sha256=jSPznr34XPfWM6LysWIiN4hE-vtyti3cHyvzy9ruykg,11349
|
|
43
43
|
cuqi/experimental/mcmc/_sampler.py,sha256=_5Uo2F-Mta46w3lo7WBVNwvTLYhES_BzMTJrKxA00c8,14861
|
|
44
44
|
cuqi/geometry/__init__.py,sha256=Tz1WGzZBY-QGH3c0GiyKm9XHN8MGGcnU6TUHLZkzB3o,842
|
|
@@ -77,8 +77,8 @@ cuqi/testproblem/_testproblem.py,sha256=x769LwwRdJdzIiZkcQUGb_5-vynNTNALXWKato7s
|
|
|
77
77
|
cuqi/utilities/__init__.py,sha256=T4tLsC215MknBCsw_C0Qeeg_ox26aDUrCA5hbWvNQkU,387
|
|
78
78
|
cuqi/utilities/_get_python_variable_name.py,sha256=QwlBVj2koJRA8s8pWd554p7-ElcI7HUwY32HknaR92E,1827
|
|
79
79
|
cuqi/utilities/_utilities.py,sha256=MWAqV6L5btMpWwlUzrZYuV2VeSpfTbOaLRMRkuw2WIA,8509
|
|
80
|
-
CUQIpy-1.0.0.post0.
|
|
81
|
-
CUQIpy-1.0.0.post0.
|
|
82
|
-
CUQIpy-1.0.0.post0.
|
|
83
|
-
CUQIpy-1.0.0.post0.
|
|
84
|
-
CUQIpy-1.0.0.post0.
|
|
80
|
+
CUQIpy-1.0.0.post0.dev229.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
|
|
81
|
+
CUQIpy-1.0.0.post0.dev229.dist-info/METADATA,sha256=-LQQOopcYpRJTp_ZhyH2H97JxI2jLfgsIS1AzYs1FNU,18393
|
|
82
|
+
CUQIpy-1.0.0.post0.dev229.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
83
|
+
CUQIpy-1.0.0.post0.dev229.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
|
|
84
|
+
CUQIpy-1.0.0.post0.dev229.dist-info/RECORD,,
|
cuqi/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2024-05-
|
|
11
|
+
"date": "2024-05-21T12:48:50+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.0.0.post0.
|
|
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
|
|
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
|
cuqi/experimental/mcmc/_pcn.py
CHANGED
|
@@ -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
|
|
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 #
|
|
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
|
-
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|