CUQIpy 1.0.0.post0.dev422__py3-none-any.whl → 1.1.0.post0.dev6__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.0.0.post0.dev422
3
+ Version: 1.1.0.post0.dev6
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
@@ -201,8 +201,8 @@ Requires-Python: >=3.8
201
201
  Description-Content-Type: text/markdown
202
202
  License-File: LICENSE
203
203
  Requires-Dist: matplotlib
204
- Requires-Dist: numpy >=1.17.0
205
- Requires-Dist: scipy <1.13
204
+ Requires-Dist: numpy>=1.17.0
205
+ Requires-Dist: scipy<1.13
206
206
  Requires-Dist: arviz
207
207
 
208
208
  <div align="center">
@@ -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=k73TZwcds5LPuY1DG4RWM3rSQaCchiDE2au5GyM6qBw,510
3
+ cuqi/_version.py,sha256=zE26ErwFlMyeJXV4SYNxfd7_W2u419dmfpiKdhmwBf0,508
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
@@ -34,20 +34,20 @@ cuqi/distribution/_posterior.py,sha256=zAfL0GECxekZ2lBt1W6_LN0U_xskMwK4VNce5xAF7
34
34
  cuqi/distribution/_smoothed_laplace.py,sha256=p-1Y23mYA9omwiHGkEuv3T2mwcPAAoNlCr7T8osNkjE,2925
35
35
  cuqi/distribution/_uniform.py,sha256=7xJmCZH_LPhuGkwEDGh-_CTtzcWKrXMOxtTJUFb7Ydo,1607
36
36
  cuqi/experimental/__init__.py,sha256=vhZvyMX6rl8Y0haqCzGLPz6PSUKyu75XMQbeDHqTTrw,83
