CUQIpy 1.2.0.post0.dev371__py3-none-any.whl → 1.2.0.post0.dev380__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.dev371
3
+ Version: 1.2.0.post0.dev380
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=aCSiaEm7qLSKRBZK6ItWGrDgH6VDQk0Dsn3zPQbPL98,510
3
+ cuqi/_version.py,sha256=4Rygq2rO32tD5TYtalGmZY_AqICH80eNKpSu2m7Zj5A,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
@@ -69,7 +69,7 @@ cuqi/operator/_operator.py,sha256=yNwPTh7jR07AiKMbMQQ5_54EgirlKFsbq9JN1EODaQI,88
69
69
  cuqi/pde/__init__.py,sha256=NyS_ZYruCvy-Yg24qKlwm3ZIX058kLNQX9bqs-xg4ZM,99
70
70
  cuqi/pde/_pde.py,sha256=WRkOYyIdT_T3aZepRh0aS9C5nBbUZUcHaA80iSRvgoo,12572
71
71
  cuqi/problem/__init__.py,sha256=JxJty4JqHTOqSG6NeTGiXRQ7OLxiRK9jvVq3lXLeIRw,38
72
- cuqi/problem/_problem.py,sha256=d5jS5ETyinv8Ez_B6I5-QOIl4Vqvf-e_6qy5RN2gnUE,38160
72
+ cuqi/problem/_problem.py,sha256=XyJ_MZbVFUiiywUM-mrra3tUD_QMRK_kXLj4xVqRgAc,38169
73
73
  cuqi/sampler/__init__.py,sha256=D-dYa0gFgIwQukP8_VKhPGmlGKXbvVo7YqaET4SdAeQ,382
74
74
  cuqi/sampler/_conjugate.py,sha256=ztmUR3V3qZk9zelKx48ULnmMs_zKTDUfohc256VOIe8,2753
75
75
  cuqi/sampler/_conjugate_approx.py,sha256=xX-X71EgxGnZooOY6CIBhuJTs3dhcKfoLnoFxX3CO2g,1938
@@ -84,15 +84,15 @@ cuqi/sampler/_rto.py,sha256=KIs0cDEoYK5I35RwO9fr5eKWeINLsmTLSVBnLdZmzzM,11921
84
84
  cuqi/sampler/_sampler.py,sha256=TkZ_WAS-5Q43oICa-Elc2gftsRTBd7PEDUMDZ9tTGmU,5712
85
85
  cuqi/samples/__init__.py,sha256=vCs6lVk-pi8RBqa6cIN5wyn6u-K9oEf1Na4k1ZMrYv8,44
86
86
  cuqi/samples/_samples.py,sha256=hUc8OnCF9CTCuDTrGHwwzv3wp8mG_6vsJAFvuQ-x0uA,35832
87
- cuqi/solver/__init__.py,sha256=3eoTTgBHe3M6ygrbgUVG3GlqaZVe5lGajNV9rolXZJ8,179
88
- cuqi/solver/_solver.py,sha256=GquU_rj-9yfPQnBVE_gXo4wdF84xw_pLks3bJarzR58,29491
87
+ cuqi/solver/__init__.py,sha256=KuNlGxjPphG9tV-46YrmbcSQNhi0HMyhDd_v6V5sRaQ,209
88
+ cuqi/solver/_solver.py,sha256=2mil7Gq7InHlQaOfnuTRDB5nw6dqJk9gR8DLFxpw_6g,29481
89
89
  cuqi/testproblem/__init__.py,sha256=DWTOcyuNHMbhEuuWlY5CkYkNDSAqhvsKmJXBLivyblU,202
90
90
  cuqi/testproblem/_testproblem.py,sha256=x769LwwRdJdzIiZkcQUGb_5-vynNTNALXWKato7sS0Q,52540
91
91
  cuqi/utilities/__init__.py,sha256=H7xpJe2UinjZftKvE2JuXtTi4DqtkR6uIezStAXwfGg,428
92
92
  cuqi/utilities/_get_python_variable_name.py,sha256=wxpCaj9f3ZtBNqlGmmuGiITgBaTsY-r94lUIlK6UAU4,2043
