.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/kernel_localization.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_examples_kernel_localization.py: Kernel localization. =================== In classical signal processing, a filter can be translated in the vertex domain. We cannot do that on graphs. Instead, we can :meth:`~pygsp2.filters.Filter.localize` a filter kernel. Note how on classic structures (like the ring), the localized kernel is the same everywhere, while it changes when localized on irregular graphs. .. GENERATED FROM PYTHON SOURCE LINES 11-42 .. image-sg:: /examples/images/sphx_glr_kernel_localization_001.png :alt: heat kernel, $g(L) \delta_{0}$, $g(L) \delta_{10}$, $g(L) \delta_{20}$, heat kernel, $g(L) \delta_{0}$, $g(L) \delta_{10}$, $g(L) \delta_{20}$ :srcset: /examples/images/sphx_glr_kernel_localization_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np from matplotlib import pyplot as plt import pygsp2 as pg fig, axes = plt.subplots(2, 4, figsize=(10, 4)) graphs = [ pg.graphs.Ring(40), pg.graphs.Sensor(64, seed=42), ] locations = [0, 10, 20] for graph, axs in zip(graphs, axes): graph.compute_fourier_basis() g = pg.filters.Heat(graph) g.plot(ax=axs[0], title='heat kernel') axs[0].set_xlabel(r'eigenvalues $\lambda$') axs[0].set_ylabel(r'$g(\lambda) = \exp \left( \frac{{-{}\lambda}}{{\lambda_{{max}}}} \right)$'.format(g.scale[0])) maximum = 0 for loc in locations: x = g.localize(loc) maximum = np.maximum(maximum, x.max()) for loc, ax in zip(locations, axs[1:]): graph.plot(g.localize(loc), limits=[0, maximum], highlight=loc, ax=ax, title=r'$g(L) \delta_{{{}}}$'.format(loc)) ax.set_axis_off() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.541 seconds) **Estimated memory usage:** 181 MB .. _sphx_glr_download_examples_kernel_localization.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: kernel_localization.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: kernel_localization.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: kernel_localization.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_