CUQIpy 1.2.0.post0.dev6__py3-none-any.whl → 1.2.0.post0.dev15__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CUQIpy
3
- Version: 1.2.0.post0.dev6
3
+ Version: 1.2.0.post0.dev15
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=xb6__fpIlsNEbO-nODNBdf1auVnfH6IOTdnzCGGf1Jg,508
3
+ cuqi/_version.py,sha256=jnnRtB8exI7lWU5EPo-fzA3hR7cN_F8fP6jeWSCwWEk,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,7 +40,7 @@ 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=UAPM9tGs8tneUcDiywXKEBNsKazQMLSjWsTemJ7QwnQ,19377
43
+ cuqi/experimental/mcmc/_hmc.py,sha256=2MuU-fWvun0bmt1niFLL7iIHbtwubI2b-MHRykWDjwM,19548
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
@@ -63,7 +63,7 @@ cuqi/operator/_operator.py,sha256=yNwPTh7jR07AiKMbMQQ5_54EgirlKFsbq9JN1EODaQI,88
63
63
  cuqi/pde/__init__.py,sha256=NyS_ZYruCvy-Yg24qKlwm3ZIX058kLNQX9bqs-xg4ZM,99
64
64
  cuqi/pde/_pde.py,sha256=WRkOYyIdT_T3aZepRh0aS9C5nBbUZUcHaA80iSRvgoo,12572
65
65
  cuqi/problem/__init__.py,sha256=JxJty4JqHTOqSG6NeTGiXRQ7OLxiRK9jvVq3lXLeIRw,38
66
- cuqi/problem/_problem.py,sha256=t8y8NNQGKHYIbXN45FWuuwuU7pMgDdD8MS6az_1Tx8k,38160
66
+ cuqi/problem/_problem.py,sha256=d5jS5ETyinv8Ez_B6I5-QOIl4Vqvf-e_6qy5RN2gnUE,38160
67
67
  cuqi/sampler/__init__.py,sha256=D-dYa0gFgIwQukP8_VKhPGmlGKXbvVo7YqaET4SdAeQ,382
68
68
  cuqi/sampler/_conjugate.py,sha256=ztmUR3V3qZk9zelKx48ULnmMs_zKTDUfohc256VOIe8,2753
69
69
  cuqi/sampler/_conjugate_approx.py,sha256=xX-X71EgxGnZooOY6CIBhuJTs3dhcKfoLnoFxX3CO2g,1938
@@ -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.dev6.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
89
- CUQIpy-1.2.0.post0.dev6.dist-info/METADATA,sha256=5JyZXn9E9P00XKFW9jfbJNRr5qR75LAYKxOEdcgKbG0,18409
90
- CUQIpy-1.2.0.post0.dev6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
91
- CUQIpy-1.2.0.post0.dev6.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
92
- CUQIpy-1.2.0.post0.dev6.dist-info/RECORD,,
88
+ CUQIpy-1.2.0.post0.dev15.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
89
+ CUQIpy-1.2.0.post0.dev15.dist-info/METADATA,sha256=AjFHjLR2ychxpFCl7bziruEmKwSf0O8mpLd_jHCZ4wg,18410
90
+ CUQIpy-1.2.0.post0.dev15.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
91
+ CUQIpy-1.2.0.post0.dev15.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
92
+ CUQIpy-1.2.0.post0.dev15.dist-info/RECORD,,
cuqi/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-09-26T10:45:39+0200",
11
+ "date": "2024-09-30T18:06:47+0200",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "d00b1c910863237ecb20eef45804b254af31f094",
15
- "version": "1.2.0.post0.dev6"
14
+ "full-revisionid": "59a6730dfe1227a35a2def467daf63265bdba87f",
15
+ "version": "1.2.0.post0.dev15"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -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', '_mu',
92
- '_alpha', '_n_alpha'})
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=15,
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,23 @@ 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
112
  # Arrays to store acceptance rate
123
113
  self._acc = [None] # Overwrites acc from Sampler. TODO. Check if this is necessary
124
114
 
125
- self._alpha = 0 # check if meaningful value
126
- self._n_alpha = 0 # check if meaningful value
115
+ self._current_alpha_ratio = np.nan # Current alpha ratio is set to some
116
+ # value (other than np.nan) before
117
+ # being used
127
118
 
128
119
  self.current_target_logd, self.current_target_grad = self._nuts_target(self.current_point)
129
120
 
130
- # parameters dual averaging
121
+ # Parameters dual averaging
122
+ # Initialize epsilon and epsilon_bar
123
+ # epsilon is the step size used in the current iteration
124
+ # after warm up and one sampling step, epsilon is updated
125
+ # to epsilon_bar for the remaining sampling steps.
131
126
  if self.step_size is None:
132
127
  self._epsilon = self._FindGoodEpsilon()
133
128
  else:
@@ -155,6 +150,8 @@ class NUTS(Sampler):
155
150
 
156
151
  @max_depth.setter
157
152
  def max_depth(self, value):
153
+ if value is None:
154
+ value = 15 # default value
158
155
  if not isinstance(value, int):
159
156
  raise TypeError('max_depth must be an integer.')
160
157
  if value < 0:
@@ -273,8 +270,7 @@ class NUTS(Sampler):
273
270
  s = s_prime *\
274
271
  int((dpoints @ r_minus.T) >= 0) * int((dpoints @ r_plus.T) >= 0)
275
272
  j += 1
276
- self._alpha = alpha
277
- self._n_alpha = n_alpha
273
+ self._current_alpha_ratio = alpha/n_alpha
278
274
 
279
275
  # update run diagnostic attributes
280
276
  self._update_run_diagnostic_attributes(
@@ -293,7 +289,7 @@ class NUTS(Sampler):
293
289
 
294
290
  eta1 = 1/(k + t_0)
295
291
  self._H_bar = (1-eta1)*self._H_bar +\
296
- eta1*(self.opt_acc_rate - (self._alpha/self._n_alpha))
292
+ eta1*(self.opt_acc_rate - (self._current_alpha_ratio))
297
293
  self._epsilon = np.exp(self._mu - (np.sqrt(k)/gamma)*self._H_bar)
298
294
  eta = k**(-kappa)
299
295
  self._epsilon_bar =\
@@ -309,12 +305,12 @@ class NUTS(Sampler):
309
305
  # self._epsilon
310
306
  # Parameters that does not change during the run
311
307
  # self._mu
312
-
308
+ self._ensure_initialized()
313
309
  if self._epsilon_bar == "unset": # Initial value of epsilon_bar for tuning
314
310
  self._epsilon_bar = 1
315
311
 
316
312
  def _pre_sample(self):
317
-
313
+ self._ensure_initialized()
318
314
  if self._epsilon_bar == "unset": # Initial value of epsilon_bar for sampling
319
315
  self._epsilon_bar = self._epsilon
320
316
 
cuqi/problem/_problem.py CHANGED
@@ -614,7 +614,7 @@ class BayesianProblem(object):
614
614
 
615
615
  scale = 0.02
616
616
 
617
- sampler = cuqi.experimental.mcmc.pCN(self.posterior, scale, callback=callback)
617
+ sampler = cuqi.experimental.mcmc.PCN(self.posterior, scale, callback=callback)
618
618
 
619
619
  ti = time.time()
620
620