<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Foundations for Signal Analysis and Interpretation</title><link href="https://sail.usc.edu/foundations/" rel="alternate"></link><link href="https://sail.usc.edu/foundations/feeds/all.atom.xml" rel="self"></link><id>https://sail.usc.edu/foundations/</id><updated>2017-09-01T00:00:00-07:00</updated><entry><title>GraSP Tutorial</title><link href="https://sail.usc.edu/foundations/grasp_tutorial.html" rel="alternate"></link><published>2017-09-01T00:00:00-07:00</published><updated>2017-09-01T00:00:00-07:00</updated><author><name>Benjamin Girault</name></author><id>tag:sail.usc.edu,2017-09-01:/foundations/grasp_tutorial.html</id><summary type="html">&lt;p&gt;The Graph Signal Processing toolbox GraSP can be found &lt;a href="https://gforge.inria.fr/projects/grasp" title="GraSP website"&gt;here&lt;/a&gt;, and &lt;a href="https://github.com/STAC-USC/GraSP" title="GraSP on Github"&gt;here&lt;/a&gt; (both are GIT repositories with the same content).&lt;/p&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;Before being able to use the toolbox, several third party tools need to be downloaded and made available to Matlab. To do that, go to the grasp root folder …&lt;/p&gt;</summary><content type="html">&lt;p&gt;The Graph Signal Processing toolbox GraSP can be found &lt;a href="https://gforge.inria.fr/projects/grasp" title="GraSP website"&gt;here&lt;/a&gt;, and &lt;a href="https://github.com/STAC-USC/GraSP" title="GraSP on Github"&gt;here&lt;/a&gt; (both are GIT repositories with the same content).&lt;/p&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;Before being able to use the toolbox, several third party tools need to be downloaded and made available to Matlab. To do that, go to the grasp root folder and run the command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;grasp_install&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then setup Matlab path to make the GraSP toolbox available to Matlab:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;grasp_start&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You are know ready to use the toolbox.&lt;/p&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
&lt;p&gt;First, we need a graph to perform graph signal processing on. You can use the provided functions in &lt;code&gt;Graphs/&lt;/code&gt; or any structure you have (we will come back to that later). For example, a random sampling in 2D square, with edges weighted by a Gaussian kernel of the Euclidean distance, is obtained using &lt;code&gt;grasp_plane_rnd&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_plane_rnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The structure &lt;code&gt;g&lt;/code&gt; contains now several fields describing this graph. To show this graph, use the &lt;code&gt;grasp_show_graph&lt;/code&gt; function:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;grasp_show_graph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gca&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The first signal we use in this tutorial is a delta signal obtained by &lt;code&gt;grasp_delta&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;delta_1&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_delta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;We can show it on the previous figure using:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;grasp_show_graph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gca&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;node_values&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delta_1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;We observe in the command above a first way of giving optional parameters to functions in the toolbox, using pairs of name and value. The other way of achieving the same goal is through a Matlab structure:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;node_values&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delta_1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="n"&gt;grasp_show_graph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gca&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;We will use the first form in this tutorial, but sometime the second form is more efficient.&lt;/p&gt;
&lt;p&gt;The next step is to construct the graph Fourier transform. This is done by computing the eigendecomposition of a matrix, and performed by &lt;code&gt;grasp_eigendecomposition&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_eigendecomposition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This completes the data structure &lt;code&gt;g&lt;/code&gt; with the graph Fourier transform. To perform the GFT on the delta signal we defined, we can use the &lt;code&gt;grasp_fourier&lt;/code&gt; function:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;delta_1_hat&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_fourier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delta_1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Components of &lt;code&gt;delta_1_hat&lt;/code&gt; are the Fourier components of the signal &lt;code&gt;delta_1&lt;/code&gt; ordered by increasing frequency.&lt;/p&gt;
&lt;p&gt;Now that the GFT is defined, we can compute a more complex signal using &lt;code&gt;grasp_heat_kernel&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;heat&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_heat_kernel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This signal is a low pass signal. We can then convolve the two signals using:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;conv_sig&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_convolution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delta_1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You can find more operators in the &lt;code&gt;Operators/&lt;/code&gt; folder.&lt;/p&gt;
&lt;h3&gt;Graphs&lt;/h3&gt;
&lt;p&gt;We saw in the previous section that we can build a graph using the function in the folder &lt;code&gt;Graphs/&lt;/code&gt;. Another way is to construct the GraSP structure from the adjacency matrix of the graph. If &lt;code&gt;A&lt;/code&gt; is the adjacency matrix, then we just have to do:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_struct&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Showing the graph &lt;code&gt;g&lt;/code&gt; on a figure then involves the field &lt;code&gt;layout&lt;/code&gt; of the structure &lt;code&gt;g&lt;/code&gt;. This a two column array with as many rows as vertices in the graph. The first column corresponds to the horizontal coordinate, and the second to the vertical coordinate. Coordinates are between 0 and 10. If you have access to a meaningful layout, you can use it to compute &lt;code&gt;g.layout&lt;/code&gt;. Otherwise, use &lt;code&gt;grasp_layout&lt;/code&gt; to do this computation automatically:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layout&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_layout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This function requires GraphViz to be installed on your computer.&lt;/p&gt;
&lt;h4&gt;Manipulating graphs&lt;/h4&gt;
&lt;p&gt;You will find several functions in &lt;code&gt;Graphs/Tools&lt;/code&gt; to refine a graph, such as computing Gaussian weights (&lt;code&gt;grasp_adjacency_gaussian&lt;/code&gt;), thresholding edges (&lt;code&gt;grasp_adjacency_thresh&lt;/code&gt;) or performing KNN selection of edges (&lt;code&gt;grasp_adjacency_knn&lt;/code&gt;).&lt;/p&gt;
&lt;h4&gt;Import/Export&lt;/h4&gt;
&lt;p&gt;You can export a graph structure (adjacency matrix and layout) in two CSV files (one for the vertices and one for the edges) for use outside matlab using the function &lt;code&gt;grasp_exportcsv&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;grasp_exportcsv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;vertices.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;edges.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This structure can then be imported back into Matlab using &lt;code&gt;grasp_importcsv&lt;/code&gt;, used in another software, or used with the LaTeX package provided with GraSP (commands displaying graphs and matrices).&lt;/p&gt;
&lt;p&gt;If you have a CSV file with the adjacency matrix and a layout, you can also use &lt;code&gt;grasp_importcsv&lt;/code&gt; to import the graph into GraSP.&lt;/p&gt;
&lt;p&gt;Finally, GraSP provides function to convert structure from (&lt;code&gt;grasp_from_gspbox&lt;/code&gt;) and to (&lt;code&gt;grasp_to_gspbox&lt;/code&gt;) the toolbox &lt;a href="https://github.com/epfl-lts2/gspbox" title="GSPbox"&gt;GSPbox&lt;/a&gt;, making them compatible with one another.&lt;/p&gt;
&lt;h3&gt;Plotting Functions&lt;/h3&gt;
&lt;p&gt;We saw the most useful function &lt;code&gt;grasp_show_graph&lt;/code&gt; in action earlier. This function has several parameters to control how the figure is rendered. We invite you to read its documentation and experiment. Two of interest are &lt;code&gt;node_values&lt;/code&gt; seen earlier, and &lt;code&gt;show_edges&lt;/code&gt; that should be set to false when the number of edges is high to speed up the function.&lt;/p&gt;
&lt;p&gt;Based on this function, we have also &lt;code&gt;grasp_show_fouriermodes&lt;/code&gt; displaying all (or some) Fourier modes on the same figure within several subaxes.&lt;/p&gt;
&lt;p&gt;Next, we have &lt;code&gt;grasp_show_matrix&lt;/code&gt; that improves upon the builtin function &lt;a href="https://www.mathworks.com/help/images/ref/imshow.html" title="imshow"&gt;&lt;code&gt;imshow&lt;/code&gt;&lt;/a&gt; and giving control over the color scale or the size of the pixels to plot a matrix.&lt;/p&gt;
&lt;p&gt;We also have several functions to better control figures and axes. First, Matlab offers the possibility of having titles to figure that differ from the standard &lt;code&gt;Figure x&lt;/code&gt; where x is an integer. We use that possibility and wrap everything nicely in &lt;code&gt;grasp_open_figurename&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Also, to have better control over subaxes, compared to the builtin function &lt;a href="https://www.mathworks.com/help/matlab/ref/subplot.html" title="subplot"&gt;&lt;code&gt;subplot&lt;/code&gt;&lt;/a&gt;, we provide &lt;code&gt;grasp_subaxis&lt;/code&gt; that controls margin between axes allowing for denser figures. The function &lt;code&gt;grasp_subaxis_matrix_dimensions&lt;/code&gt; gives also the ideal number of rows and columns given a total number of figures to maximize the size of the subaxes. Typical usage of this functions is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nb_rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nb_cols&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grasp_subaxis_matrix_dimensions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;...&lt;/span&gt;
&lt;span class="n"&gt;grasp_subaxis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nb_rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nb_cols&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c"&gt;...&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In &lt;code&gt;Util/&lt;/code&gt;, the function &lt;code&gt;grasp_set_blue_red_colormap&lt;/code&gt; will switch the color scale to a blue - white - red one. This is especially useful when the color scale (&lt;code&gt;color_scale&lt;/code&gt; of &lt;code&gt;grasp_show_graph&lt;/code&gt; and &lt;code&gt;grasp_show_matrix&lt;/code&gt;) is symmetric about 0 (from -x to +x) such that 0 is white. Color intensity correspond to how big the value is, and the actual color corresponds to negative or positive values.&lt;/p&gt;</content><category term="first_page"></category></entry></feed>