Skip to content

Commit

Permalink
[doc/pds] replace operators in examples from _dev for core operators
Browse files Browse the repository at this point in the history
  • Loading branch information
joanrue committed Apr 4, 2024
1 parent 42507e3 commit ecbc4a4
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/pyxu/opt/solver/pds.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,29 +397,27 @@ class CondatVu(_PrimalDualSplitting):
import matplotlib.pyplot as plt
import numpy as np
import pyxu.operator as pxo
from pyxu.experimental._dev import DownSampling, FirstDerivative
from pyxu.operator import SubSample, PartialDerivative
from pyxu.opt.solver import CV
x = np.repeat(np.asarray([0, 2, 1, 3, 0, 2, 0]), 10)
N = x.size
D = FirstDerivative(size=N, kind="forward")
D.lipschitz = D.estimate_lipschitz()
D = PartialDerivative.finite_difference(dim_shape=(N,), order=(1,))
downsample = DownSampling(size=N, downsampling_factor=3)
downsample = SubSample(N, slice(None, None, 3))
y = downsample(x)
loss = (1 / 2) * pxo.SquaredL2Norm(y.size).argshift(-y)
F = loss * downsample
F.diff_lipschitz = F.estimate_diff_lipschitz()
cv = CV(f=F, g=0.01 * pxo.L1Norm(N), h=0.1 * pxo.L1Norm(N), K=D)
cv = CV(f=F, g=0.01 * pxo.L1Norm(N), h=0.1 * pxo.L1Norm((N)), K=D)
x0, z0 = np.zeros((2, N))
cv.fit(x0=x0, z0=z0)
x_recons = cv.solution()
plt.figure()
plt.stem(x, linefmt="C0-", markerfmt="C0o")
mask_ids = np.where(downsample.downsampling_mask)[0]
mask_ids = np.where(downsample.adjoint(np.ones_like(y)))[0]
markerline, stemlines, baseline = plt.stem(mask_ids, y, linefmt="C3-", markerfmt="C3o")
markerline.set_markerfacecolor("none")
plt.stem(x_recons, linefmt="C1--", markerfmt="C1s")
Expand Down Expand Up @@ -709,29 +707,27 @@ class PD3O(_PrimalDualSplitting):
import matplotlib.pyplot as plt
import numpy as np
import pyxu.operator as pxo
from pyxu.experimental._dev import DownSampling, FirstDerivative
from pyxu.operator import SubSample, PartialDerivative
from pyxu.opt.solver import PD3O
x = np.repeat(np.asarray([0, 2, 1, 3, 0, 2, 0]), 10)
N = x.size
D = FirstDerivative(size=N, kind="forward")
D.lipschitz = D.estimate_lipschitz()
D = PartialDerivative.finite_difference(dim_shape=(N,), order=(1,))
downsample = DownSampling(size=N, downsampling_factor=3)
downsample = SubSample(N, slice(None, None, 3))
y = downsample(x)
loss = (1 / 2) * pxo.SquaredL2Norm(y.size).argshift(-y)
F = loss * downsample
F.diff_lipschitz = F.estimate_diff_lipschitz()
pd3o = PD3O(f=F, g=0.01 * pxo.L1Norm(N), h=0.1 * pxo.L1Norm(N), K=D)
pd3o = PD3O(f=F, g=0.01 * pxo.L1Norm(N), h=0.1 * pxo.L1Norm((N)), K=D)
x0, z0 = np.zeros((2, N))
pd3o.fit(x0=x0, z0=z0)
x_recons = pd3o.solution()
plt.figure()
plt.stem(x, linefmt="C0-", markerfmt="C0o")
mask_ids = np.where(downsample.downsampling_mask)[0]
mask_ids = np.where(downsample.adjoint(np.ones_like(y)))[0]
markerline, stemlines, baseline = plt.stem(mask_ids, y, linefmt="C3-", markerfmt="C3o")
markerline.set_markerfacecolor("none")
plt.stem(x_recons, linefmt="C1--", markerfmt="C1s")
Expand Down

0 comments on commit ecbc4a4

Please sign in to comment.