37
- cuqi/experimental/mcmc/__init__.py,sha256=0Vk_MzfE_9tvqQRgR6_3nkjSe_D3vgFqVM9pFrXN2iQ,581
38
- cuqi/experimental/mcmc/_conjugate.py,sha256=r3cEXFXjNucDUAzj9mq4nZtgc6B3lJM21c77d1tB8gw,9936
39
- cuqi/experimental/mcmc/_conjugate_approx.py,sha256=FLhNN0O6DvohLjmekMA6iVn8yXMEvUGcx1s8w3Wu8cA,3665
40
- cuqi/experimental/mcmc/_cwmh.py,sha256=-TM_S_UtD5ljEfXGEUpYImxNx3JXppIKTSpoWen7kP8,7142
41
- cuqi/experimental/mcmc/_direct.py,sha256=pAtxqoSQGhLdukLi8gcoY2qXJmKluttX5RWOk5fAbOY,786
42
- cuqi/experimental/mcmc/_gibbs.py,sha256=z6YOCiBM1YuZbQHfdmsArR-pT61dsS14F_O4kUxsNYM,10638
43
- cuqi/experimental/mcmc/_hmc.py,sha256=0sZMHtnNFGGtQdzpx-cgqA0xyfvGy7r4K62RH3AQNa4,19285
44
- cuqi/experimental/mcmc/_langevin_algorithm.py,sha256=n6WRQooKuUDjmqF-CtpcSNFDvaHCgLKhWxX-hi7h_ZA,8224
45
- cuqi/experimental/mcmc/_laplace_approximation.py,sha256=VVLOKQWZViT1CZg5RDiycG6trpKdQg94aQCKrAdSl2g,5707
46
- cuqi/experimental/mcmc/_mh.py,sha256=r1RNQLuOaT_WlHvCwS2StsgNAOeTD36z2fOzUtbGhHk,2842
47
- cuqi/experimental/mcmc/_pcn.py,sha256=T4T32mfoii3k6Jfz0qxPQbwdh6wdVOxttiEP7NWaZzg,3386
48
- cuqi/experimental/mcmc/_rto.py,sha256=wzlqm8waT6mB-3RFtMz-PlSUa1Yy3dfUoyKKahTaey4,10086
49
- cuqi/experimental/mcmc/_sampler.py,sha256=4dh9XVALkD3Ro9vkLZkNoFNge7Xv8QRbjh4LB7NY0HI,20073
50
- cuqi/experimental/mcmc/_utilities.py,sha256=qrSq8hvK_G2rSxYYfR5psk4sbTe7098TS5QNu13THeE,528
37
+ cuqi/experimental/mcmc/__init__.py,sha256=8Ce1mHvfbKPe0A5gCDl5Bj4ok8bvbn90LEDvfePfNT4,536
38
+ cuqi/experimental/mcmc/_conjugate.py,sha256=VNPQkGity0mposcqxrx4UIeXm35EvJvZED4p2stffvA,9924
39
+ cuqi/experimental/mcmc/_conjugate_approx.py,sha256=uEnY2ea9su5ivcNagyRAwpQP2gBY98sXU7N0y5hTADo,3653
40
+ cuqi/experimental/mcmc/_cwmh.py,sha256=VoSTfdDbKKLKb5XyOq8xplrrGTK-8IQESdQDZ8PFp2I,7121
41
+ cuqi/experimental/mcmc/_direct.py,sha256=9pQS_2Qk2-ybt6m8WTfPoKetcxQ00WaTRN85-Z0FrBY,777
42
+ cuqi/experimental/mcmc/_gibbs.py,sha256=tMrAy1c_d9G9fOrr8SvuDVCSKjWrYvnI8znPM3GBPqc,10608
43
+ cuqi/experimental/mcmc/_hmc.py,sha256=h63KT0jYq86H541hQzhHHzuLEn7vrRE_2r1o1mTEcZo,19261
44
+ cuqi/experimental/mcmc/_langevin_algorithm.py,sha256=GKC_mlix3si_3J8E6I58ozh3ErB0XPmHMjV7sFyKLEQ,8200
45
+ cuqi/experimental/mcmc/_laplace_approximation.py,sha256=4vRc0h7iLrbs2UrptQN5SDAaAq-RpXlnx569OqHmmuE,5698
46
+ cuqi/experimental/mcmc/_mh.py,sha256=7KpM7RFVDQ13SD3uGStPJAHZdsX5mO_fzJLkXK90YgI,2827
47
+ cuqi/experimental/mcmc/_pcn.py,sha256=wqJBZLuRFSwxihaI53tumAg6AWVuceLMOmXssTetd1A,3374
48
+ cuqi/experimental/mcmc/_rto.py,sha256=P1AV1tgnRMXLatkayb2O-OiE5Cta3S_yA9arSAoBkdw,10071
49
+ cuqi/experimental/mcmc/_sampler.py,sha256=6BRq3cQFG-NjUpHWpLA7EisX0Vjxu4MhpWA6Z1nFpos,20049
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=WYFC-4_VBTW73b2ldsnfGYKvdSiCE8plr89xTSmkadg,46804
53
53
  cuqi/implicitprior/__init__.py,sha256=CaDQGYtmeFzN37vf3QUmKhcN9-H5lO66ZbK035k4qUw,246
@@ -85,8 +85,8 @@ cuqi/testproblem/_testproblem.py,sha256=x769LwwRdJdzIiZkcQUGb_5-vynNTNALXWKato7s
85
85
  cuqi/utilities/__init__.py,sha256=T4tLsC215MknBCsw_C0Qeeg_ox26aDUrCA5hbWvNQkU,387
86
86
  cuqi/utilities/_get_python_variable_name.py,sha256=QwlBVj2koJRA8s8pWd554p7-ElcI7HUwY32HknaR92E,1827
87
87
  cuqi/utilities/_utilities.py,sha256=MWAqV6L5btMpWwlUzrZYuV2VeSpfTbOaLRMRkuw2WIA,8509
