CUQIpy 1.0.0.post0.dev360__py3-none-any.whl → 1.0.0.post0.dev384__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.dev360.dist-info → CUQIpy-1.0.0.post0.dev384.dist-info}/METADATA +1 -1
- {CUQIpy-1.0.0.post0.dev360.dist-info → CUQIpy-1.0.0.post0.dev384.dist-info}/RECORD +12 -10
- {CUQIpy-1.0.0.post0.dev360.dist-info → CUQIpy-1.0.0.post0.dev384.dist-info}/WHEEL +1 -1
- cuqi/_version.py +3 -3
- cuqi/distribution/__init__.py +1 -0
- cuqi/distribution/_smoothed_laplace.py +95 -0
- cuqi/implicitprior/__init__.py +3 -2
- cuqi/implicitprior/_regularizedGMRF.py +82 -0
- cuqi/implicitprior/_regularizedGaussian.py +87 -0
- cuqi/implicitprior/_regularizedUnboundedUniform.py +66 -0
- {CUQIpy-1.0.0.post0.dev360.dist-info → CUQIpy-1.0.0.post0.dev384.dist-info}/LICENSE +0 -0
- {CUQIpy-1.0.0.post0.dev360.dist-info → CUQIpy-1.0.0.post0.dev384.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.dev384
|
|
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=IKVgkfhXqLynqXrlVfTXOFBq5r4w6rJcCBTk1PNkuKA,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
|
|
@@ -14,7 +14,7 @@ cuqi/data/cookie.png,sha256=mr6wUeoIUc5VC2qYj8vafOmTbcRwz0fHz4IIPK9_PnE,984680
|
|
|
14
14
|
cuqi/data/satellite.mat,sha256=a0Nz_Ak-Y0m360dH74pa_rpk-MhaQ91ftGTKhQX7I8g,16373
|
|
15
15
|
cuqi/density/__init__.py,sha256=0zfVcPgqdqiPkss5n_WP_PUt-G3ovHXjokhqEKIlLwA,48
|
|
16
16
|
cuqi/density/_density.py,sha256=BG7gtP0cbFYLVgjYQGkNAhM95PR5ocBVLKRlOVX2PyM,7253
|
|
17
|
-
cuqi/distribution/__init__.py,sha256=
|
|
17
|
+
cuqi/distribution/__init__.py,sha256=4vVLArg6NVzBj67vVioK8BY6wISJKb5cOxdoHMuUb_s,714
|
|
18
18
|
cuqi/distribution/_beta.py,sha256=hdAc6Tbuz9Yqf76NSHxpaUgN7s6Z2lNV7YSRD3JhyCU,2997
|
|
19
19
|
cuqi/distribution/_cauchy.py,sha256=UsVXYz8HhagXN5fIWSAIyELqhsJAX_-wk9kkRGgRmA8,3296
|
|
20
20
|
cuqi/distribution/_cmrf.py,sha256=tCbEulM_O7FB3C_W-3IqZp9zGHkTofCdFF0ybHc9UZI,3745
|
|
@@ -31,6 +31,7 @@ cuqi/distribution/_lognormal.py,sha256=st1Uhf67qy2Seo65hA88JQ7lkEjQkW6KxznXahF_0
|
|
|
31
31
|
cuqi/distribution/_modifiedhalfnormal.py,sha256=gB9fj10hdMvr05aa_xhAirJATLqKh1gpbdSs2pRoAVM,7267
|
|
32
32
|
cuqi/distribution/_normal.py,sha256=UeoTtGDT7YSf4ZNo2amlVF9K-YQpYbf8q76jcRJTVFw,1914
|
|
33
33
|
cuqi/distribution/_posterior.py,sha256=zAfL0GECxekZ2lBt1W6_LN0U_xskMwK4VNce5xAF7ig,5018
|
|
34
|
+
cuqi/distribution/_smoothed_laplace.py,sha256=bfvOI4YOYC6QPds1UHNHar_q-vOZEjBcPxVhIlq7s0k,2923
|
|
34
35
|
cuqi/distribution/_uniform.py,sha256=7xJmCZH_LPhuGkwEDGh-_CTtzcWKrXMOxtTJUFb7Ydo,1607
|
|
35
36
|
cuqi/experimental/__init__.py,sha256=vhZvyMX6rl8Y0haqCzGLPz6PSUKyu75XMQbeDHqTTrw,83
|
|
36
37
|
cuqi/experimental/mcmc/__init__.py,sha256=0Vk_MzfE_9tvqQRgR6_3nkjSe_D3vgFqVM9pFrXN2iQ,581
|
|
@@ -49,9 +50,10 @@ cuqi/experimental/mcmc/_sampler.py,sha256=4dh9XVALkD3Ro9vkLZkNoFNge7Xv8QRbjh4LB7
|
|
|
49
50
|
cuqi/experimental/mcmc/_utilities.py,sha256=qrSq8hvK_G2rSxYYfR5psk4sbTe7098TS5QNu13THeE,528
|
|
50
51
|
cuqi/geometry/__init__.py,sha256=Tz1WGzZBY-QGH3c0GiyKm9XHN8MGGcnU6TUHLZkzB3o,842
|
|
51
52
|
cuqi/geometry/_geometry.py,sha256=WYFC-4_VBTW73b2ldsnfGYKvdSiCE8plr89xTSmkadg,46804
|
|
52
|
-
cuqi/implicitprior/__init__.py,sha256=
|
|
53
|
-
cuqi/implicitprior/_regularizedGMRF.py,sha256=
|
|
54
|
-
cuqi/implicitprior/_regularizedGaussian.py,sha256=
|
|
53
|
+
cuqi/implicitprior/__init__.py,sha256=CaDQGYtmeFzN37vf3QUmKhcN9-H5lO66ZbK035k4qUw,246
|
|
54
|
+
cuqi/implicitprior/_regularizedGMRF.py,sha256=IR9tKzNMoz-b0RKu6ahVgMx_lDNB3jZHVWFMQm6QqZk,6259
|
|
55
|
+
cuqi/implicitprior/_regularizedGaussian.py,sha256=cQtrgzyJU2pwoK4ORGl1erKLE9VY5NqwZTiqiViDswA,12371
|
|
56
|
+
cuqi/implicitprior/_regularizedUnboundedUniform.py,sha256=H2fTOSqYTlDiLxQ7Ya6wnpCUIkpO4qKrkTOsOPnBBeU,3483
|
|
55
57
|
cuqi/likelihood/__init__.py,sha256=QXif382iwZ5bT3ZUqmMs_n70JVbbjxbqMrlQYbMn4Zo,1776
|
|
56
58
|
cuqi/likelihood/_likelihood.py,sha256=z3AXAbIrv_DjOYh4jy3iDHemuIFUUJu6wdvJ5e2dgW0,6913
|
|
57
59
|
cuqi/model/__init__.py,sha256=IcN4aZCnyp9o-8TNIoZ8vew99QQgi0EmZvnsIuR6qYI,49
|
|
@@ -83,8 +85,8 @@ cuqi/testproblem/_testproblem.py,sha256=x769LwwRdJdzIiZkcQUGb_5-vynNTNALXWKato7s
|
|
|
83
85
|
cuqi/utilities/__init__.py,sha256=T4tLsC215MknBCsw_C0Qeeg_ox26aDUrCA5hbWvNQkU,387
|
|
84
86
|
cuqi/utilities/_get_python_variable_name.py,sha256=QwlBVj2koJRA8s8pWd554p7-ElcI7HUwY32HknaR92E,1827
|
|
85
87
|
cuqi/utilities/_utilities.py,sha256=MWAqV6L5btMpWwlUzrZYuV2VeSpfTbOaLRMRkuw2WIA,8509
|
|
86
|
-
CUQIpy-1.0.0.post0.
|
|
87
|
-
CUQIpy-1.0.0.post0.
|
|
88
|
-
CUQIpy-1.0.0.post0.
|
|
89
|
-
CUQIpy-1.0.0.post0.
|
|
90
|
-
CUQIpy-1.0.0.post0.
|
|
88
|
+
CUQIpy-1.0.0.post0.dev384.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
|
|
89
|
+
CUQIpy-1.0.0.post0.dev384.dist-info/METADATA,sha256=5xT68suvERdJf0DPgCPA23chSdG2yRnQQJhW_zSnjps,18393
|
|
90
|
+
CUQIpy-1.0.0.post0.dev384.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
|
91
|
+
CUQIpy-1.0.0.post0.dev384.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
|
|
92
|
+
CUQIpy-1.0.0.post0.dev384.dist-info/RECORD,,
|
cuqi/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2024-07-
|
|
11
|
+
"date": "2024-07-05T09:29:07+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "1.0.0.post0.
|
|
14
|
+
"full-revisionid": "3e3d762fab019f39257708bb9cdf5abc3681f196",
|
|
15
|
+
"version": "1.0.0.post0.dev384"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
cuqi/distribution/__init__.py
CHANGED
|
@@ -9,6 +9,7 @@ from ._gmrf import GMRF
|
|
|
9
9
|
from ._inverse_gamma import InverseGamma
|
|
10
10
|
from ._lmrf import LMRF
|
|
11
11
|
from ._laplace import Laplace
|
|
12
|
+
from ._smoothed_laplace import SmoothedLaplace
|
|
12
13
|
from ._lognormal import Lognormal
|
|
13
14
|
from ._normal import Normal
|
|
14
15
|
from ._posterior import Posterior
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from cuqi.utilities import force_ndarray
|
|
3
|
+
from cuqi.distribution import Distribution
|
|
4
|
+
|
|
5
|
+
class SmoothedLaplace(Distribution):
|
|
6
|
+
""" Smoothed Laplace distribution.
|
|
7
|
+
|
|
8
|
+
Defines a smoothed Laplace distribution given a location, a scale and a smoothing parameter
|
|
9
|
+
beta. The smoothed Laplace distribution is defined as
|
|
10
|
+
|
|
11
|
+
.. math::
|
|
12
|
+
|
|
13
|
+
p(x) = \\frac{1}{2b} \exp\left(-\\frac{\sqrt{(x-\mu)^2 + \beta}}{b}\\right),
|
|
14
|
+
|
|
15
|
+
where :math:`\mu` is the location (mean), :math:`b` is the scale (decay) parameter and
|
|
16
|
+
:math:`\beta` is the smoothing parameter.
|
|
17
|
+
|
|
18
|
+
The rate parameter is defined as :math:`\lambda = \\frac{1}{b}`.
|
|
19
|
+
|
|
20
|
+
The variables of this Laplace distribution are independent identically distributed (i.i.d.).
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
location : scalar, list, tuple, or ndarray
|
|
25
|
+
The location parameter of the distribution.
|
|
26
|
+
|
|
27
|
+
scale : scalar, list, tuple, or ndarray
|
|
28
|
+
The scale parameter of the distribution.
|
|
29
|
+
|
|
30
|
+
beta : scalar
|
|
31
|
+
The smoothing parameter of the distribution.
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, location=None, scale=None, beta=1e-3, **kwargs):
|
|
36
|
+
super().__init__(**kwargs)
|
|
37
|
+
|
|
38
|
+
self.location = location
|
|
39
|
+
self.scale = scale
|
|
40
|
+
self.beta = beta
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def location(self):
|
|
44
|
+
""" Location parameter """
|
|
45
|
+
return self._location
|
|
46
|
+
|
|
47
|
+
@location.setter
|
|
48
|
+
def location(self, value):
|
|
49
|
+
self._location = force_ndarray(value, flatten=True)
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def scale(self):
|
|
53
|
+
""" Scale parameter """
|
|
54
|
+
return self._scale
|
|
55
|
+
|
|
56
|
+
@scale.setter
|
|
57
|
+
def scale(self, value):
|
|
58
|
+
self._scale = force_ndarray(value, flatten=True)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def beta(self):
|
|
62
|
+
""" Beta parameter """
|
|
63
|
+
return self._beta
|
|
64
|
+
|
|
65
|
+
@beta.setter
|
|
66
|
+
def beta(self, value):
|
|
67
|
+
self._beta = value
|
|
68
|
+
|
|
69
|
+
def logpdf(self, x):
|
|
70
|
+
"""
|
|
71
|
+
Computes the logarithm of the probability density function at the given values of x.
|
|
72
|
+
"""
|
|
73
|
+
# x accepts scalar, list, tuple, or ndarray
|
|
74
|
+
if isinstance(x, (float, int)):
|
|
75
|
+
x = np.array([x])
|
|
76
|
+
elif isinstance(x, (list, tuple)):
|
|
77
|
+
x = np.array(x)
|
|
78
|
+
return np.sum(np.log(0.5 / self.scale)) - np.sum(np.sqrt((x - self.location) ** 2 + self.beta) / self.scale)
|
|
79
|
+
|
|
80
|
+
def gradient(self, x):
|
|
81
|
+
"""
|
|
82
|
+
Computes the gradient of logpdf at the given values of x.
|
|
83
|
+
"""
|
|
84
|
+
# x accepts scalar, list, tuple, or ndarray
|
|
85
|
+
if isinstance(x, (float, int)):
|
|
86
|
+
x = np.array([x])
|
|
87
|
+
elif isinstance(x, (list, tuple)):
|
|
88
|
+
x = np.array(x)
|
|
89
|
+
return -np.array((x - self.location) / self.scale / np.sqrt((x - self.location) ** 2 + self.beta))
|
|
90
|
+
|
|
91
|
+
def _sample(self, N=1, rng=None):
|
|
92
|
+
"""
|
|
93
|
+
Generates random samples from the distribution.
|
|
94
|
+
"""
|
|
95
|
+
raise NotImplementedError(f"sample is not implemented for {self.__class__.__name__}.")
|
cuqi/implicitprior/__init__.py
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
from ._regularizedGaussian import RegularizedGaussian
|
|
2
|
-
from ._regularizedGMRF import RegularizedGMRF
|
|
1
|
+
from ._regularizedGaussian import RegularizedGaussian, ConstrainedGaussian, NonnegativeGaussian
|
|
2
|
+
from ._regularizedGMRF import RegularizedGMRF, ConstrainedGMRF, NonnegativeGMRF
|
|
3
|
+
from ._regularizedUnboundedUniform import RegularizedUnboundedUniform
|
|
@@ -68,3 +68,85 @@ class RegularizedGMRF(RegularizedGaussian):
|
|
|
68
68
|
super(Distribution, self).__init__(**kwargs)
|
|
69
69
|
|
|
70
70
|
self._parse_regularization_input_arguments(proximal, projector, constraint, regularization, args)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ConstrainedGMRF(RegularizedGMRF):
|
|
75
|
+
""" Implicit Constrained GMRF (Gaussian Markov Random Field).
|
|
76
|
+
|
|
77
|
+
Defines a so-called implicit prior based on a GMRF distribution with implicit constraints.
|
|
78
|
+
The constraint can be defined as a preset or in the form of a projector.
|
|
79
|
+
|
|
80
|
+
Precisely one of projector or constraint needs to be provided. Otherwise, an error is raised.
|
|
81
|
+
|
|
82
|
+
Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
|
|
83
|
+
|
|
84
|
+
Alias for :class:`~cuqi.implicitprior.RegularizedGMRF` with only constraints available.
|
|
85
|
+
|
|
86
|
+
For more details on implicit regularized Gaussian see the following paper:
|
|
87
|
+
|
|
88
|
+
[1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
|
|
89
|
+
Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
mean
|
|
94
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
95
|
+
|
|
96
|
+
prec
|
|
97
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
98
|
+
|
|
99
|
+
bc_type
|
|
100
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
101
|
+
|
|
102
|
+
order
|
|
103
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
104
|
+
|
|
105
|
+
projector : callable f(x) or None
|
|
106
|
+
Euclidean projection onto the constraint C, that is, a solver for the optimization problem
|
|
107
|
+
min_(z in C) 0.5||x-z||_2^2.
|
|
108
|
+
|
|
109
|
+
constraint : string or None
|
|
110
|
+
Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
|
|
111
|
+
For "box", the following additional parameters can be passed:
|
|
112
|
+
lower_bound : array_like or None
|
|
113
|
+
Lower bound of box, defaults to zero
|
|
114
|
+
upper_bound : array_like
|
|
115
|
+
Upper bound of box, defaults to one
|
|
116
|
+
|
|
117
|
+
"""
|
|
118
|
+
def __init__(self, mean=None, prec=None, bc_type='zero', order=1, projector=None, constraint=None, **kwargs):
|
|
119
|
+
super().__init__(mean=mean, prec=prec, bc_type=bc_type, order=order, projector=projector, constraint=constraint, **kwargs)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class NonnegativeGMRF(RegularizedGMRF):
|
|
123
|
+
""" Implicit Nonnegative GMRF (Gaussian Markov Random Field).
|
|
124
|
+
|
|
125
|
+
Defines a so-called implicit prior based on a GMRF distribution with implicit nonnegativity constraints.
|
|
126
|
+
|
|
127
|
+
Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
|
|
128
|
+
|
|
129
|
+
Alias for :class:`~cuqi.implicitprior.RegularizedGMRF` with only nonnegativity constraints.
|
|
130
|
+
|
|
131
|
+
For more details on implicit regularized Gaussian see the following paper:
|
|
132
|
+
|
|
133
|
+
[1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
|
|
134
|
+
Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
mean
|
|
139
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
140
|
+
|
|
141
|
+
prec
|
|
142
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
143
|
+
|
|
144
|
+
bc_type
|
|
145
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
146
|
+
|
|
147
|
+
order
|
|
148
|
+
See :class:`~cuqi.distribution.GMRF` for details.
|
|
149
|
+
|
|
150
|
+
"""
|
|
151
|
+
def __init__(self, mean=None, prec=None, bc_type='zero', order=1, **kwargs):
|
|
152
|
+
super().__init__(mean=mean, prec=prec, bc_type=bc_type, order=order, constraint="nonnegativity", **kwargs)
|
|
@@ -234,3 +234,90 @@ class RegularizedGaussian(Distribution):
|
|
|
234
234
|
new_density = new_density.to_likelihood(value)
|
|
235
235
|
|
|
236
236
|
return new_density
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
class ConstrainedGaussian(RegularizedGaussian):
|
|
240
|
+
""" Implicit Constrained Gaussian.
|
|
241
|
+
|
|
242
|
+
Defines a so-called implicit prior based on a Gaussian distribution with implicit constraints.
|
|
243
|
+
The constraint can be defined as a preset or in the form of a projector.
|
|
244
|
+
|
|
245
|
+
Precisely one of projector or constraint needs to be provided. Otherwise, an error is raised.
|
|
246
|
+
|
|
247
|
+
Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
|
|
248
|
+
|
|
249
|
+
Alias for :class:`~cuqi.implicitprior.RegularizedGaussian` with only constraints available.
|
|
250
|
+
|
|
251
|
+
For more details on implicit regularized Gaussian see the following paper:
|
|
252
|
+
|
|
253
|
+
[1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
|
|
254
|
+
Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
|
|
255
|
+
|
|
256
|
+
Parameters
|
|
257
|
+
----------
|
|
258
|
+
mean
|
|
259
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
260
|
+
|
|
261
|
+
cov
|
|
262
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
263
|
+
|
|
264
|
+
prec
|
|
265
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
266
|
+
|
|
267
|
+
sqrtcov
|
|
268
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
269
|
+
|
|
270
|
+
sqrtprec
|
|
271
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
272
|
+
|
|
273
|
+
projector : callable f(x) or None
|
|
274
|
+
Euclidean projection onto the constraint C, that is, a solver for the optimization problem
|
|
275
|
+
min_(z in C) 0.5||x-z||_2^2.
|
|
276
|
+
|
|
277
|
+
constraint : string or None
|
|
278
|
+
Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
|
|
279
|
+
For "box", the following additional parameters can be passed:
|
|
280
|
+
lower_bound : array_like or None
|
|
281
|
+
Lower bound of box, defaults to zero
|
|
282
|
+
upper_bound : array_like
|
|
283
|
+
Upper bound of box, defaults to one
|
|
284
|
+
|
|
285
|
+
"""
|
|
286
|
+
def __init__(self, mean=None, cov=None, prec=None, sqrtcov=None,sqrtprec=None, projector=None, constraint=None, **kwargs):
|
|
287
|
+
super().__init__(mean=mean, cov=cov, prec=prec, sqrtcov=sqrtcov, sqrtprec=sqrtprec, projector=projector, constraint=constraint, **kwargs)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
class NonnegativeGaussian(RegularizedGaussian):
|
|
291
|
+
""" Implicit Nonnegative Gaussian.
|
|
292
|
+
|
|
293
|
+
Defines a so-called implicit prior based on a Gaussian distribution with implicit nonnegativity constraints.
|
|
294
|
+
|
|
295
|
+
Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
|
|
296
|
+
|
|
297
|
+
Alias for :class:`~cuqi.implicitprior.RegularizedGaussian` with only nonnegativity constraints.
|
|
298
|
+
|
|
299
|
+
For more details on implicit regularized Gaussian see the following paper:
|
|
300
|
+
|
|
301
|
+
[1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
|
|
302
|
+
Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
|
|
303
|
+
|
|
304
|
+
Parameters
|
|
305
|
+
----------
|
|
306
|
+
mean
|
|
307
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
308
|
+
|
|
309
|
+
cov
|
|
310
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
311
|
+
|
|
312
|
+
prec
|
|
313
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
314
|
+
|
|
315
|
+
sqrtcov
|
|
316
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
317
|
+
|
|
318
|
+
sqrtprec
|
|
319
|
+
See :class:`~cuqi.distribution.Gaussian` for details.
|
|
320
|
+
|
|
321
|
+
"""
|
|
322
|
+
def __init__(self, mean=None, cov=None, prec=None, sqrtcov=None,sqrtprec=None, **kwargs):
|
|
323
|
+
super().__init__(mean=mean, cov=cov, prec=prec, sqrtcov=sqrtcov, sqrtprec=sqrtprec, constraint="nonnegativity", **kwargs)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from cuqi.implicitprior import RegularizedGaussian
|
|
2
|
+
from cuqi.distribution import Distribution, Gaussian
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class RegularizedUnboundedUniform(RegularizedGaussian):
|
|
8
|
+
""" Implicit Regularized Unbounded Uniform.
|
|
9
|
+
|
|
10
|
+
Defines a so-called implicit prior with implicit regularization on a Gaussian distribution with zero precision.
|
|
11
|
+
The regularization can be defined in the form of a proximal operator or a projector.
|
|
12
|
+
Alternatively, preset constraints and regularization can be used.
|
|
13
|
+
|
|
14
|
+
For regularization of the form f(x), provide a single proximal operator.
|
|
15
|
+
|
|
16
|
+
Can be used as a prior in a posterior which can be sampled with the RegularizedLinearRTO sampler.
|
|
17
|
+
|
|
18
|
+
Alias for :class:`~cuqi.implicitprior.RegularizedGaussian` with zero mean and zero sqrtprec.
|
|
19
|
+
|
|
20
|
+
For more details on implicit regularized Gaussian see the following paper:
|
|
21
|
+
|
|
22
|
+
[1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. "Sparse Bayesian inference with regularized
|
|
23
|
+
Gaussian distributions." Inverse Problems 39.11 (2023): 115004.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
geometry : :class:`~cuqi.geometry.Geometry` or integer
|
|
28
|
+
The geometry of the underlying variable. Defines the dimension of the distribution.
|
|
29
|
+
|
|
30
|
+
proximal : callable f(x, scale) or None
|
|
31
|
+
Euclidean proximal operator f of the regularization function g, that is, a solver for the optimization problem
|
|
32
|
+
min_z 0.5||x-z||_2^2+scale*g(x).
|
|
33
|
+
|
|
34
|
+
projector : callable f(x) or None
|
|
35
|
+
Euclidean projection onto the constraint C, that is, a solver for the optimization problem
|
|
36
|
+
min_(z in C) 0.5||x-z||_2^2.
|
|
37
|
+
|
|
38
|
+
constraint : string or None
|
|
39
|
+
Preset constraints. Can be set to "nonnegativity" and "box". Required for use in Gibbs.
|
|
40
|
+
For "box", the following additional parameters can be passed:
|
|
41
|
+
lower_bound : array_like or None
|
|
42
|
+
Lower bound of box, defaults to zero
|
|
43
|
+
upper_bound : array_like
|
|
44
|
+
Upper bound of box, defaults to one
|
|
45
|
+
|
|
46
|
+
regularization : string or None
|
|
47
|
+
Preset regularization. Can be set to "l1". Required for use in Gibbs in future update.
|
|
48
|
+
For "l1", the following additional parameters can be passed:
|
|
49
|
+
strength : scalar
|
|
50
|
+
Regularization parameter, i.e., strength*||x||_1 , defaults to one
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
def __init__(self, geometry, proximal = None, projector = None, constraint = None, regularization = None, **kwargs):
|
|
54
|
+
|
|
55
|
+
args = {"lower_bound" : kwargs.pop("lower_bound", None),
|
|
56
|
+
"upper_bound" : kwargs.pop("upper_bound", None),
|
|
57
|
+
"strength" : kwargs.pop("strength", None)}
|
|
58
|
+
|
|
59
|
+
# Underlying explicit Gaussian
|
|
60
|
+
# This line throws a warning due trying to applying get_sqrtprec_from_sqrtprec to an all zero matrix
|
|
61
|
+
self._gaussian = Gaussian(mean = np.zeros(geometry.par_dim), sqrtprec = np.zeros((geometry.par_dim,geometry.par_dim)), geometry = geometry, **kwargs)
|
|
62
|
+
|
|
63
|
+
# Init from abstract distribution class
|
|
64
|
+
super(Distribution, self).__init__(**kwargs)
|
|
65
|
+
|
|
66
|
+
self._parse_regularization_input_arguments(proximal, projector, constraint, regularization, args)
|
|
File without changes
|
|
File without changes
|