Example #1
0
def test_make_analysis_compressed_sensing_problem():
    m = 10
    N, n = 30, 20
    l = 15
    numdata = 10

    assert_raises(ValueError, make_analysis_compressed_sensing_problem, m, n, N, l, numdata, "randn", "somethingwrong")
    P = numpy.random.randn(m,n)
    assert_raises(ValueError, make_analysis_compressed_sensing_problem, m+1, n, N, l, numdata, "randn", P)

    measurements, acqumatrix, data, operator, gamma, cosupport = \
        make_analysis_compressed_sensing_problem(m, n, N, l, numdata, "randn", "randn")

    assert_equal(measurements.shape, (m,numdata))
    assert_equal(acqumatrix.shape, (m,n))
    assert_array_equal(measurements, numpy.dot(acqumatrix, data))
    def run(self):
        self.avgerr = dict()
        for solver in self.solvers:
            self.avgerr[solver] = np.zeros(shape=(len(self.deltas), len(self.rhos)))

        for idelta, delta in enumerate(self.deltas):
            for irho, rho in enumerate(self.rhos):
                m = int(round(self.signaldim * delta, 0))  # delta = m/n
                l = self.signaldim - int(round(m * rho, 0))             # rho = (n-l)/m

                #TODO: make operator only once
                measurements, acqumatrix, realdata, operator, realgamma, realcosupport = \
                    gen.make_analysis_compressed_sensing_problem(
                        m, self.signaldim, self.dictdim, l, self.numdata, "randn", "randn")

                for solver in self.solvers:
                    data = solver.solve(measurements, acqumatrix, operator)

                    errors = data - realdata
                    for i in range(errors.shape[1]):
                        errors[:, i] = errors[:, i] / np.linalg.norm(realdata[:, i])
                    self.avgerr[solver][idelta, irho] = np.mean(np.sqrt(sum(errors**2, 0)))
Example #3
0
def tuplewrap_make_analysis_compressed_sensing_problem(tuple_data):
    return gen.make_analysis_compressed_sensing_problem(*tuple_data)
import numpy as np
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_true
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_allclose

from generate import make_analysis_compressed_sensing_problem
from analysisl1min import AnalysisL1Min

m, N, n, l, numdata = 16, 25, 20, 18, 10
#rng = np.random.RandomState(47)

SolverClass = AnalysisL1Min

measurements, acqumatrix, data, operator, gamma, cosupport = make_analysis_compressed_sensing_problem(m,n,N,l, numdata, random_state=47)
tol = 1e-6

algorithms = ["nesta"]

def test_correct_shapes():
    stopvals = [1e-6]
    for algo in algorithms:
        for stopval in stopvals:
            yield subtest_correct_shapes, stopval, algo

def subtest_correct_shapes(stopval, algorithm):
    solver = SolverClass(stopval = stopval, algorithm=algorithm)
    # single vector
    recdata = solver.solve(measurements[:,0], acqumatrix, operator)
    assert_equal(recdata.shape, (n,))