88
- CUQIpy-1.0.0.post0.dev422.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
89
- CUQIpy-1.0.0.post0.dev422.dist-info/METADATA,sha256=Jve5Frt45OfhfjKlDOY5s0VTD9V4fRj2xxAFXTj4Q4k,18393
90
- CUQIpy-1.0.0.post0.dev422.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
91
- CUQIpy-1.0.0.post0.dev422.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
92
- CUQIpy-1.0.0.post0.dev422.dist-info/RECORD,,
88
+ CUQIpy-1.1.0.post0.dev6.dist-info/LICENSE,sha256=kJWRPrtRoQoZGXyyvu50Uc91X6_0XRaVfT0YZssicys,10799
89
+ CUQIpy-1.1.0.post0.dev6.dist-info/METADATA,sha256=Tna5gC1RR9I0iPXGIyWFzrZTygQ6wyiMOG7Qxf44LMw,18389
90
+ CUQIpy-1.1.0.post0.dev6.dist-info/WHEEL,sha256=nCVcAvsfA9TDtwGwhYaRrlPhTLV9m-Ga6mdyDtuwK18,91
91
+ CUQIpy-1.1.0.post0.dev6.dist-info/top_level.txt,sha256=AgmgMc6TKfPPqbjV0kvAoCBN334i_Lwwojc7HE3ZwD0,5
92
+ CUQIpy-1.1.0.post0.dev6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.2.0)
2
+ Generator: setuptools (73.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
cuqi/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-07-05T13:16:30+0200",
11
+ "date": "2024-08-20T08:33:58+0200",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "e1833beaad21264a01eea69959efffa942db3f34",
15
- "version": "1.0.0.post0.dev422"
14
+ "full-revisionid": "c829512fd34484d0da1b102565fbe54556dd93a2",
15
+ "version": "1.1.0.post0.dev6"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -1,15 +1,15 @@
1
1
  """ Re-implementation of sampler module in a more object oriented way. """
2
2
 
3
- from ._sampler import SamplerNew, ProposalBasedSamplerNew
4
- from ._langevin_algorithm import ULANew, MALANew
5
- from ._mh import MHNew
6
- from ._pcn import PCNNew
7
- from ._rto import LinearRTONew, RegularizedLinearRTONew
8
- from ._cwmh import CWMHNew
9
- from ._laplace_approximation import UGLANew
10
- from ._hmc import NUTSNew
11
- from ._gibbs import HybridGibbsNew
12
- from ._conjugate import ConjugateNew
13
- from ._conjugate_approx import ConjugateApproxNew
14
- from ._direct import DirectNew
3
+ from ._sampler import Sampler, ProposalBasedSampler
4
+ from ._langevin_algorithm import ULA, MALA
5
+ from ._mh import MH
6
+ from ._pcn import PCN
7
+ from ._rto import LinearRTO, RegularizedLinearRTO
8
+ from ._cwmh import CWMH
9
+ from ._laplace_approximation import UGLA
10
+ from ._hmc import NUTS
11
+ from ._gibbs import HybridGibbs
12
+ from ._conjugate import Conjugate
13
+ from ._conjugate_approx import ConjugateApprox
14
+ from ._direct import Direct
15
15
  from ._utilities import find_valid_samplers
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
  from abc import ABC, abstractmethod
3
3
  import math
4
- from cuqi.experimental.mcmc import SamplerNew
4
+ from cuqi.experimental.mcmc import Sampler
5
5
  from cuqi.distribution import Posterior, Gaussian, Gamma, GMRF
6
6
  from cuqi.implicitprior import RegularizedGaussian, RegularizedGMRF
7
7
  from cuqi.utilities import get_non_default_args
8
8
 
9
- class ConjugateNew(SamplerNew):
9
+ class Conjugate(Sampler):
10
10
  """ Conjugate sampler
11
11
 
12
12
  Sampler for sampling a posterior distribution which is a so-called "conjugate" distribution, i.e., where the likelihood and prior are conjugate to each other - denoted as a conjugate pair.
@@ -34,7 +34,7 @@ class ConjugateNew(SamplerNew):
34
34
  def _initialize(self):
35
35
  pass
36
36
 
37
- @SamplerNew.target.setter # Overwrite the target setter to set the conjugate pair
37
+ @Sampler.target.setter # Overwrite the target setter to set the conjugate pair
38
38
  def target(self, value):
39
39
  """ Set the target density. Runs validation of the target. """
40
40
  self._target = value
@@ -1,10 +1,10 @@
1
1
  import numpy as np
2
- from cuqi.experimental.mcmc import ConjugateNew
2
+ from cuqi.experimental.mcmc import Conjugate
3
3
  from cuqi.experimental.mcmc._conjugate import _ConjugatePair, _get_conjugate_parameter, _check_conjugate_parameter_is_scalar_reciprocal
4
4
  from cuqi.distribution import LMRF, Gamma
5
5
  import scipy as sp
6
6
 
7
- class ConjugateApproxNew(ConjugateNew):
7
+ class ConjugateApprox(Conjugate):
8
8
  """ Approximate Conjugate sampler
9
9
 
10
10
  Sampler for sampling a posterior distribution where the likelihood and prior can be approximated
@@ -17,7 +17,7 @@ class ConjugateApproxNew(ConjugateNew):
17
17
 
18
18
  LMRF likelihood must have zero mean.
19
19
 
20
- For more details on conjugacy see :class:`ConjugateNew`.
20
+ For more details on conjugacy see :class:`Conjugate`.
21
21
 
22
22
  """
23
23
 
@@ -1,10 +1,10 @@
1
1
  import numpy as np
2
2
  import cuqi
3
- from cuqi.experimental.mcmc import ProposalBasedSamplerNew
3
+ from cuqi.experimental.mcmc import ProposalBasedSampler
4
4
  from cuqi.array import CUQIarray
5
5
  from numbers import Number
6
6
 
7
- class CWMHNew(ProposalBasedSamplerNew):
7
+ class CWMH(ProposalBasedSampler):
8
8
  """Component-wise Metropolis Hastings sampler.
9
9
 
10
10
  Allows sampling of a target distribution by a component-wise random-walk
@@ -40,7 +40,7 @@ class CWMHNew(ProposalBasedSamplerNew):
40
40
 
41
41
  kwargs : dict
42
42
  Additional keyword arguments to be passed to the base class
43
- :class:`ProposalBasedSamplerNew`.
43
+ :class:`ProposalBasedSampler`.
44
44
 
45
45
  Example
46
46
  -------
@@ -61,14 +61,14 @@ class CWMHNew(ProposalBasedSamplerNew):
61
61
  dim=dim, logpdf_func=logpdf_func)
