CUQIpy 1.2.0.post0.dev409__py3-none-any.whl → 1.2.0.post0.dev446__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.dev409.dist-info → CUQIpy-1.2.0.post0.dev446.dist-info}/METADATA +1 -1
- {CUQIpy-1.2.0.post0.dev409.dist-info → CUQIpy-1.2.0.post0.dev446.dist-info}/RECORD +11 -11
- cuqi/_version.py +3 -3
- cuqi/experimental/mcmc/_rto.py +47 -13
- cuqi/geometry/_geometry.py +1 -1
- cuqi/implicitprior/_regularizedGaussian.py +5 -3
- cuqi/solver/__init__.py +2 -1
- cuqi/solver/_solver.py +39 -1
- {CUQIpy-1.2.0.post0.dev409.dist-info → CUQIpy-1.2.0.post0.dev446.dist-info}/LICENSE +0 -0
- {CUQIpy-1.2.0.post0.dev409.dist-info → CUQIpy-1.2.0.post0.dev446.dist-info}/WHEEL +0 -0
- {CUQIpy-1.2.0.post0.dev409.dist-info → CUQIpy-1.2.0.post0.dev446.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: CUQIpy
|
|
3
|
-
Version: 1.2.0.post0.
|
|
3
|
+
Version: 1.2.0.post0.dev446
|
|
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=ukIYDW0D_LdEgCoVq2KQxRE9HDsW1NNxfWZNFz2Syds,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
|
|
@@ -52,14 +52,14 @@ cuqi/experimental/mcmc/_langevin_algorithm.py,sha256=NIoCLKL5x89Bxm-JLDLR_NTunRE
|
|
|
52
52
|
cuqi/experimental/mcmc/_laplace_approximation.py,sha256=XcGIa2wl9nCSTtAFurejYYOKkDVAJ22q75xQKsyu2nI,5803
|
|
53
53
|
cuqi/experimental/mcmc/_mh.py,sha256=MXo0ahXP4KGFkaY4HtvcBE-TMQzsMlTmLKzSvpz7drU,2941
|
|
54
54
|
cuqi/experimental/mcmc/_pcn.py,sha256=wqJBZLuRFSwxihaI53tumAg6AWVuceLMOmXssTetd1A,3374
|
|
55
|
-
cuqi/experimental/mcmc/_rto.py,sha256=
|
|
55
|
+
cuqi/experimental/mcmc/_rto.py,sha256=pFFzKaEDT2yLp-kstGs0tPdoq20gh3axj3XAszj9xFQ,13905
|
|
56
56
|
cuqi/experimental/mcmc/_sampler.py,sha256=BZHnpB6s-YSddd46wQSds0vNF61RA58Nc9ZU05WngdU,20184
|
|
57
57
|
cuqi/experimental/mcmc/_utilities.py,sha256=kUzHbhIS3HYZRbneNBK41IogUYX5dS_bJxqEGm7TQBI,525
|
|
58
58
|
cuqi/geometry/__init__.py,sha256=Tz1WGzZBY-QGH3c0GiyKm9XHN8MGGcnU6TUHLZkzB3o,842
|
|
59
|
-
cuqi/geometry/_geometry.py,sha256=
|
|
59
|
+
cuqi/geometry/_geometry.py,sha256=tsWMca6E-KEXwr_LhjwP7Lsdi5TWCyu0T956Cj5LEXQ,47091
|
|
60
60
|
cuqi/implicitprior/__init__.py,sha256=6z3lvw-tWDyjZSpB3pYzvijSMK9Zlf1IYqOVTtMD2h4,309
|
|
61
61
|
cuqi/implicitprior/_regularizedGMRF.py,sha256=rr3R2C1aheuu_KD35MureZKfOwY8O1pkVDHvuaFnFFU,6300
|
|
62
|
-
cuqi/implicitprior/_regularizedGaussian.py,sha256=
|
|
62
|
+
cuqi/implicitprior/_regularizedGaussian.py,sha256=btpjKUG1byLSu7S3J8N1MZZBuskCEIdmatMASwQEHtE,15656
|
|
63
63
|
cuqi/implicitprior/_regularizedUnboundedUniform.py,sha256=H2fTOSqYTlDiLxQ7Ya6wnpCUIkpO4qKrkTOsOPnBBeU,3483
|
|
64
64
|
cuqi/implicitprior/_restorator.py,sha256=Z350XUJEt7N59Qw-SIUaBljQNDJk4Zb0i_KRFrt2DCg,10087
|
|
65
65
|
cuqi/likelihood/__init__.py,sha256=QXif382iwZ5bT3ZUqmMs_n70JVbbjxbqMrlQYbMn4Zo,1776
|
|
@@ -86,15 +86,15 @@ cuqi/sampler/_rto.py,sha256=KIs0cDEoYK5I35RwO9fr5eKWeINLsmTLSVBnLdZmzzM,11921
|
|
|
86
86
|
cuqi/sampler/_sampler.py,sha256=TkZ_WAS-5Q43oICa-Elc2gftsRTBd7PEDUMDZ9tTGmU,5712
|
|
87
87
|
cuqi/samples/__init__.py,sha256=vCs6lVk-pi8RBqa6cIN5wyn6u-K9oEf1Na4k1ZMrYv8,44
|
|
88
88
|
cuqi/samples/_samples.py,sha256=hUc8OnCF9CTCuDTrGHwwzv3wp8mG_6vsJAFvuQ-x0uA,35832
|
|
89
|
-
cuqi/solver/__init__.py,sha256=
|
|
90
|
-
cuqi/solver/_solver.py,sha256=
|
|
89
|
+
cuqi/solver/__init__.py,sha256=KYgAi_8VoAwljTB3S2I87YnJkRtedskLee7hQp_-zp8,220
|
|
90
|
+
cuqi/solver/_solver.py,sha256=hGOFEJ74s0qHvXwt8h0JBdnqE5LGa_yZzNB9cd8zPAs,30661
|
|
91
91
|
cuqi/testproblem/__init__.py,sha256=DWTOcyuNHMbhEuuWlY5CkYkNDSAqhvsKmJXBLivyblU,202
|
|
92
92
|
cuqi/testproblem/_testproblem.py,sha256=x769LwwRdJdzIiZkcQUGb_5-vynNTNALXWKato7sS0Q,52540
|
|
93
93
|
cuqi/utilities/__init__.py,sha256=H7xpJe2UinjZftKvE2JuXtTi4DqtkR6uIezStAXwfGg,428
|
|
94
94
|
cuqi/utilities/_get_python_variable_name.py,sha256=wxpCaj9f3ZtBNqlGmmuGiITgBaTsY-r94lUIlK6UAU4,2043
|
|
95
95
|
cuqi/utilities/_utilities.py,sha256=Jc4knn80vLoA7kgw9FzXwKVFGaNBOXiA9kgvltZU3Ao,11777
|
|
96
|
-
CUQIpy-1.2.0.post0.
|
|
97
|
-
CUQIpy-1.2.0.post0.
|
|
98
|
-
CUQIpy-1.2.0.post0.
|
|
99
|
-
CUQIpy-1.2.0.post0.
|
|
100
|
-
CUQIpy-1.2.0.post0.
|
|
96
|
+
CUQIpy-1.2.0.post0.dev446.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
|
|
97
|
+
CUQIpy-1.2.0.post0.dev446.dist-info/METADATA,sha256=z-UvrfRd531Ja_erEONzN_pqzmd6u3_zh14VnObY3y0,18529
|
|
98
|
+
CUQIpy-1.2.0.post0.dev446.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
99
|
+
CUQIpy-1.2.0.post0.dev446.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
|
|
100
|
+
CUQIpy-1.2.0.post0.dev446.dist-info/RECORD,,
|
cuqi/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2025-01-
|
|
11
|
+
"date": "2025-01-20T14:37:50+0100",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.2.0.post0.
|
|
14
|
+
"full-revisionid": "04ade2ac5f81fefc462cb802ec723be5f10e0f0a",
|
|
15
|
+
"version": "1.2.0.post0.dev446"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
cuqi/experimental/mcmc/_rto.py
CHANGED
|
@@ -3,7 +3,7 @@ from scipy.linalg.interpolative import estimate_spectral_norm
|
|
|
3
3
|
from scipy.sparse.linalg import LinearOperator as scipyLinearOperator
|
|
4
4
|
import numpy as np
|
|
5
5
|
import cuqi
|
|
6
|
-
from cuqi.solver import CGLS, FISTA, ADMM
|
|
6
|
+
from cuqi.solver import CGLS, FISTA, ADMM, ScipyLinearLSQ
|
|
7
7
|
from cuqi.experimental.mcmc import Sampler
|
|
8
8
|
|
|
9
9
|
|
|
@@ -168,6 +168,7 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
168
168
|
Used when prior.proximal is callable.
|
|
169
169
|
ADMM: [2] Boyd et al. "Distributed optimization and statistical learning via the alternating direction method of multipliers."Foundations and Trends® in Machine learning, 2011.
|
|
170
170
|
Used when prior.proximal is a list of penalty terms.
|
|
171
|
+
ScipyLinearLSQ: Wrapper for Scipy's lsq_linear for the Trust Region Reflective algorithm. Optionally used when the constraint is either "nonnegativity" or "box".
|
|
171
172
|
|
|
172
173
|
Parameters
|
|
173
174
|
------------
|
|
@@ -178,7 +179,7 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
178
179
|
Initial point for the sampler. *Optional*.
|
|
179
180
|
|
|
180
181
|
maxit : int
|
|
181
|
-
Maximum number of iterations of the
|
|
182
|
+
Maximum number of iterations of the FISTA/ADMM/ScipyLinearLSQ solver. *Optional*.
|
|
182
183
|
|
|
183
184
|
inner_max_it : int
|
|
184
185
|
Maximum number of iterations of the CGLS solver used within the ADMM solver. *Optional*.
|
|
@@ -188,14 +189,20 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
188
189
|
If stepsize is a float, then this stepsize is used.
|
|
189
190
|
|
|
190
191
|
penalty_parameter : int
|
|
191
|
-
Penalty parameter of the
|
|
192
|
+
Penalty parameter of the ADMM solver. *Optional*.
|
|
192
193
|
See [2] or `cuqi.solver.ADMM`
|
|
193
194
|
|
|
194
195
|
abstol : float
|
|
195
|
-
Absolute tolerance of the
|
|
196
|
+
Absolute tolerance of the FISTA/ScipyLinearLSQ solver. *Optional*.
|
|
197
|
+
|
|
198
|
+
inner_abstol : float
|
|
199
|
+
Tolerance parameter for ScipyLinearLSQ's inner solve of the unbounded least-squares problem. *Optional*.
|
|
196
200
|
|
|
197
201
|
adaptive : bool
|
|
198
|
-
If True, FISTA is used as
|
|
202
|
+
If True, FISTA is used as solver, otherwise ISTA is used. *Optional*.
|
|
203
|
+
|
|
204
|
+
solver : string
|
|
205
|
+
If set to "ScipyLinearLSQ", solver is set to cuqi.solver.ScipyLinearLSQ, otherwise FISTA/ISTA or ADMM is used. Note "ScipyLinearLSQ" can only be used with `RegularizedGaussian` of `box` or `nonnegativity` constraint. *Optional*.
|
|
199
206
|
|
|
200
207
|
callback : callable, *Optional*
|
|
201
208
|
If set this function will be called after every sample.
|
|
@@ -204,23 +211,41 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
204
211
|
An example is shown in demos/demo31_callback.py.
|
|
205
212
|
|
|
206
213
|
"""
|
|
207
|
-
def __init__(self, target=None, initial_point=None, maxit=100, inner_max_it=10, stepsize="automatic", penalty_parameter=10, abstol=1e-10, adaptive=True, **kwargs):
|
|
214
|
+
def __init__(self, target=None, initial_point=None, maxit=100, inner_max_it=10, stepsize="automatic", penalty_parameter=10, abstol=1e-10, adaptive=True, solver=None, inner_abstol=None, **kwargs):
|
|
208
215
|
|
|
209
216
|
super().__init__(target=target, initial_point=initial_point, **kwargs)
|
|
210
217
|
|
|
211
218
|
# Other parameters
|
|
212
219
|
self.stepsize = stepsize
|
|
213
|
-
self.abstol = abstol
|
|
220
|
+
self.abstol = abstol
|
|
221
|
+
self.inner_abstol = inner_abstol
|
|
214
222
|
self.adaptive = adaptive
|
|
215
223
|
self.maxit = maxit
|
|
216
224
|
self.inner_max_it = inner_max_it
|
|
217
225
|
self.penalty_parameter = penalty_parameter
|
|
226
|
+
self.solver = solver
|
|
218
227
|
|
|
219
228
|
def _initialize(self):
|
|
220
229
|
super()._initialize()
|
|
221
|
-
if self.
|
|
230
|
+
if self.solver is None:
|
|
231
|
+
self.solver = "FISTA" if callable(self.proximal) else "ADMM"
|
|
232
|
+
if self.solver == "FISTA":
|
|
222
233
|
self._stepsize = self._choose_stepsize()
|
|
223
234
|
|
|
235
|
+
@property
|
|
236
|
+
def solver(self):
|
|
237
|
+
return self._solver
|
|
238
|
+
|
|
239
|
+
@solver.setter
|
|
240
|
+
def solver(self, value):
|
|
241
|
+
if value == "ScipyLinearLSQ":
|
|
242
|
+
if (self.target.prior._preset == "nonnegativity" or self.target.prior._preset == "box"):
|
|
243
|
+
self._solver = value
|
|
244
|
+
else:
|
|
245
|
+
raise ValueError("ScipyLinearLSQ only supports RegularizedGaussian with box or nonnegativity constraint.")
|
|
246
|
+
else:
|
|
247
|
+
self._solver = value
|
|
248
|
+
|
|
224
249
|
@property
|
|
225
250
|
def proximal(self):
|
|
226
251
|
return self.target.prior.proximal
|
|
@@ -229,7 +254,6 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
229
254
|
super().validate_target()
|
|
230
255
|
if not isinstance(self.target.prior, (cuqi.implicitprior.RegularizedGaussian, cuqi.implicitprior.RegularizedGMRF)):
|
|
231
256
|
raise TypeError("Prior needs to be RegularizedGaussian or RegularizedGMRF")
|
|
232
|
-
self._inner_solver = "FISTA" if callable(self.proximal) else "ADMM"
|
|
233
257
|
|
|
234
258
|
def _choose_stepsize(self):
|
|
235
259
|
if isinstance(self.stepsize, str):
|
|
@@ -254,15 +278,25 @@ class RegularizedLinearRTO(LinearRTO):
|
|
|
254
278
|
def step(self):
|
|
255
279
|
y = self.b_tild + np.random.randn(len(self.b_tild))
|
|
256
280
|
|
|
257
|
-
if self.
|
|
281
|
+
if self.solver == "FISTA":
|
|
258
282
|
sim = FISTA(self.M, y, self.proximal,
|
|
259
283
|
self.current_point, maxit = self.maxit, stepsize = self._stepsize, abstol = self.abstol, adaptive = self.adaptive)
|
|
260
|
-
elif self.
|
|
284
|
+
elif self.solver == "ADMM":
|
|
261
285
|
sim = ADMM(self.M, y, self.proximal,
|
|
262
|
-
self.current_point, self.penalty_parameter, maxit = self.maxit, inner_max_it = self.inner_max_it, adaptive = self.adaptive)
|
|
286
|
+
self.current_point, self.penalty_parameter, maxit = self.maxit, inner_max_it = self.inner_max_it, adaptive = self.adaptive)
|
|
287
|
+
elif self.solver == "ScipyLinearLSQ":
|
|
288
|
+
A_op = sp.sparse.linalg.LinearOperator((sum([llh.dim for llh in self.likelihoods])+self.target.prior.dim, self.target.prior.dim),
|
|
289
|
+
matvec=lambda x: self.M(x, 1),
|
|
290
|
+
rmatvec=lambda x: self.M(x, 2)
|
|
291
|
+
)
|
|
292
|
+
sim = ScipyLinearLSQ(A_op, y, self.target.prior._box_bounds,
|
|
293
|
+
max_iter = self.maxit,
|
|
294
|
+
lsmr_maxiter = self.inner_max_it,
|
|
295
|
+
tol = self.abstol,
|
|
296
|
+
lsmr_tol = self.inner_abstol)
|
|
263
297
|
else:
|
|
264
298
|
raise ValueError("Choice of solver not supported.")
|
|
265
299
|
|
|
266
300
|
self.current_point, _ = sim.solve()
|
|
267
301
|
acc = 1
|
|
268
|
-
return acc
|
|
302
|
+
return acc
|
cuqi/geometry/_geometry.py
CHANGED
|
@@ -523,7 +523,7 @@ class Image2D(Geometry):
|
|
|
523
523
|
Colormap is defaulted to grayscale.
|
|
524
524
|
|
|
525
525
|
A How-To guide on the use of Image2D as the domain/range geometry of a CUQI
|
|
526
|
-
:class:`Model` is available `here <https://cuqi-dtu.github.io/CUQIpy/user/_auto_howtos/
|
|
526
|
+
:class:`Model` is available `here <https://cuqi-dtu.github.io/CUQIpy/user/_auto_howtos/Image2D.html>`_.
|
|
527
527
|
|
|
528
528
|
Parameters
|
|
529
529
|
-----------
|
|
@@ -113,10 +113,12 @@ class RegularizedGaussian(Distribution):
|
|
|
113
113
|
elif (isinstance(constraint, str) and constraint.lower() == "nonnegativity"):
|
|
114
114
|
self._proximal = lambda z, gamma: ProjectNonnegative(z)
|
|
115
115
|
self._preset = "nonnegativity"
|
|
116
|
+
self._box_bounds = (np.ones(self.dim)*0, np.ones(self.dim)*np.inf)
|
|
116
117
|
elif (isinstance(constraint, str) and constraint.lower() == "box"):
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
self.
|
|
118
|
+
self._box_lower = optional_regularization_parameters["lower_bound"]
|
|
119
|
+
self._box_upper = optional_regularization_parameters["upper_bound"]
|
|
120
|
+
self._box_bounds = (np.ones(self.dim)*self._box_lower, np.ones(self.dim)*self._box_upper)
|
|
121
|
+
self._proximal = lambda z, _: ProjectBox(z, self._box_lower, self._box_upper)
|
|
120
122
|
self._preset = "box" # Not supported in Gibbs
|
|
121
123
|
elif (isinstance(regularization, str) and regularization.lower() in ["l1"]):
|
|
122
124
|
self._strength = optional_regularization_parameters["strength"]
|
cuqi/solver/__init__.py
CHANGED
cuqi/solver/_solver.py
CHANGED
|
@@ -164,7 +164,7 @@ class ScipyMaximizer(ScipyMinimizer):
|
|
|
164
164
|
|
|
165
165
|
|
|
166
166
|
|
|
167
|
-
class
|
|
167
|
+
class ScipyLSQ(object):
|
|
168
168
|
"""Wrapper for :meth:`scipy.optimize.least_squares`.
|
|
169
169
|
|
|
170
170
|
Solve nonlinear least-squares problems with bounds:
|
|
@@ -227,6 +227,44 @@ class ScipyLeastSquares(object):
|
|
|
227
227
|
sol = solution['x']
|
|
228
228
|
return sol, info
|
|
229
229
|
|
|
230
|
+
class ScipyLinearLSQ(object):
|
|
231
|
+
"""Wrapper for :meth:`scipy.optimize.lsq_linear`.
|
|
232
|
+
|
|
233
|
+
Solve linear least-squares problems with bounds:
|
|
234
|
+
|
|
235
|
+
.. math::
|
|
236
|
+
|
|
237
|
+
\min \|A x - b\|_2^2
|
|
238
|
+
|
|
239
|
+
subject to :math:`lb <= x <= ub`.
|
|
240
|
+
|
|
241
|
+
Parameters
|
|
242
|
+
----------
|
|
243
|
+
A : ndarray, LinearOperator
|
|
244
|
+
Design matrix (system matrix).
|
|
245
|
+
b : ndarray
|
|
246
|
+
The right-hand side of the linear system.
|
|
247
|
+
bounds : 2-tuple of array_like or scipy.optimize Bounds
|
|
248
|
+
Bounds for variables.
|
|
249
|
+
kwargs : Other keyword arguments passed to Scipy's `lsq_linear`. See documentation of `scipy.optimize.lsq_linear` for details.
|
|
250
|
+
"""
|
|
251
|
+
def __init__(self, A, b, bounds=(-np.inf, np.inf), **kwargs):
|
|
252
|
+
self.A = A
|
|
253
|
+
self.b = b
|
|
254
|
+
self.bounds = bounds
|
|
255
|
+
self.kwargs = kwargs
|
|
256
|
+
|
|
257
|
+
def solve(self):
|
|
258
|
+
"""Runs optimization algorithm and returns solution and optimization information.
|
|
259
|
+
|
|
260
|
+
Returns
|
|
261
|
+
----------
|
|
262
|
+
solution : Tuple
|
|
263
|
+
Solution found (array_like) and optimization information (dictionary).
|
|
264
|
+
"""
|
|
265
|
+
res = opt.lsq_linear(self.A, self.b, bounds=self.bounds, **self.kwargs)
|
|
266
|
+
x = res.pop('x')
|
|
267
|
+
return x, res
|
|
230
268
|
|
|
231
269
|
|
|
232
270
|
class CGLS(object):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|