.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/0100_lop/cs_operators.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_0100_lop_cs_operators.py: .. _gallery:lop:cs_operators: Compressive Sensing Operators =============================================== .. contents:: :depth: 2 :local: .. GENERATED FROM PYTHON SOURCE LINES 14-15 Let's import necessary libraries .. GENERATED FROM PYTHON SOURCE LINES 15-29 .. code-block:: default import jax.numpy as jnp # Random numbers from jax import random # For plotting diagrams import matplotlib.pyplot as plt ## CR-Sparse modules import cr.nimble as cnb # Linear operators from cr.sparse import lop # Some random number seeds key = random.PRNGKey(0) keys = random.split(key, 10) .. GENERATED FROM PYTHON SOURCE LINES 30-33 Rademacher sensing operators ----------------------------------------------------------------- Size of the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 33-34 .. code-block:: default m, n = 4, 8 .. GENERATED FROM PYTHON SOURCE LINES 35-38 Unnormalized atoms / columns ''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 38-39 .. code-block:: default Phi = lop.rademacher_dict(keys[0], m, n, normalize_atoms=False) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 41-42 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-1. 1. -1. -1. 1. -1. -1. 1.] [ 1. -1. -1. -1. 1. -1. 1. 1.] [-1. -1. -1. -1. -1. 1. -1. -1.] [ 1. -1. -1. 1. 1. -1. 1. -1.]] .. GENERATED FROM PYTHON SOURCE LINES 43-44 Let's print the contents of the adjoint matrix .. GENERATED FROM PYTHON SOURCE LINES 44-45 .. code-block:: default print(lop.to_adjoint_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-1. 1. -1. 1.] [ 1. -1. -1. -1.] [-1. -1. -1. -1.] [-1. -1. -1. 1.] [ 1. 1. -1. 1.] [-1. -1. 1. -1.] [-1. 1. -1. 1.] [ 1. 1. -1. -1.]] .. GENERATED FROM PYTHON SOURCE LINES 46-47 Let's apply the forward operator .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: default x = jnp.array([3, -2, 4, 8, 2, 2, 6, -1]) y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [-24 -2 -18 16] .. GENERATED FROM PYTHON SOURCE LINES 51-52 Let's apply the adjoint operator .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 56 -20 28 60 8 -8 56 -24] .. GENERATED FROM PYTHON SOURCE LINES 55-56 Let's JIT compile the trans and times functions .. GENERATED FROM PYTHON SOURCE LINES 56-57 .. code-block:: default Phi = lop.jit(Phi) .. GENERATED FROM PYTHON SOURCE LINES 58-59 Let's verify the forward operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: default x = jnp.array([3, -2, 4, 8, 2, 2, 6, -1]) y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [-24 -2 -18 16] .. GENERATED FROM PYTHON SOURCE LINES 63-64 Let's verify the adjoint operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 56 -20 28 60 8 -8 56 -24] .. GENERATED FROM PYTHON SOURCE LINES 68-71 Normalized atoms / columns ''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 71-72 .. code-block:: default Phi = lop.rademacher_dict(keys[0], m, n, normalize_atoms=True) .. GENERATED FROM PYTHON SOURCE LINES 73-74 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 74-75 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.5 0.5 -0.5 -0.5 0.5 -0.5 -0.5 0.5] [ 0.5 -0.5 -0.5 -0.5 0.5 -0.5 0.5 0.5] [-0.5 -0.5 -0.5 -0.5 -0.5 0.5 -0.5 -0.5] [ 0.5 -0.5 -0.5 0.5 0.5 -0.5 0.5 -0.5]] .. GENERATED FROM PYTHON SOURCE LINES 76-77 Check the column wise norms .. GENERATED FROM PYTHON SOURCE LINES 77-78 .. code-block:: default print(cnb.norms_l2_cw(lop.to_matrix(Phi))) .. rst-class:: sphx-glr-script-out .. code-block:: none [1. 1. 1. 1. 1. 1. 1. 1.] .. GENERATED FROM PYTHON SOURCE LINES 79-80 Let's print the contents of the adjoint matrix .. GENERATED FROM PYTHON SOURCE LINES 80-81 .. code-block:: default print(lop.to_adjoint_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.5 0.5 -0.5 0.5] [ 0.5 -0.5 -0.5 -0.5] [-0.5 -0.5 -0.5 -0.5] [-0.5 -0.5 -0.5 0.5] [ 0.5 0.5 -0.5 0.5] [-0.5 -0.5 0.5 -0.5] [-0.5 0.5 -0.5 0.5] [ 0.5 0.5 -0.5 -0.5]] .. GENERATED FROM PYTHON SOURCE LINES 82-83 Let's apply the forward operator .. GENERATED FROM PYTHON SOURCE LINES 83-86 .. code-block:: default x = jnp.array([3, -2, 4, 8, 2, 2, 6, -1]) y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [-12. -1. -9. 8.] .. GENERATED FROM PYTHON SOURCE LINES 87-88 Let's apply the adjoint operator .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [14. -5. 7. 15. 2. -2. 14. -6.] .. GENERATED FROM PYTHON SOURCE LINES 91-92 Let's JIT compile the trans and times functions .. GENERATED FROM PYTHON SOURCE LINES 92-93 .. code-block:: default Phi = lop.jit(Phi) .. GENERATED FROM PYTHON SOURCE LINES 94-95 Let's verify the forward operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: default y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [-12. -1. -9. 8.] .. GENERATED FROM PYTHON SOURCE LINES 98-99 Let's verify the adjoint operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 99-101 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [14. -5. 7. 15. 2. -2. 14. -6.] .. GENERATED FROM PYTHON SOURCE LINES 102-105 Column wise application on input ''''''''''''''''''''''''''''''''''''''' Number of signals .. GENERATED FROM PYTHON SOURCE LINES 105-106 .. code-block:: default k = 5 .. GENERATED FROM PYTHON SOURCE LINES 107-108 Prepare a signal matrix .. GENERATED FROM PYTHON SOURCE LINES 108-110 .. code-block:: default X = random.randint(keys[1], (n, k), -5, 5) print(X) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-4 -5 -2 -4 2] [ 0 2 -2 1 3] [ 2 -2 4 -4 -2] [ 2 4 -5 1 -1] [ 2 -5 -2 -2 -4] [-4 2 -3 -1 -4] [-1 -1 -1 4 1] [-3 -4 -1 -4 1]] .. GENERATED FROM PYTHON SOURCE LINES 111-112 Let's apply the forward operator column wise .. GENERATED FROM PYTHON SOURCE LINES 112-114 .. code-block:: default Y = Phi.times(X) print(Y) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 2. -2.5 1. -0.5 2. ] [ -3. -10.5 0. -1.5 2. ] [ -1. 6.5 3. 3.5 -2. ] [ 2. -2.5 -4. 3.5 0. ]] .. GENERATED FROM PYTHON SOURCE LINES 115-116 Let's apply the adjoint operator column wise .. GENERATED FROM PYTHON SOURCE LINES 116-119 .. code-block:: default Z = Phi.trans(Y) print(Z) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ -1. -8.5 -4. -0.5 1. ] [ 2. 2. 1. -3. 1. ] [ 0. 4.5 0. -2.5 -1. ] [ 2. 2. -4. 1. -1. ] [ 1. -11. -3. -1. 3. ] [ -1. 11. 3. 1. -3. ] [ -1. -8.5 -4. -0.5 1. ] [ -1. -8.5 1. -4.5 3. ]] .. GENERATED FROM PYTHON SOURCE LINES 120-123 Row wise application on input ''''''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 123-124 .. code-block:: default Phi = lop.rademacher_dict(keys[0], m, n, normalize_atoms=True, axis=1) .. GENERATED FROM PYTHON SOURCE LINES 125-126 Prepare a signal matrix with each signal along a row .. GENERATED FROM PYTHON SOURCE LINES 126-127 .. code-block:: default XT = X.T .. GENERATED FROM PYTHON SOURCE LINES 128-129 Let's apply the forward operator column wise .. GENERATED FROM PYTHON SOURCE LINES 129-131 .. code-block:: default Y = Phi.times(XT) print(Y) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 2. -3. -1. 2. ] [ -2.5 -10.5 6.5 -2.5] [ 1. 0. 3. -4. ] [ -0.5 -1.5 3.5 3.5] [ 2. 2. -2. 0. ]] .. GENERATED FROM PYTHON SOURCE LINES 132-133 Let's apply the adjoint operator column wise .. GENERATED FROM PYTHON SOURCE LINES 133-136 .. code-block:: default Z = Phi.trans(Y) print(Z) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ -1. 2. 0. 2. 1. -1. -1. -1. ] [ -8.5 2. 4.5 2. -11. 11. -8.5 -8.5] [ -4. 1. 0. -4. -3. 3. -4. 1. ] [ -0.5 -3. -2.5 1. -1. 1. -0.5 -4.5] [ 1. 1. -1. -1. 3. -3. 1. 3. ]] .. GENERATED FROM PYTHON SOURCE LINES 137-140 Square sensing matrix ''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 140-141 .. code-block:: default Phi = lop.rademacher_dict(keys[0], n, normalize_atoms=False) .. GENERATED FROM PYTHON SOURCE LINES 142-143 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 143-146 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 1. 1. -1. -1. -1. -1. 1. 1.] [-1. 1. 1. 1. -1. -1. -1. -1.] [-1. -1. 1. 1. 1. -1. 1. -1.] [ 1. -1. 1. -1. 1. 1. 1. -1.] [-1. 1. -1. 1. 1. 1. -1. -1.] [-1. 1. -1. 1. 1. -1. 1. 1.] [ 1. -1. 1. -1. -1. -1. -1. 1.] [-1. -1. 1. -1. 1. -1. 1. -1.]] .. GENERATED FROM PYTHON SOURCE LINES 147-149 Gaussian sensing operators ----------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 151-154 Unnormalized atoms / columns ''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 154-155 .. code-block:: default Phi = lop.gaussian_dict(keys[0], m, n, normalize_atoms=False) .. GENERATED FROM PYTHON SOURCE LINES 156-157 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 157-158 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.76261741 -0.54906996 0.35375743 0.44785326 0.20306852 0.4002937 -0.10082346 -1.38919403] [ 0.68214811 -0.73785154 -0.31989581 -0.37379108 0.02430423 0.60747778 0.24837508 0.39562076] [ 0.08833386 0.49151262 -0.45341975 -0.63881669 -0.23097626 0.10892717 -0.75912382 0.09899961] [-0.97121466 0.38958316 -0.38142231 1.05170598 -0.59028129 -0.18775354 -0.78933777 0.06830431]] .. GENERATED FROM PYTHON SOURCE LINES 159-160 Let's print the contents of the adjoint matrix .. GENERATED FROM PYTHON SOURCE LINES 160-161 .. code-block:: default print(lop.to_adjoint_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.76261741 0.68214811 0.08833386 -0.97121466] [-0.54906996 -0.73785154 0.49151262 0.38958316] [ 0.35375743 -0.31989581 -0.45341975 -0.38142231] [ 0.44785326 -0.37379108 -0.63881669 1.05170598] [ 0.20306852 0.02430423 -0.23097626 -0.59028129] [ 0.4002937 0.60747778 0.10892717 -0.18775354] [-0.10082346 0.24837508 -0.75912382 -0.78933777] [-1.38919403 0.39562076 0.09899961 0.06830431]] .. GENERATED FROM PYTHON SOURCE LINES 162-163 Let's apply the forward operator .. GENERATED FROM PYTHON SOURCE LINES 163-166 .. code-block:: default x = jnp.array([3, -2, 4, 8, 2, 2, 6, -1]) y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 5.79912122 1.61042927 -12.54007687 -3.16525231] .. GENERATED FROM PYTHON SOURCE LINES 167-168 Let's apply the adjoint operator .. GENERATED FROM PYTHON SOURCE LINES 168-170 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [ -1.3575335 -11.76911601 8.42952898 6.67708692 5.98160846 2.52798389 11.83322722 -8.87664847] .. GENERATED FROM PYTHON SOURCE LINES 171-172 Let's JIT compile the trans and times functions .. GENERATED FROM PYTHON SOURCE LINES 172-173 .. code-block:: default Phi = lop.jit(Phi) .. GENERATED FROM PYTHON SOURCE LINES 174-175 Let's verify the forward operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 175-178 .. code-block:: default x = jnp.array([3, -2, 4, 8, 2, 2, 6, -1]) y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 5.79912122 1.61042927 -12.54007687 -3.16525231] .. GENERATED FROM PYTHON SOURCE LINES 179-180 Let's verify the adjoint operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 180-183 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [ -1.3575335 -11.76911601 8.42952898 6.67708692 5.98160846 2.52798389 11.83322722 -8.87664847] .. GENERATED FROM PYTHON SOURCE LINES 184-187 Normalized atoms / columns ''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 187-188 .. code-block:: default Phi = lop.gaussian_dict(keys[0], m, n, normalize_atoms=True) .. GENERATED FROM PYTHON SOURCE LINES 189-190 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 190-191 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.53952553 -0.4932261 0.46508795 0.32887168 0.30488928 0.52725899 -0.08942487 -0.95844277] [ 0.48259628 -0.6628074 -0.42056978 -0.27448567 0.03649064 0.80015779 0.22029504 0.27294953] [ 0.06249316 0.4415227 -0.59611486 -0.46910168 -0.34679027 0.14347673 -0.6733011 0.06830253] [-0.6871009 0.34996011 -0.50145921 0.77229829 -0.88625475 -0.24730527 -0.70009922 0.047125 ]] .. GENERATED FROM PYTHON SOURCE LINES 192-193 Check the column wise norms .. GENERATED FROM PYTHON SOURCE LINES 193-194 .. code-block:: default print(cnb.norms_l2_cw(lop.to_matrix(Phi))) .. rst-class:: sphx-glr-script-out .. code-block:: none [1. 1. 1. 1. 1. 1. 1. 1.] .. GENERATED FROM PYTHON SOURCE LINES 195-196 Let's print the contents of the adjoint matrix .. GENERATED FROM PYTHON SOURCE LINES 196-197 .. code-block:: default print(lop.to_adjoint_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.53952553 0.48259628 0.06249316 -0.6871009 ] [-0.4932261 -0.6628074 0.4415227 0.34996011] [ 0.46508795 -0.42056978 -0.59611486 -0.50145921] [ 0.32887168 -0.27448567 -0.46910168 0.77229829] [ 0.30488928 0.03649064 -0.34679027 -0.88625475] [ 0.52725899 0.80015779 0.14347673 -0.24730527] [-0.08942487 0.22029504 -0.6733011 -0.70009922] [-0.95844277 0.27294953 0.06830253 0.047125 ]] .. GENERATED FROM PYTHON SOURCE LINES 198-199 Let's apply the forward operator .. GENERATED FROM PYTHON SOURCE LINES 199-202 .. code-block:: default x = jnp.array([3, -2, 4, 8, 2, 2, 6, -1]) y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 5.94539092 1.61735679 -11.34757498 -5.10351374] .. GENERATED FROM PYTHON SOURCE LINES 203-204 Let's apply the adjoint operator .. GENERATED FROM PYTHON SOURCE LINES 204-206 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 0.37032318 -10.80065612 11.40858028 2.89306098 10.32994614 4.06291433 11.0379306 -6.27243136] .. GENERATED FROM PYTHON SOURCE LINES 207-208 Let's JIT compile the trans and times functions .. GENERATED FROM PYTHON SOURCE LINES 208-209 .. code-block:: default Phi = lop.jit(Phi) .. GENERATED FROM PYTHON SOURCE LINES 210-211 Let's verify the forward operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 211-213 .. code-block:: default y = Phi.times(x) print(y) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 5.94539092 1.61735679 -11.34757498 -5.10351374] .. GENERATED FROM PYTHON SOURCE LINES 214-215 Let's verify the adjoint operator after JIT compile .. GENERATED FROM PYTHON SOURCE LINES 215-217 .. code-block:: default z = Phi.trans(y) print(z) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 0.37032318 -10.80065612 11.40858028 2.89306098 10.32994614 4.06291433 11.0379306 -6.27243136] .. GENERATED FROM PYTHON SOURCE LINES 218-221 Column wise application on input ''''''''''''''''''''''''''''''''''''''' Number of signals .. GENERATED FROM PYTHON SOURCE LINES 221-222 .. code-block:: default k = 5 .. GENERATED FROM PYTHON SOURCE LINES 223-224 Prepare a signal matrix .. GENERATED FROM PYTHON SOURCE LINES 224-226 .. code-block:: default X = random.randint(keys[1], (n, k), -5, 5) print(X) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-4 -5 -2 -4 2] [ 0 2 -2 1 3] [ 2 -2 4 -4 -2] [ 2 4 -5 1 -1] [ 2 -5 -2 -2 -4] [-4 2 -3 -1 -4] [-1 -1 -1 4 1] [-3 -4 -1 -4 1]] .. GENERATED FROM PYTHON SOURCE LINES 227-228 Let's apply the forward operator column wise .. GENERATED FROM PYTHON SOURCE LINES 228-230 .. code-block:: default Y = Phi.times(X) print(Y) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 5.21151717 5.54975384 1.13780878 2.47243 -8.19423762] [-7.48728951 -3.88963009 -2.91612777 -2.26915609 -2.76095358] [-3.17949966 2.30739835 -0.17883383 -0.30940293 3.31914138] [ 3.06551754 12.67579867 -2.02564721 4.9074167 3.78756451]] .. GENERATED FROM PYTHON SOURCE LINES 231-232 Let's apply the adjoint operator column wise .. GENERATED FROM PYTHON SOURCE LINES 232-235 .. code-block:: default Z = Phi.trans(Y) print(Z) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ -8.73010144 -13.43671088 -0.64054117 -5.82025136 0.69355917] [ 2.06116221 5.29558478 0.58377917 1.86533811 8.66256504] [ 5.93085649 -3.51488594 2.87800132 -0.17219376 -6.52776613] [ 7.62807664 11.59989779 -0.30588428 5.371094 -0.5688957 ] [ -0.29849024 -10.48404468 2.0977516 -3.57090899 -7.10687709] [ -4.45749663 -2.98989408 -1.25814771 -1.77009412 -6.99014907] [ -2.12085781 -11.7810428 0.79440614 -3.94833782 -4.76190827] [ -7.11129849 -5.62584597 -1.99415376 -2.77891873 7.50530159]] .. GENERATED FROM PYTHON SOURCE LINES 236-239 Row wise application on input ''''''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 239-240 .. code-block:: default Phi = lop.gaussian_dict(keys[0], m, n, normalize_atoms=True, axis=1) .. GENERATED FROM PYTHON SOURCE LINES 241-242 Prepare a signal matrix with each signal along a row .. GENERATED FROM PYTHON SOURCE LINES 242-243 .. code-block:: default XT = X.T .. GENERATED FROM PYTHON SOURCE LINES 244-245 Let's apply the forward operator column wise .. GENERATED FROM PYTHON SOURCE LINES 245-247 .. code-block:: default Y = Phi.times(XT) print(Y) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 5.21151717 -7.48728951 -3.17949966 3.06551754] [ 5.54975384 -3.88963009 2.30739835 12.67579867] [ 1.13780878 -2.91612777 -0.17883383 -2.02564721] [ 2.47243 -2.26915609 -0.30940293 4.9074167 ] [-8.19423762 -2.76095358 3.31914138 3.78756451]] .. GENERATED FROM PYTHON SOURCE LINES 248-249 Let's apply the adjoint operator column wise .. GENERATED FROM PYTHON SOURCE LINES 249-252 .. code-block:: default Z = Phi.trans(Y) print(Z) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ -8.73010144 2.06116221 5.93085649 7.62807664 -0.29849024 -4.45749663 -2.12085781 -7.11129849] [-13.43671088 5.29558478 -3.51488594 11.59989779 -10.48404468 -2.98989408 -11.7810428 -5.62584597] [ -0.64054117 0.58377917 2.87800132 -0.30588428 2.0977516 -1.25814771 0.79440614 -1.99415376] [ -5.82025136 1.86533811 -0.17219376 5.371094 -3.57090899 -1.77009412 -3.94833782 -2.77891873] [ 0.69355917 8.66256504 -6.52776613 -0.5688957 -7.10687709 -6.99014907 -4.76190827 7.50530159]] .. GENERATED FROM PYTHON SOURCE LINES 253-256 Square sensing matrix ''''''''''''''''''''''''''''''''''' Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 256-257 .. code-block:: default Phi = lop.gaussian_dict(keys[0], n, normalize_atoms=False) .. GENERATED FROM PYTHON SOURCE LINES 258-259 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 259-262 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-5.06479786e-01 -1.76665935e-01 2.54534851e-01 -5.06364763e-01 -1.96507134e-01 1.79333415e-01 6.42379919e-01 2.10040808e-01] [ 1.07240051e-01 -5.94812765e-01 1.25249038e-01 1.14459574e-01 -2.02012833e-01 -4.09751511e-01 -4.33936884e-01 -1.34516542e-01] [ 1.11053768e-01 3.48672071e-01 3.68653905e-01 9.45349248e-02 -3.29041791e-01 -1.77899332e-01 -4.04006639e-01 -1.00726911e-01] [ 1.33743289e-01 -5.08041866e-01 -4.99556060e-01 1.33236537e-01 -1.68340852e-01 -2.78095509e-01 -9.48804677e-02 -3.28437869e-01] [-1.03963687e-03 -5.37674760e-02 -2.64978470e-01 -5.69247421e-01 -2.17436962e-01 -3.91220044e-01 -2.19387753e-01 -2.30803981e-01] [ 1.71456228e-01 1.59848991e-01 -2.55230677e-01 -2.51277665e-01 2.37702097e-02 -3.31785957e-01 -1.86295948e-01 9.79684620e-01] [-4.17172092e-02 2.52724150e-01 2.02487423e-01 -3.80860117e-01 -2.98349811e-01 -1.20580149e-01 8.39526917e-01 -2.28584283e-01] [ 2.06869121e-01 1.04520297e+00 8.87791963e-01 2.20836838e-01 1.17742766e-01 -1.85396223e-01 4.36565908e-03 -2.27983571e-01]] .. GENERATED FROM PYTHON SOURCE LINES 263-266 Random matrix with orthonormal rows ----------------------------------------------------------------- Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 266-267 .. code-block:: default Phi = lop.random_orthonormal_rows_dict(keys[0], m, n) .. GENERATED FROM PYTHON SOURCE LINES 268-269 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 269-270 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.48805761 0.12995918 0.4365591 0.01555415 0.05653164 -0.14781949 -0.62155505 -0.37776645] [-0.46559454 0.31376094 -0.50148534 0.45550458 0.37354653 0.06455508 0.2203263 -0.18318237] [ 0.34953016 -0.08652247 -0.37115078 0.21179339 -0.33253457 -0.53588747 -0.13369294 -0.52163662] [-0.34327893 -0.77342544 0.15727696 0.3162613 -0.21117691 0.13210122 0.2701341 -0.15555246]] .. GENERATED FROM PYTHON SOURCE LINES 271-272 Check the row wise norms .. GENERATED FROM PYTHON SOURCE LINES 272-273 .. code-block:: default print(cnb.norms_l2_rw(lop.to_matrix(Phi))) .. rst-class:: sphx-glr-script-out .. code-block:: none [1. 1. 1. 1.] .. GENERATED FROM PYTHON SOURCE LINES 274-275 Let's apply the forward operator column wise .. GENERATED FROM PYTHON SOURCE LINES 275-277 .. code-block:: default Y = Phi.times(X) print(Y) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 5.3156526 3.44362845 3.71437922 -0.58889084 -2.10908012] [ 2.58851023 4.55426428 -4.95769928 5.43997158 -1.15770268] [ 1.46024812 2.47991672 -0.14152435 2.96448472 3.78835967] [ 1.56595683 2.79219775 1.19267863 2.27984255 -3.206765 ]] .. GENERATED FROM PYTHON SOURCE LINES 278-279 Let's apply the adjoint operator column wise .. GENERATED FROM PYTHON SOURCE LINES 279-281 .. code-block:: default Z = Phi.trans(Y) print(Z) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-3.82670014 -3.8928266 0.03655821 -1.9918535 3.99333346] [ 0.16549613 -0.49764393 -1.98301766 -0.38946395 1.51507918] [ 0.72681332 -1.26182404 4.3478673 -3.72685574 -2.2505701 ] [ 2.06628118 3.53634503 -1.85325656 3.81765653 -0.77196994] [ 0.45115468 0.48159786 -1.84675587 0.53154779 -1.13425141] [-1.19431947 -1.17513811 -0.63570689 -0.84923291 -2.21672446] [-2.50586037 -0.71426 -3.05989872 1.7841294 -0.31689645] [-3.48755201 -3.86309685 -0.60670455 -2.67506262 -0.46851652]] .. GENERATED FROM PYTHON SOURCE LINES 282-283 The frame operator .. GENERATED FROM PYTHON SOURCE LINES 283-284 .. code-block:: default F = lop.frame(Phi) .. GENERATED FROM PYTHON SOURCE LINES 285-286 Check that it's close to identity matrix .. GENERATED FROM PYTHON SOURCE LINES 286-288 .. code-block:: default print(jnp.round(lop.to_matrix(F),2)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 1. -0. 0. 0.] [-0. 1. 0. 0.] [ 0. 0. 1. -0.] [ 0. 0. -0. 1.]] .. GENERATED FROM PYTHON SOURCE LINES 289-292 Random orthonormal basis operator ----------------------------------------------------------------- Construct the operator wrapping the sensing matrix .. GENERATED FROM PYTHON SOURCE LINES 292-293 .. code-block:: default Phi = lop.random_onb_dict(keys[0], n) .. GENERATED FROM PYTHON SOURCE LINES 294-295 Let's print the contents of the matrix .. GENERATED FROM PYTHON SOURCE LINES 295-296 .. code-block:: default print(lop.to_matrix(Phi)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-0.83021008 0.10099603 0.1924291 -0.18709837 -0.05440769 -0.42034524 0.05004106 0.21531801] [ 0.17578544 -0.49159467 0.73866229 -0.34880127 0.22399819 0.03967139 -0.03076634 0.08633818] [ 0.1820368 0.2083679 0.2342978 -0.08887811 -0.75177769 -0.00617792 -0.49250229 0.22996581] [ 0.21922894 -0.43921983 -0.12485129 0.04649406 -0.44739928 -0.55798428 0.46709786 -0.10762012] [-0.00170415 -0.03951229 -0.294542 -0.6724019 0.03554208 -0.17193851 -0.34738298 -0.55502752] [ 0.28104713 0.04021688 -0.36937749 -0.38856286 0.23274741 -0.19465774 0.00554408 0.73476564] [-0.06838189 0.20710371 0.01707164 -0.47829639 -0.29978828 0.51519234 0.60668761 -0.00266108] [ 0.33909513 0.6824461 0.35125433 -0.0373899 0.19031866 -0.4212764 0.21687527 -0.18377793]] .. GENERATED FROM PYTHON SOURCE LINES 297-298 Check the row wise norms .. GENERATED FROM PYTHON SOURCE LINES 298-299 .. code-block:: default print(cnb.norms_l2_rw(lop.to_matrix(Phi))) .. rst-class:: sphx-glr-script-out .. code-block:: none [1. 1. 1. 1. 1. 1. 1. 1.] .. GENERATED FROM PYTHON SOURCE LINES 300-301 Check the column wise norms .. GENERATED FROM PYTHON SOURCE LINES 301-302 .. code-block:: default print(cnb.norms_l2_cw(lop.to_matrix(Phi))) .. rst-class:: sphx-glr-script-out .. code-block:: none [1. 1. 1. 1. 1. 1. 1. 1.] .. GENERATED FROM PYTHON SOURCE LINES 303-304 Let's apply the forward operator column wise .. GENERATED FROM PYTHON SOURCE LINES 304-306 .. code-block:: default Y = Phi.times(X) print(Y) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 4.20807229 1.73982564 4.26812837 2.33307439 0.60917887] [ 0.13764291 -6.08988076 4.70769159 -5.45427267 -3.25084291] [-2.11354663 2.00161547 2.38539797 -2.92598768 3.37874579] [ 0.15927087 -0.45449504 1.91737998 2.9814184 3.7050189 ] [ 0.84423256 -0.12512179 3.61341624 1.4045029 0.78271592] [-3.60578444 -6.63795754 -0.79905496 -3.18274785 2.3980138 ] [-3.90797221 0.74207081 0.63229793 2.4558273 0.67111076] [ 1.67154977 -2.45856137 0.39897891 -0.4730898 3.0173381 ]] .. GENERATED FROM PYTHON SOURCE LINES 307-308 Let's apply the adjoint operator column wise .. GENERATED FROM PYTHON SOURCE LINES 308-310 .. code-block:: default Z = Phi.trans(Y) print(Z) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-4. -5. -2. -4. 2.] [ 0. 2. -2. 1. 3.] [ 2. -2. 4. -4. -2.] [ 2. 4. -5. 1. -1.] [ 2. -5. -2. -2. -4.] [-4. 2. -3. -1. -4.] [-1. -1. -1. 4. 1.] [-3. -4. -1. -4. 1.]] .. GENERATED FROM PYTHON SOURCE LINES 311-312 The gram operator .. GENERATED FROM PYTHON SOURCE LINES 312-313 .. code-block:: default G = lop.gram(Phi) .. GENERATED FROM PYTHON SOURCE LINES 314-315 Check that it's close to identity matrix .. GENERATED FROM PYTHON SOURCE LINES 315-316 .. code-block:: default print(jnp.round(lop.to_matrix(G),2)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 1. 0. 0. 0. 0. 0. 0. -0.] [ 0. 1. 0. -0. 0. 0. -0. -0.] [ 0. 0. 1. -0. -0. 0. 0. 0.] [ 0. -0. -0. 1. 0. -0. -0. 0.] [ 0. 0. -0. 0. 1. -0. -0. -0.] [ 0. 0. 0. -0. -0. 1. -0. 0.] [ 0. -0. 0. -0. -0. -0. 1. 0.] [-0. -0. 0. 0. -0. 0. 0. 1.]] .. GENERATED FROM PYTHON SOURCE LINES 317-318 The frame operator .. GENERATED FROM PYTHON SOURCE LINES 318-319 .. code-block:: default F = lop.frame(Phi) .. GENERATED FROM PYTHON SOURCE LINES 320-321 Check that it's close to identity matrix .. GENERATED FROM PYTHON SOURCE LINES 321-323 .. code-block:: default print(jnp.round(lop.to_matrix(F),2)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 1. -0. -0. 0. 0. 0. 0. 0.] [-0. 1. 0. 0. 0. -0. 0. -0.] [-0. 0. 1. -0. 0. 0. -0. -0.] [ 0. 0. -0. 1. 0. 0. -0. 0.] [ 0. 0. 0. 0. 1. -0. 0. 0.] [ 0. -0. 0. 0. -0. 1. 0. 0.] [ 0. 0. -0. -0. 0. 0. 1. 0.] [ 0. -0. -0. 0. 0. 0. 0. 1.]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.243 seconds) .. _sphx_glr_download_gallery_0100_lop_cs_operators.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cs_operators.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cs_operators.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_