62
62
 
63
63
  # Set up sampler
64
- sampler = cuqi.experimental.mcmc.CWMHNew(target, scale=1)
64
+ sampler = cuqi.experimental.mcmc.CWMH(target, scale=1)
65
65
 
66
66
  # Sample
67
67
  samples = sampler.sample(2000).get_samples()
68
68
 
69
69
  """
70
70
 
71
- _STATE_KEYS = ProposalBasedSamplerNew._STATE_KEYS.union(['_scale_temp'])
71
+ _STATE_KEYS = ProposalBasedSampler._STATE_KEYS.union(['_scale_temp'])
72
72
 
73
73
  def __init__(self, target:cuqi.density.Density=None, proposal=None, scale=1,
74
74
  initial_point=None, **kwargs):
@@ -78,7 +78,7 @@ class CWMHNew(ProposalBasedSamplerNew):
78
78
  def _initialize(self):
79
79
  if isinstance(self.scale, Number):
80
80
  self.scale = np.ones(self.dim)*self.scale
81
- self._acc = [np.ones((self.dim))] # Overwrite acc from ProposalBasedSamplerNew with list of arrays
81
+ self._acc = [np.ones((self.dim))] # Overwrite acc from ProposalBasedSampler with list of arrays
82
82
 
83
83
  # Handling of temporary scale parameter due to possible bug in old CWMH
84
84
  self._scale_temp = self.scale.copy()
@@ -1,6 +1,6 @@
1
- from cuqi.experimental.mcmc import SamplerNew
1
+ from cuqi.experimental.mcmc import Sampler
2
2
 
3
- class DirectNew(SamplerNew):
3
+ class Direct(Sampler):
4
4
  """ Direct sampler
5
5
 
