import logging
import matplotlib.pyplot as plt

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-20s :: %(message)s'
)

grid = UniformGrid(np.linspace(0, 2*np.pi, 200))
op = Volterra(grid)

exact_solution = np.sin(grid.coords[0])
exact_data = op(exact_solution)
noise = 0.03 * op.domain.randn()
data = exact_data + noise
init = grid.zeros()

setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=L2)

# Run the solver with a `-1 <= reco <= 1` constraint. For illustration, you can also try a
# constraint which is violated by the exact solution.
newton = NewtonSemiSmooth(setting, data, init, alpha=0.1, psi_minus=-1, psi_plus=1)
stoprule = (
    rules.CountIterations(1000) +
    rules.Discrepancy(
        setting.Hcodomain.norm, data,
        noiselevel=setting.Hcodomain.norm(noise),
        tau=1.1
    )
)
Exemple #2
0
from regpy.discrs import UniformGrid
from regpy.hilbert import L2

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-40s :: %(message)s')

# TODO dtype=complex?
grid = UniformGrid((-1, 1, 100), (-1, 1, 100))

sobolev_index = 30
noiselevel = 0.05

# In real applications with data known before constructing the operator, estimate_sampling_pattern
# can be used to determine the mask.
mask = grid.zeros(dtype=bool)
mask[::2] = True
mask[:10] = True
mask[-10:] = True

full_mri_op = parallel_mri(grid=grid, ncoils=10)
sampling = cartesian_sampling(full_mri_op.codomain, mask=mask)
mri_op = sampling * full_mri_op

# Substitute Sobolev weights into coil profiles
smoother = sobolev_smoother(mri_op.domain, sobolev_index)
smoothed_op = mri_op * smoother

exact_solution = mri_op.domain.zeros()
exact_density, exact_coils = mri_op.domain.split(
    exact_solution)  # returns views into exact_solution in this case