93
93
  cuqi/utilities/_utilities.py,sha256=Jc4knn80vLoA7kgw9FzXwKVFGaNBOXiA9kgvltZU3Ao,11777
94
- CUQIpy-1.2.0.post0.dev371.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
95
- CUQIpy-1.2.0.post0.dev371.dist-info/METADATA,sha256=E1ZkVZJmFHrBSOHR00ITcdesi425F7hiA9_zOF6K9Ws,18529
96
- CUQIpy-1.2.0.post0.dev371.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
97
- CUQIpy-1.2.0.post0.dev371.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
98
- CUQIpy-1.2.0.post0.dev371.dist-info/RECORD,,
94
+ CUQIpy-1.2.0.post0.dev380.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
95
+ CUQIpy-1.2.0.post0.dev380.dist-info/METADATA,sha256=pio8eeEPi2sbNpoalD1ZWlftxpKJMt3vin-Y0LRsJLo,18529
96
+ CUQIpy-1.2.0.post0.dev380.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
97
+ CUQIpy-1.2.0.post0.dev380.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
98
+ CUQIpy-1.2.0.post0.dev380.dist-info/RECORD,,
cuqi/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-12-10T23:09:59+0100",
11
+ "date": "2024-12-20T09:13:49+0100",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "6325eb7e648f3d6f801195a1d06a2d67928479f5",
15
- "version": "1.2.0.post0.dev371"
14
+ "full-revisionid": "7405af566d2a50ba59fc861865d41c08f8dcf160",
15
+ "version": "1.2.0.post0.dev380"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
cuqi/problem/_problem.py CHANGED
@@ -771,11 +771,11 @@ class BayesianProblem(object):
771
771
  if self._check_posterior(self, CMRF, must_have_gradient=True): # Use L-BFGS-B for CMRF prior as it has better performance for this multi-modal posterior
772
772
  if disp: print(f"Using scipy.optimize.L_BFGS_B on negative log of {density.__class__.__name__}")
773
773
  if disp: print("x0: ones vector")
774
- solver = cuqi.solver.L_BFGS_B(func, x0, gradfunc=gradfunc)
774
+ solver = cuqi.solver.ScipyLBFGSB(func, x0, gradfunc=gradfunc)
775
775
  else:
776
776
  if disp: print(f"Using scipy.optimize.minimize on negative log of {density.__class__.__name__}")
777
777
  if disp: print("x0: ones vector")
778
- solver = cuqi.solver.minimize(func, x0, gradfunc=gradfunc)
778
+ solver = cuqi.solver.ScipyMinimizer(func, x0, gradfunc=gradfunc)
779
779
 
780
780
  x_MAP, solver_info = solver.solve()
781
781
 
cuqi/solver/__init__.py CHANGED
@@ -1,8 +1,8 @@
1
1
  from ._solver import (
2
- L_BFGS_B,
3
- minimize,
4
- maximize,
5
- LS,
2
+ ScipyLBFGSB,
3
+ ScipyMinimizer,
4
+ ScipyMaximizer,
5
+ ScipyLeastSquares,
6
6
  CGLS,
7
7
  LM,
8
8
  PDHG,
cuqi/solver/_solver.py CHANGED
@@ -15,7 +15,7 @@ except ImportError:
15
15
  has_cholmod = False
16
16
 
17
17
 
18
- class L_BFGS_B(object):
18
+ class ScipyLBFGSB(object):
19
19
  """Wrapper for :meth:`scipy.optimize.fmin_l_bfgs_b`.
20
20
 
21
21
  Minimize a function func using the L-BFGS-B algorithm.
@@ -30,14 +30,10 @@ class L_BFGS_B(object):
30
30
  Initial guess.
31
31
  gradfunc : callable f(x,*args), optional
32
32
  The gradient of func.
33
- If None, then the solver approximates the gradient.
33
+ If None, the solver approximates the gradient with a finite difference scheme.
34
34
  kwargs : keyword arguments passed to scipy's L-BFGS-B algorithm. See documentation for scipy.optimize.minimize
35
-
36
- Methods
37
- ----------
38
- :meth:`solve`: Runs the solver and returns the solution and info about the optimization.
39
35
  """
40
- def __init__(self,func,x0, gradfunc = None, **kwargs):
36
+ def __init__(self, func, x0, gradfunc = None, **kwargs):
41
37
  self.func= func
42
38
  self.x0 = x0
43
39
  self.gradfunc = gradfunc
@@ -83,7 +79,7 @@ class L_BFGS_B(object):
83
79
  "nfev": solution[2]['funcalls']}