6
6
  This sampler is used to sample from a target distribution directly. It simply calls the sample method of the target object to generate a sample.
@@ -1,5 +1,5 @@
1
1
  from cuqi.distribution import JointDistribution
2
- from cuqi.experimental.mcmc import SamplerNew
2
+ from cuqi.experimental.mcmc import Sampler
3
3
  from cuqi.samples import Samples
4
4
  from typing import Dict
5
5
  import numpy as np
@@ -12,9 +12,9 @@ except ImportError:
12
12
  warnings.warn("Module mcmc: Progressbar not found. Install progressbar2 to get sampling progress.")
13
13
  return iterable
14
14
 
15
- # Not subclassed from SamplerNew as Gibbs handles multiple samplers and samples multiple parameters
15
+ # Not subclassed from Sampler as Gibbs handles multiple samplers and samples multiple parameters
16
16
  # Similar approach as for JointDistribution
17
- class HybridGibbsNew:
17
+ class HybridGibbs:
18
18
  """
19
19
  Hybrid Gibbs sampler for sampling a joint distribution.
20
20
 
@@ -80,13 +80,13 @@ class HybridGibbsNew:
80
80
 
81
81
  # Define sampling strategy
82
82
  sampling_strategy = {
83
- 'x': cuqi.experimental.mcmc.LinearRTONew(maxit=15),
84
- 'd': cuqi.experimental.mcmc.ConjugateNew(),
85
- 'l': cuqi.experimental.mcmc.ConjugateNew(),
83
+ 'x': cuqi.experimental.mcmc.LinearRTO(maxit=15),
84
+ 'd': cuqi.experimental.mcmc.Conjugate(),
85
+ 'l': cuqi.experimental.mcmc.Conjugate(),
86
86
  }
87
87
 
88
88
  # Define Gibbs sampler
89
- sampler = cuqi.experimental.mcmc.HybridGibbsNew(posterior, sampling_strategy)
89
+ sampler = cuqi.experimental.mcmc.HybridGibbs(posterior, sampling_strategy)
90
90
 
91
91
  # Run sampler
92
92
  samples = sampler.sample(Ns=1000, Nb=200)
@@ -98,7 +98,7 @@ class HybridGibbsNew:
98
98
 
99
99
  """
100
100
 
101
- def __init__(self, target: JointDistribution, sampling_strategy: Dict[str, SamplerNew], num_sampling_steps: Dict[str, int] = None):
101
+ def __init__(self, target: JointDistribution, sampling_strategy: Dict[str, Sampler], num_sampling_steps: Dict[str, int] = None):
102
102
 
103
103
  # Store target and allow conditioning to reduce to a single density
104
104
  self.target = target() # Create a copy of target distribution (to avoid modifying the original)
@@ -150,13 +150,13 @@ class HybridGibbsNew:
150
150
  for sampler in self.samplers.values():
151
151
  sampler.validate_target()
152
152
 
153
- def sample(self, Ns) -> 'HybridGibbsNew':
153
+ def sample(self, Ns) -> 'HybridGibbs':
154
154
  """ Sample from the joint distribution using Gibbs sampling """
155
155
  for _ in progressbar(range(Ns)):
156
156
  self.step()
157
157
  self._store_samples()
158
158
 
159
- def warmup(self, Nb) -> 'HybridGibbsNew':
159
+ def warmup(self, Nb) -> 'HybridGibbs':
160
160
  """ Warmup (tune) the Gibbs sampler """
161
161
  for idx in progressbar(range(Nb)):
162
162
  self.step()
@@ -1,10 +1,10 @@
1
1
  import numpy as np
2
2
  import numpy as np
3
- from cuqi.experimental.mcmc import SamplerNew
3
+ from cuqi.experimental.mcmc import Sampler
4
4
  from cuqi.array import CUQIarray
5
5
  from numbers import Number
6
6
 
