Exemplo n.º 1
0
def ts_snr(x, y):
    """Maximum SNR attainable via translation and scaling.

    Compute the SNR between `x` and the output of
    :func:`translatescale`(`x`, `y`).

    Parameters
    ----------
    x : ndarray
        Reference array
    y : ndarray
        Comparison array (to be translated and scaled)

    Returns
    -------
    float
        SNR value in dB
    """

    yts = translatescale(x, y)
    return snr(x, yts)
Exemplo n.º 2
0
def sm_snr(x, y):
    """Maximum SNR attainable via subsampling and scaling.

    Compute the SNR between the output of :func:`subsamplematch`(`x`, `y`)
    and `y`.

    Parameters
    ----------
    x : ndarray
        Reference array (to be subsampled and scaled)
    y : ndarray
        Comparison array

    Returns
    -------
    float
        SNR value in dB
    """

    xsm = subsamplematch(x, y)
    return snr(xsm, y)
Exemplo n.º 3
0
def snr(*args, **kwargs):
    warnings.warn("sporco.linalg.snr is deprecated: use sporco.metric.snr",
                  PendingDeprecationWarning)
    return sm.snr(*args, **kwargs)
Exemplo n.º 4
0
opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': True, 'MaxMainIter': 20,
                    'HighMemSolve': True, 'LinSolveCheck': False,
                    'RelStopTol': 2e-3, 'AuxVarObj': False,
                    'AutoRho': {'Enabled': False}})


# Initialise and run AddMaskSim/ConvBPDNGradReg object
opt['GradWeight'] = wgrd
b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, shw, msk, lmbda, mu, opt)
X1 = b.solve()
print("AddMaskSim/ConvBPDNGradReg solve time: %.2fs" %
      b.timer.elapsed('solve'))


# Time CUDA AddMaskSim/ConvBPDNGradReg solve
opt['GradWeight'] = 1.0
t = util.Timer()
with util.ContextTimer(t):
    X2 = cucbpdn.cbpdngrdmsk(D, shw, msk, lmbda, mu, opt)
print("GPU AddMaskSim/ConvBPDNGradReg solve time: %.2fs" % t.elapsed())
print("GPU time improvement factor: %.1f" % (b.timer.elapsed('solve') /
                                             t.elapsed()))


# Compare CPU and GPU solutions
print("CPU solution:  min: %.4e  max: %.4e   l1: %.4e" %
          (X1.min(), X1.max(), np.sum(np.abs(X1))))
print("GPU solution:  min: %.4e  max: %.4e   l1: %.4e" %
          (X2.min(), X2.max(), np.sum(np.abs(X2))))
print("CPU/GPU MSE: %.2e  SNR: %.2f dB" % (sm.mse(X1, X2), sm.snr(X1, X2)))
Exemplo n.º 5
0
    'Verbose': True,
    'gEvalY': False,
    'MaxMainIter': 200,
    'RelStopTol': 5e-4,
    'AutoRho': {
        'Enabled': True
    }
})
b = rpca.RobustPCA(S1, None, opt)
X, Y = b.solve()
"""
Display solve time and low-rank component recovery accuracy.
"""

print("RobustPCA solve time:   %5.2f s" % b.timer.elapsed('solve'))
print("Low-rank component SNR: %5.2f dB" % metric.snr(S0, X))
"""
Display reference, corrupted, and recovered matrices.
"""

fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.imview(S0, fig=fig, cmap=plot.cm.Blues, title='Original matrix')
plot.subplot(1, 3, 2)
plot.imview(S1, fig=fig, cmap=plot.cm.Blues, title='Corrupted matrix')
plot.subplot(1, 3, 3)
plot.imview(X, fig=fig, cmap=plot.cm.Blues, title='Recovered matrix')
fig.show()
"""
Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
"""
Exemplo n.º 6
0
def snr(*args, **kwargs):
    warnings.warn("sporco.linalg.snr is deprecated: please use"\
                  " sporco.metric.snr")
    return sm.snr(*args, **kwargs)
Exemplo n.º 7
0
Set options for the Robust PCA solver, create the solver object, and solve, returning the estimates of the low rank and sparse components ``X`` and ``Y``. Unlike most other SPORCO classes for optimisation problems, :class:`.rpca.RobustPCA` has a meaningful default regularization parameter, as used here.
"""

opt = rpca.RobustPCA.Options({'Verbose': True, 'gEvalY': False,
                              'MaxMainIter': 200, 'RelStopTol': 5e-4,
                              'AutoRho': {'Enabled': True}})
b = rpca.RobustPCA(S1, None, opt)
X, Y = b.solve()


"""
Display solve time and low-rank component recovery accuracy.
"""

print("RobustPCA solve time:   %5.2f s" % b.timer.elapsed('solve'))
print("Low-rank component SNR: %5.2f dB" % metric.snr(S0, X))


"""
Display reference, corrupted, and recovered matrices.
"""

fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.imview(S0, cmap=plot.cm.Blues, title='Original matrix', fig=fig)
plot.subplot(1, 3, 2)
plot.imview(S1, cmap=plot.cm.Blues, title='Corrupted matrix', fig=fig)
plot.subplot(1, 3, 3)
plot.imview(X, cmap=plot.cm.Blues, title='Recovered matrix', fig=fig)
fig.show()
Exemplo n.º 8
0
 def test_02(self):
     N = 16
     x = np.random.randn(N)
     x /= np.sqrt(np.var(x))
     y = x + 1
     assert np.abs(metric.snr(x, y)) < 1e-8