84
80
  return solution[0], info
85
81
 
86
- class minimize(object):
82
+ class ScipyMinimizer(object):
87
83
  """Wrapper for :meth:`scipy.optimize.minimize`.
88
84
 
89
85
  Minimize a function func using scipy's optimize.minimize module.
@@ -115,12 +111,8 @@ class minimize(object):
115
111
  ‘trust-krylov’
116
112
  If not given, chosen to be one of BFGS, L-BFGS-B, SLSQP, depending if the problem has constraints or bounds.
117
113
  kwargs : keyword arguments passed to scipy's minimizer. See documentation for scipy.optimize.minimize
118
-
119
- Methods
120
- ----------
121
- :meth:`solve`: Runs the solver and returns the solution and info about the optimization.
122
114
  """
123
- def __init__(self,func,x0, gradfunc = None, method = None, **kwargs):
115
+ def __init__(self, func, x0, gradfunc = '2-point', method = None, **kwargs):
124
116
  self.func= func
125
117
  self.x0 = x0
126
118
  self.method = method
@@ -147,18 +139,20 @@ class minimize(object):
147
139
  info = {"success": solution['success'],
148
140
  "message": solution['message'],
149
141
  "func": solution['fun'],
150
- "grad": solution['jac'],
151
142
  "nit": solution['nit'],
152
143
  "nfev": solution['nfev']}
144
+ # if gradfunc is callable, record the gradient in the info dict
145
+ if 'jac' in solution.keys():
146
+ info['grad'] = solution['jac']
153
147
  if isinstance(self.x0,CUQIarray):
154
148
  sol = CUQIarray(solution['x'],geometry=self.x0.geometry)
155
149
  else:
156
150
  sol = solution['x']
157
151
  return sol, info
158
152
 
159
- class maximize(minimize):
160
- """Simply calls ::class:: cuqi.solver.minimize with -func."""
161
- def __init__(self,func,x0, gradfunc = None, method = None, **kwargs):
153
+ class ScipyMaximizer(ScipyMinimizer):
154
+ """Simply calls ::class:: cuqi.solver.ScipyMinimizer with -func."""
155
+ def __init__(self, func, x0, gradfunc = None, method = None, **kwargs):
162
156
  def nfunc(*args,**kwargs):
163
157
  return -func(*args,**kwargs)
164
158
  if gradfunc is not None:
@@ -170,7 +164,7 @@ class maximize(minimize):
170
164
 
171
165
 
172
166
 
173
- class LS(object):
167
+ class ScipyLeastSquares(object):
174
168
  """Wrapper for :meth:`scipy.optimize.least_squares`.
175
169
 
176
170
  Solve nonlinear least-squares problems with bounds:
@@ -189,7 +183,7 @@ class LS(object):
189
183
  Initial guess.
190
184
  Jac : callable f(x,*args), optional
191
185
  The Jacobian of func.
192
- If None, then the solver approximates the Jacobian.
186
+ If not specified, the solver approximates the Jacobian with a finite difference scheme.
193
187
  loss: callable rho(x,*args)
194
188
  Determines the loss function
195
189
  'linear' : rho(z) = z. Gives a standard least-squares problem.
@@ -203,7 +197,7 @@ class LS(object):
203
197
  'dogbox', dogleg algorithm with rectangular trust regions, for small problems with bounds.
204
198
  'lm', Levenberg-Marquardt algorithm as implemented in MINPACK. Doesn't handle bounds and sparse Jacobians.
205
199
  """
206
- def __init__(self, func, x0, jacfun=None, method='trf', loss='linear', tol=1e-6, maxit=1e4):
200
+ def __init__(self, func, x0, jacfun='2-point', method='trf', loss='linear', tol=1e-6, maxit=1e4):
207
201
  self.func = func
208
202
  self.x0 = x0
209
203
  self.jacfun = jacfun