7
- class NUTSNew(SamplerNew):
7
+ class NUTS(Sampler):
8
8
  """No-U-Turn Sampler (Hoffman and Gelman, 2014).
9
9
 
10
10
  Samples a distribution given its logpdf and gradient using a Hamiltonian
@@ -58,7 +58,7 @@ class NUTSNew(SamplerNew):
58
58
  target = tp.posterior
59
59
 
60
60
  # Set up sampler
61
- sampler = cuqi.experimental.mcmc.NUTSNew(target)
61
+ sampler = cuqi.experimental.mcmc.NUTS(target)
62
62
 
63
63
  # Sample
64
64
  sampler.warmup(5000)
@@ -87,11 +87,11 @@ class NUTSNew(SamplerNew):
87
87
 
88
88
  """
89
89
 
90
- _STATE_KEYS = SamplerNew._STATE_KEYS.union({'_epsilon', '_epsilon_bar',
90
+ _STATE_KEYS = Sampler._STATE_KEYS.union({'_epsilon', '_epsilon_bar',
91
91
  '_H_bar', '_mu',
92
92
  '_alpha', '_n_alpha'})
93
93
 
94
- _HISTORY_KEYS = SamplerNew._HISTORY_KEYS.union({'num_tree_node_list',
94
+ _HISTORY_KEYS = Sampler._HISTORY_KEYS.union({'num_tree_node_list',
95
95
  'epsilon_list',
96
96
  'epsilon_bar_list'})
97
97
 
@@ -120,7 +120,7 @@ class NUTSNew(SamplerNew):
120
120
  def _initialize(self):
121
121
 
122
122
  # Arrays to store acceptance rate
123
- self._acc = [None] # Overwrites acc from SamplerNew. TODO. Check if this is necessary
123
+ self._acc = [None] # Overwrites acc from Sampler. TODO. Check if this is necessary
124
124
 
125
125
  self._alpha = 0 # check if meaningful value
126
126
  self._n_alpha = 0 # check if meaningful value
@@ -188,7 +188,7 @@ class NUTSNew(SamplerNew):
188
188
  self._opt_acc_rate = value
189
189
 
190
190
  #=========================================================================
191
- #================== Implement methods required by SamplerNew =============
191
+ #================== Implement methods required by Sampler =============
192
192
  #=========================================================================
193
193
  def validate_target(self):
194
194
  # Check if the target has logd and gradient methods
@@ -1,9 +1,9 @@
1
1
  import numpy as np
2
2
  import cuqi
3
- from cuqi.experimental.mcmc import SamplerNew
3
+ from cuqi.experimental.mcmc import Sampler
4
4
  from cuqi.array import CUQIarray
5
5
 
6
- class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
6
+ class ULA(Sampler): # Refactor to Proposal-based sampler?
7
7
  """Unadjusted Langevin algorithm (ULA) (Roberts and Tweedie, 1996)
8
8
 
9
9
  Samples a distribution given its logpdf and gradient (up to a constant) based on
@@ -52,7 +52,7 @@ class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
52
52
  gradient_func=gradient_func)
53
53
 
54
54
  # Set up sampler
55
- sampler = cuqi.experimental.mcmc.ULANew(target, scale=1/dim**2)
55
+ sampler = cuqi.experimental.mcmc.ULA(target, scale=1/dim**2)
56
56
 
57
57
  # Sample
58
58
  sampler.sample(2000)
@@ -61,7 +61,7 @@ class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
61
61
  # TODO: update demo once sampler merged
62
62
  """
63
63
 
64
- _STATE_KEYS = SamplerNew._STATE_KEYS.union({'current_target_logd', 'scale', 'current_target_grad'})
64
+ _STATE_KEYS = Sampler._STATE_KEYS.union({'current_target_logd', 'scale', 'current_target_grad'})
65
65
 
66
66
  def __init__(self, target=None, scale=1.0, **kwargs):
67
67
 
@@ -125,7 +125,7 @@ class ULANew(SamplerNew): # Refactor to Proposal-based sampler?
125
125
  pass
126
126
 
127
127
 
128
- class MALANew(ULANew): # Refactor to Proposal-based sampler?
128
+ class MALA(ULA): # Refactor to Proposal-based sampler?
129
129
  """ Metropolis-adjusted Langevin algorithm (MALA) (Roberts and Tweedie, 1996)
130
130
 
131
131
  Samples a distribution given its logd and gradient (up to a constant) based on
@@ -174,7 +174,7 @@ class MALANew(ULANew): # Refactor to Proposal-based sampler?
174
174
  gradient_func=gradient_func)
175
175
 
176
176
  # Set up sampler
177
- sampler = cuqi.experimental.mcmc.MALANew(target, scale=1/5**2)
177
+ sampler = cuqi.experimental.mcmc.MALA(target, scale=1/5**2)
178
178
 
179
179
  # Sample
180
180
  sampler.sample(2000)
@@ -2,9 +2,9 @@ import scipy as sp
2
2
  import numpy as np
3
3
  import cuqi
4
4
  from cuqi.solver import CGLS
5
- from cuqi.experimental.mcmc import SamplerNew
5
+ from cuqi.experimental.mcmc import Sampler
6
6
 
7
- class UGLANew(SamplerNew):
7
+ class UGLA(Sampler):
8
8
  """ Unadjusted (Gaussian) Laplace Approximation sampler
9
9
 
10
10
  Samples an approximate posterior where the prior is approximated
@@ -1,9 +1,9 @@
1
1
  import numpy as np
2
2
  import cuqi
3
- from cuqi.experimental.mcmc import ProposalBasedSamplerNew
3
+ from cuqi.experimental.mcmc import ProposalBasedSampler
4
4
 
5
5
 
6
- class MHNew(ProposalBasedSamplerNew):
6
+ class MH(ProposalBasedSampler):
7
7
  """ Metropolis-Hastings (MH) sampler.
8
8
 
9
9
  Parameters
@@ -18,11 +18,11 @@ class MHNew(ProposalBasedSamplerNew):
18
18
  Scaling parameter for the proposal distribution.
19
19
 
20
20
  kwargs : dict
21
- Additional keyword arguments to be passed to the base class :class:`ProposalBasedSamplerNew`.
21
+ Additional keyword arguments to be passed to the base class :class:`ProposalBasedSampler`.
22
22
 
23
23
  """
24
24
 
25
- _STATE_KEYS = ProposalBasedSamplerNew._STATE_KEYS.union({'scale', '_scale_temp'})
25
+ _STATE_KEYS = ProposalBasedSampler._STATE_KEYS.union({'scale', '_scale_temp'})
26
26
 
27
27
  def __init__(self, target=None, proposal=None, scale=1, **kwargs):
28
28
  super().__init__(target, proposal=proposal, scale=scale, **kwargs)
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
2
  import cuqi
3
- from cuqi.experimental.mcmc import SamplerNew
3
+ from cuqi.experimental.mcmc import Sampler
4
4
  from cuqi.array import CUQIarray
5
5
 
6
- class PCNNew(SamplerNew): # Refactor to Proposal-based sampler?
6
+ class PCN(Sampler): # Refactor to Proposal-based sampler?
7
7
 
8
- _STATE_KEYS = SamplerNew._STATE_KEYS.union({'scale', 'current_likelihood_logd', 'lambd'})
8
+ _STATE_KEYS = Sampler._STATE_KEYS.union({'scale', 'current_likelihood_logd', 'lambd'})
9
9
 
10
10
  def __init__(self, target=None, scale=1.0, **kwargs):
11
11
 
@@ -4,10 +4,10 @@ from scipy.sparse.linalg import LinearOperator as scipyLinearOperator
4
4
  import numpy as np
5
5
  import cuqi
6
6
  from cuqi.solver import CGLS, FISTA
7
- from cuqi.experimental.mcmc import SamplerNew
7
+ from cuqi.experimental.mcmc import Sampler
8
8
 
9
9
 
10
- class LinearRTONew(SamplerNew):
10
+ class LinearRTO(Sampler):
11
11
  """
12
12
  Linear RTO (Randomize-Then-Optimize) sampler.
13
13
 
@@ -155,7 +155,7 @@ class LinearRTONew(SamplerNew):
155
155
  """ Get the default initial point for the sampler. Defaults to an array of zeros. """
156
156
  return np.zeros(self.dim)
157
157
 
158
- class RegularizedLinearRTONew(LinearRTONew):
158
+ class RegularizedLinearRTO(LinearRTO):
159
159
  """
160
160
  Regularized Linear RTO (Randomize-Then-Optimize) sampler.
161
161
 
@@ -13,7 +13,7 @@ except ImportError:
13
13
  warnings.warn("Module mcmc: Progressbar not found. Install progressbar2 to get sampling progress.")
14
14
  return iterable
15
15
 
16
- class SamplerNew(ABC):
16
+ class Sampler(ABC):
17
17
  """ Abstract base class for all samplers.
18
18
 
19
19
  Provides a common interface for all samplers. The interface includes methods for sampling, warmup and getting the samples in an object oriented way.
@@ -194,7 +194,7 @@ class SamplerNew(ABC):
194
194
 
195
195
  self.set_state(state)
196
196
 
197
- def sample(self, Ns, batch_size=0, sample_path='./CUQI_samples/') -> 'SamplerNew':
197
+ def sample(self, Ns, batch_size=0, sample_path='./CUQI_samples/') -> 'Sampler':
198
198
  """ Sample Ns samples from the target density.
199
199
 
200
200
  Parameters
@@ -239,7 +239,7 @@ class SamplerNew(ABC):
239
239
  return self
240
240
 
241
241
 
242
- def warmup(self, Nb, tune_freq=0.1) -> 'SamplerNew':
242
+ def warmup(self, Nb, tune_freq=0.1) -> 'Sampler':
243
243
  """ Warmup the sampler by drawing Nb samples.
244
244
 
245
245
  Parameters
@@ -407,10 +407,10 @@ class SamplerNew(ABC):
407
407
  msg += f"\t {key}: {value} \n"
408
408
  return msg
409
409
 
410
- class ProposalBasedSamplerNew(SamplerNew, ABC):
410
+ class ProposalBasedSampler(Sampler, ABC):
411
411
  """ Abstract base class for samplers that use a proposal distribution. """
412
412
 
413
- _STATE_KEYS = SamplerNew._STATE_KEYS.union({'current_target_logd', 'scale'})
413
+ _STATE_KEYS = Sampler._STATE_KEYS.union({'current_target_logd', 'scale'})
414
414
 
415
415
  def __init__(self, target=None, proposal=None, scale=1, **kwargs):
416
416
  """ Initializer for abstract base class for samplers that use a proposal distribution.
@@ -419,7 +419,7 @@ class ProposalBasedSamplerNew(SamplerNew, ABC):
419
419
 
420
420
  Initialization of the sampler should be done in the _initialize method.
421
421
 
422
- See :class:`SamplerNew` for additional details.
422
+ See :class:`Sampler` for additional details.
423
423
 
424
424
  Parameters
425
425
  ----------
@@ -433,7 +433,7 @@ class ProposalBasedSamplerNew(SamplerNew, ABC):
433
433
  The scale parameter for the proposal distribution.
434
434
 
435
435
  **kwargs : dict
436
- Additional keyword arguments passed to the :class:`SamplerNew` initializer.
436
+ Additional keyword arguments passed to the :class:`Sampler` initializer.
437
437
 
438
438
  """
439
439
 
@@ -4,7 +4,7 @@ import inspect
4
4
  def find_valid_samplers(target):
5
5
  """ Finds all samplers in the cuqi.experimental.mcmc module that accept the provided target. """
6
6
 
7
- all_samplers = [(name, cls) for name, cls in inspect.getmembers(cuqi.experimental.mcmc, inspect.isclass) if issubclass(cls, cuqi.experimental.mcmc.SamplerNew)]
7
+ all_samplers = [(name, cls) for name, cls in inspect.getmembers(cuqi.experimental.mcmc, inspect.isclass) if issubclass(cls, cuqi.experimental.mcmc.Sampler)]
8
8
  valid_samplers = []
9
9
 
10
10
  for name, sampler in all_samplers: