.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/grass.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_grass.py: .. _gallery:dict:grass:1: Grassmannian Frames ===================== .. contents:: :depth: 2 :local: A Grassmannian (real) frame :math:`\Phi` is an :math:`m \times n` matrix (dictionary) with unit norm columns such that the individual columns (atoms) are as far away from each other as possible. In other words, it is a matrix with minimum possible coherence. If :math:`\bG = \Phi^T \Phi` then every off diagonal entry of the Gram matrix :math:`\bG` has the value: .. math:: |g_{i j} | = \sqrt{\frac{n - m}{m (n - 1)}} Grassmannian frames are hard to construct. CR-Sparse library includes a method based on alternate projections to construct a Grassmannian frame starting from a random dictionary. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: default # Configure JAX to work with 64-bit floating point precision. from jax.config import config config.update("jax_enable_x64", True) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Let's import necessary libraries .. GENERATED FROM PYTHON SOURCE LINES 34-43 .. code-block:: default import jax import numpy as np import jax.numpy as jnp import cr.nimble as crn import cr.sparse as crs import cr.sparse.dict as crdict from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 44-46 Frame size ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-50 .. code-block:: default m = 50 n = 100 .. GENERATED FROM PYTHON SOURCE LINES 51-53 Minimum possible coherence ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 53-58 .. code-block:: default min_mu = crdict.minimum_coherence(m, n) print(f'Minimum coherence {min_mu:.5f}') .. rst-class:: sphx-glr-script-out .. code-block:: none Minimum coherence 0.10050 .. GENERATED FROM PYTHON SOURCE LINES 59-61 Construction of Grassmannian frame ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 61-73 .. code-block:: default # Start with a Gaussian random dictionary init = crdict.gaussian_mtx(crn.KEYS[0], m, n) # Iteratively bring it close to a Grassmannian frame frame = crdict.build_grassmannian_frame(init, iterations=50) # The Gram matrix of the final frame gram = frame.T @ frame # Off diagonal elements of the gram matrix off = np.asarray(crn.off_diagonal_elements(gram)) print(f'min: {np.min(off):.3f}, max: {np.max(off):.3f}, mean: {np.mean(np.abs(off)):.5f}') # Absolute values of the Gram matrix plt.imshow(np.abs(gram)) .. image-sg:: /gallery/images/sphx_glr_grass_001.png :alt: grass :srcset: /gallery/images/sphx_glr_grass_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none min: -0.160, max: 0.166, mean: 0.11393 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.359 seconds) .. _sphx_glr_download_gallery_grass.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: grass.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: grass.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_