CUQIpy 1.2.0.post0.dev8__py3-none-any.whl → 1.2.0.post0.dev27__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.2.0.post0.dev8.dist-info → CUQIpy-1.2.0.post0.dev27.dist-info}/METADATA +1 -1
- {CUQIpy-1.2.0.post0.dev8.dist-info → CUQIpy-1.2.0.post0.dev27.dist-info}/RECORD +8 -8
- cuqi/_version.py +3 -3
- cuqi/experimental/mcmc/_hmc.py +24 -29
- cuqi/experimental/mcmc/_sampler.py +10 -2
- {CUQIpy-1.2.0.post0.dev8.dist-info → CUQIpy-1.2.0.post0.dev27.dist-info}/LICENSE +0 -0
- {CUQIpy-1.2.0.post0.dev8.dist-info → CUQIpy-1.2.0.post0.dev27.dist-info}/WHEEL +0 -0
- {CUQIpy-1.2.0.post0.dev8.dist-info → CUQIpy-1.2.0.post0.dev27.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.2.0.post0.
|
|
3
|
+
Version: 1.2.0.post0.dev27
|
|
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=XUNd3Y4LTHLhvH0Xz5AA7zswxVQgfbbyvLs1ONnxum0,509
|
|
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
|
|
@@ -40,13 +40,13 @@ cuqi/experimental/mcmc/_conjugate_approx.py,sha256=uEnY2ea9su5ivcNagyRAwpQP2gBY9
|
|
|
40
40
|
cuqi/experimental/mcmc/_cwmh.py,sha256=50v3uZaWhlVnfrEB5-lB_7pn8QoUVBe-xWxKGKbmNHg,7234
|
|
41
41
|
cuqi/experimental/mcmc/_direct.py,sha256=9pQS_2Qk2-ybt6m8WTfPoKetcxQ00WaTRN85-Z0FrBY,777
|
|
42
42
|
cuqi/experimental/mcmc/_gibbs.py,sha256=a_Zr007F233R6A3CJ_0zlQppsQrVuX8-oWCbNJWJxmA,12745
|
|
43
|
-
cuqi/experimental/mcmc/_hmc.py,sha256=
|
|
43
|
+
cuqi/experimental/mcmc/_hmc.py,sha256=AR8ucnjPe9Q78em3IMoihLoifdBxu9oAjrQ51AYPHH4,19390
|
|
44
44
|
cuqi/experimental/mcmc/_langevin_algorithm.py,sha256=yNO7ABxmkixzcLG-lv57GOTyeTr7HwFs2DrrhuZW9OI,8398
|
|
45
45
|
cuqi/experimental/mcmc/_laplace_approximation.py,sha256=rdiE3cMQFq6FLQcOQwPpuGIxrTAp3aoGPxMDSdeopV0,5688
|
|
46
46
|
cuqi/experimental/mcmc/_mh.py,sha256=MXo0ahXP4KGFkaY4HtvcBE-TMQzsMlTmLKzSvpz7drU,2941
|
|
47
47
|
cuqi/experimental/mcmc/_pcn.py,sha256=wqJBZLuRFSwxihaI53tumAg6AWVuceLMOmXssTetd1A,3374
|
|
48
48
|
cuqi/experimental/mcmc/_rto.py,sha256=OtzgiYCxDoTdXp7y4mkLa2upj74qadesoqHYpr11ZCg,10061
|
|
49
|
-
cuqi/experimental/mcmc/_sampler.py,sha256=
|
|
49
|
+
cuqi/experimental/mcmc/_sampler.py,sha256=lWb0ORdkYcVkZ6G0ypHfmrWXZPfaXnsUj1wAncKxa7g,20339
|
|
50
50
|
cuqi/experimental/mcmc/_utilities.py,sha256=kUzHbhIS3HYZRbneNBK41IogUYX5dS_bJxqEGm7TQBI,525
|
|
51
51
|
cuqi/geometry/__init__.py,sha256=Tz1WGzZBY-QGH3c0GiyKm9XHN8MGGcnU6TUHLZkzB3o,842
|
|
52
52
|
cuqi/geometry/_geometry.py,sha256=SDRZdiN2CIuS591lXxqgFoPWPIpwY-MHk75116QvdYY,46901
|
|
@@ -85,8 +85,8 @@ cuqi/testproblem/_testproblem.py,sha256=x769LwwRdJdzIiZkcQUGb_5-vynNTNALXWKato7s
|
|
|
85
85
|
cuqi/utilities/__init__.py,sha256=H7xpJe2UinjZftKvE2JuXtTi4DqtkR6uIezStAXwfGg,428
|
|
86
86
|
cuqi/utilities/_get_python_variable_name.py,sha256=QwlBVj2koJRA8s8pWd554p7-ElcI7HUwY32HknaR92E,1827
|
|
87
87
|
cuqi/utilities/_utilities.py,sha256=Jc4knn80vLoA7kgw9FzXwKVFGaNBOXiA9kgvltZU3Ao,11777
|
|
88
|
-
CUQIpy-1.2.0.post0.
|
|
89
|
-
CUQIpy-1.2.0.post0.
|
|
90
|
-
CUQIpy-1.2.0.post0.
|
|
91
|
-
CUQIpy-1.2.0.post0.
|
|
92
|
-
CUQIpy-1.2.0.post0.
|
|
88
|
+
CUQIpy-1.2.0.post0.dev27.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
|
|
89
|
+
CUQIpy-1.2.0.post0.dev27.dist-info/METADATA,sha256=e4sjOzPLNqifeVV_6sUvLx64pIOfhsZLw42i2Xi58UU,18410
|
|
90
|
+
CUQIpy-1.2.0.post0.dev27.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
91
|
+
CUQIpy-1.2.0.post0.dev27.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
|
|
92
|
+
CUQIpy-1.2.0.post0.dev27.dist-info/RECORD,,
|
cuqi/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2024-
|
|
11
|
+
"date": "2024-10-04T09:06:08+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.2.0.post0.
|
|
14
|
+
"full-revisionid": "f5a74472dfb8e7d2e07e829b2a03b811d554dc67",
|
|
15
|
+
"version": "1.2.0.post0.dev27"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
cuqi/experimental/mcmc/_hmc.py
CHANGED
|
@@ -88,14 +88,16 @@ class NUTS(Sampler):
|
|
|
88
88
|
"""
|
|
89
89
|
|
|
90
90
|
_STATE_KEYS = Sampler._STATE_KEYS.union({'_epsilon', '_epsilon_bar',
|
|
91
|
-
'_H_bar',
|
|
92
|
-
'
|
|
91
|
+
'_H_bar',
|
|
92
|
+
'current_target_logd',
|
|
93
|
+
'current_target_grad',
|
|
94
|
+
'max_depth'})
|
|
93
95
|
|
|
94
96
|
_HISTORY_KEYS = Sampler._HISTORY_KEYS.union({'num_tree_node_list',
|
|
95
97
|
'epsilon_list',
|
|
96
98
|
'epsilon_bar_list'})
|
|
97
99
|
|
|
98
|
-
def __init__(self, target=None, initial_point=None, max_depth=
|
|
100
|
+
def __init__(self, target=None, initial_point=None, max_depth=None,
|
|
99
101
|
step_size=None, opt_acc_rate=0.6, **kwargs):
|
|
100
102
|
super().__init__(target, initial_point=initial_point, **kwargs)
|
|
101
103
|
|
|
@@ -104,30 +106,20 @@ class NUTS(Sampler):
|
|
|
104
106
|
self.step_size = step_size
|
|
105
107
|
self.opt_acc_rate = opt_acc_rate
|
|
106
108
|
|
|
107
|
-
# Initialize epsilon and epsilon_bar
|
|
108
|
-
# epsilon is the step size used in the current iteration
|
|
109
|
-
# after warm up and one sampling step, epsilon is updated
|
|
110
|
-
# to epsilon_bar for the remaining sampling steps.
|
|
111
|
-
self._epsilon = None
|
|
112
|
-
self._epsilon_bar = None
|
|
113
|
-
self._H_bar = None
|
|
114
|
-
|
|
115
|
-
# Extra parameters for tuning
|
|
116
|
-
self._n_alpha = None
|
|
117
|
-
self._alpha = None
|
|
118
|
-
|
|
119
109
|
|
|
120
110
|
def _initialize(self):
|
|
121
111
|
|
|
122
|
-
#
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
self._alpha = 0 # check if meaningful value
|
|
126
|
-
self._n_alpha = 0 # check if meaningful value
|
|
112
|
+
self._current_alpha_ratio = np.nan # Current alpha ratio will be set to some
|
|
113
|
+
# value (other than np.nan) before
|
|
114
|
+
# being used
|
|
127
115
|
|
|
128
116
|
self.current_target_logd, self.current_target_grad = self._nuts_target(self.current_point)
|
|
129
117
|
|
|
130
|
-
#
|
|
118
|
+
# Parameters dual averaging
|
|
119
|
+
# Initialize epsilon and epsilon_bar
|
|
120
|
+
# epsilon is the step size used in the current iteration
|
|
121
|
+
# after warm up and one sampling step, epsilon is updated
|
|
122
|
+
# to epsilon_bar for the remaining sampling steps.
|
|
131
123
|
if self.step_size is None:
|
|
132
124
|
self._epsilon = self._FindGoodEpsilon()
|
|
133
125
|
else:
|
|
@@ -155,6 +147,8 @@ class NUTS(Sampler):
|
|
|
155
147
|
|
|
156
148
|
@max_depth.setter
|
|
157
149
|
def max_depth(self, value):
|
|
150
|
+
if value is None:
|
|
151
|
+
value = 15 # default value
|
|
158
152
|
if not isinstance(value, int):
|
|
159
153
|
raise TypeError('max_depth must be an integer.')
|
|
160
154
|
if value < 0:
|
|
@@ -236,6 +230,7 @@ class NUTS(Sampler):
|
|
|
236
230
|
r_minus, r_plus = np.copy(r_k), np.copy(r_k)
|
|
237
231
|
|
|
238
232
|
# run NUTS
|
|
233
|
+
acc = 0
|
|
239
234
|
while (s == 1) and (j <= self.max_depth):
|
|
240
235
|
# sample a direction
|
|
241
236
|
v = int(2*(np.random.rand() < 0.5)-1)
|
|
@@ -263,9 +258,8 @@ class NUTS(Sampler):
|
|
|
263
258
|
self.current_point = point_prime
|
|
264
259
|
self.current_target_logd = logd_prime
|
|
265
260
|
self.current_target_grad = np.copy(grad_prime)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
self._acc.append(0)
|
|
261
|
+
acc = 1
|
|
262
|
+
|
|
269
263
|
|
|
270
264
|
# update number of particles, tree level, and stopping criterion
|
|
271
265
|
n += n_prime
|
|
@@ -273,8 +267,7 @@ class NUTS(Sampler):
|
|
|
273
267
|
s = s_prime *\
|
|
274
268
|
int((dpoints @ r_minus.T) >= 0) * int((dpoints @ r_plus.T) >= 0)
|
|
275
269
|
j += 1
|
|
276
|
-
self.
|
|
277
|
-
self._n_alpha = n_alpha
|
|
270
|
+
self._current_alpha_ratio = alpha/n_alpha
|
|
278
271
|
|
|
279
272
|
# update run diagnostic attributes
|
|
280
273
|
self._update_run_diagnostic_attributes(
|
|
@@ -284,6 +277,8 @@ class NUTS(Sampler):
|
|
|
284
277
|
if np.isnan(self.current_target_logd):
|
|
285
278
|
raise NameError('NaN potential func')
|
|
286
279
|
|
|
280
|
+
return acc
|
|
281
|
+
|
|
287
282
|
def tune(self, skip_len, update_count):
|
|
288
283
|
""" adapt epsilon during burn-in using dual averaging"""
|
|
289
284
|
k = update_count+1
|
|
@@ -293,7 +288,7 @@ class NUTS(Sampler):
|
|
|
293
288
|
|
|
294
289
|
eta1 = 1/(k + t_0)
|
|
295
290
|
self._H_bar = (1-eta1)*self._H_bar +\
|
|
296
|
-
eta1*(self.opt_acc_rate - (self.
|
|
291
|
+
eta1*(self.opt_acc_rate - (self._current_alpha_ratio))
|
|
297
292
|
self._epsilon = np.exp(self._mu - (np.sqrt(k)/gamma)*self._H_bar)
|
|
298
293
|
eta = k**(-kappa)
|
|
299
294
|
self._epsilon_bar =\
|
|
@@ -309,12 +304,12 @@ class NUTS(Sampler):
|
|
|
309
304
|
# self._epsilon
|
|
310
305
|
# Parameters that does not change during the run
|
|
311
306
|
# self._mu
|
|
312
|
-
|
|
307
|
+
self._ensure_initialized()
|
|
313
308
|
if self._epsilon_bar == "unset": # Initial value of epsilon_bar for tuning
|
|
314
309
|
self._epsilon_bar = 1
|
|
315
310
|
|
|
316
311
|
def _pre_sample(self):
|
|
317
|
-
|
|
312
|
+
self._ensure_initialized()
|
|
318
313
|
if self._epsilon_bar == "unset": # Initial value of epsilon_bar for sampling
|
|
319
314
|
self._epsilon_bar = self._epsilon
|
|
320
315
|
|
|
@@ -220,7 +220,8 @@ class Sampler(ABC):
|
|
|
220
220
|
if hasattr(self, "_pre_sample"): self._pre_sample()
|
|
221
221
|
|
|
222
222
|
# Draw samples
|
|
223
|
-
|
|
223
|
+
pbar = tqdm(range(Ns), "Sample: ")
|
|
224
|
+
for idx in pbar:
|
|
224
225
|
|
|
225
226
|
# Perform one step of the sampler
|
|
226
227
|
acc = self.step()
|
|
@@ -229,6 +230,9 @@ class Sampler(ABC):
|
|
|
229
230
|
self._acc.append(acc)
|
|
230
231
|
self._samples.append(self.current_point)
|
|
231
232
|
|
|
233
|
+
# display acc rate at progress bar
|
|
234
|
+
pbar.set_postfix_str(f"acc rate: {np.mean(self._acc[-1-idx:]):.2%}")
|
|
235
|
+
|
|
232
236
|
# Add sample to batch
|
|
233
237
|
if batch_size > 0:
|
|
234
238
|
batch_handler.add_sample(self.current_point)
|
|
@@ -260,7 +264,8 @@ class Sampler(ABC):
|
|
|
260
264
|
if hasattr(self, "_pre_warmup"): self._pre_warmup()
|
|
261
265
|
|
|
262
266
|
# Draw warmup samples with tuning
|
|
263
|
-
|
|
267
|
+
pbar = tqdm(range(Nb), "Warmup: ")
|
|
268
|
+
for idx in pbar:
|
|
264
269
|
|
|
265
270
|
# Perform one step of the sampler
|
|
266
271
|
acc = self.step()
|
|
@@ -273,6 +278,9 @@ class Sampler(ABC):
|
|
|
273
278
|
self._acc.append(acc)
|
|
274
279
|
self._samples.append(self.current_point)
|
|
275
280
|
|
|
281
|
+
# display acc rate at progress bar
|
|
282
|
+
pbar.set_postfix_str(f"acc rate: {np.mean(self._acc[-1-idx:]):.2%}")
|
|
283
|
+
|
|
276
284
|
# Call callback function if specified
|
|
277
285
|
self._call_callback(self.current_point, len(self._samples)-1)
|
|
278
286
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|