{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# [NTDS'18] tutorial 4: Graph visualization\n", "[ntds'18]: https://github.com/mdeff/ntds_2018\n", "\n", "[Benjamin Ricaud](https://people.epfl.ch/benjamin.ricaud), [EPFL LTS2](https://lts2.epfl.ch)\n", "\n", "* Dataset: [Brain network](http://awesome.cs.jhu.edu/graph-services/download/) (Worm brain network, c.elegans_neural.male_1)\n", "* Tools: [Gephi](https://gephi.org/)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1 Live demo with the Gephi software\n", "\n", "Download a dataset (that can be read with Gephi, for example a `.graphml` file) and open it with Gephi." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2 Different layouts\n", "\n", "### 2.1 General idea\n", "\n", "Except with geographical data, the position of nodes is rarely given. In order to have a global view of the network structure, several layouts have been designed for graph visualization. The most efficients are probably the [force directed layouts](https://en.wikipedia.org/wiki/Force-directed_graph_drawing). The default Gephi layout is the [force atlas 2 layout](https://github.com/gephi/gephi/wiki/Force-Atlas-2). \n", "In this layout, nodes are seen as negative particles repealing each other, while edges keep them attached. A general \"gravity\" force attracts them in the center of the image.\n", "\n", "Alternative layouts are:\n", "* [fruchterman-reinghold layout](https://github.com/gephi/gephi/wiki/Fruchterman-Reingold), the \"mass-spring\" layout where edges are springs with a tunable stiffness.\n", "* [Yifan Hu](http://www.mathematica-journal.com/issue/v10i1/contents/graph_draw/graph_draw.pdf), a force directed layout for large graphs, using graph coarsening.\n", "\n", "### 2.2 Experiment\n", "\n", "Inside the Gephi interface, on the bottom left part, we can choose the visualization layout. Choose `Force Atlas 2` and click on `Run`. After a few seconds click on `Stop` to stop the computation.\n", "\n", "You can try to change the various layout parameters to see their effect.\n", "\n", "### 2.3 Remarks\n", "\n", "* In all these layouts, nodes are first placed at random and their positions evolve according the the layout laws. This will lead to different final positions each time the layout is run.\n", "* These algorithms work out-of-the-box but have many parameters that can be tuned to get a better visualization depending on the type of graph displayed.\n", "* An alternative layout called \"spectral layout\" will be seen later on during the course. It is based on *Laplacian eigenmaps*." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3 Shapes and colors\n", "\n", "### 3.1 General idea\n", "\n", "Useful information (about individual nodes) can be encoded in the figure using different means. It can be some text, a color scheme, or the size of nodes.\n", "\n", "### 3.2 Experiment\n", "\n", "We can modify the node sizes according to their degree using the top left window `Appearance`.\n", "Choose the `nodes` tab and the size icon. Then the `Ranking` tab and finally the `Degree` and click `Apply`.\n", "\n", "Let us add some colors to the graph. On the right side, choose `Statistics` and then run the `Modularity`. \n", "After the computation, go back to the `Appearance` and choose `nodes` and the color icon. Choose `Partition`, you can see a new node property was added by Gephi, the `Modularity`. Select it and click `Apply`. The modularity is a way to perform a [community detection](https://en.wikipedia.org/wiki/Community_structure). Here it uses the *Louvain* method.\n", "\n", "On the bottom you can display information belonging to nodes such as `Id` or `name`. Click on the `T` symbol on the bottom middle bar to display the labels. You may drag horizontally the white circles to change the size of the text or of the edges thickness. Click on the small icon on the right of the bottom middle bar to get more options. Click on `Configure...` to choose the property you want to display." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4 Graph properties\n", "\n", "### 4.1 General idea\n", "\n", "Gephi provides several tools to compute useful graph properties. They can give us a better understanding of the network struture and properties.\n", "\n", "### 4.2 Experiment\n", "\n", "On the right, choose the `Statistics` tab. Let us try to compute the following quantities:\n", "\n", "* average degree\n", "* diameter + centrality measures (computed from the shortest paths)\n", "* graph density \n", "* pagerank\n", "* connected components\n", "* eigenvector centrality" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5 Filters\n", "\n", "### 5.1 General idea\n", "\n", "As in the case of a signal, you use filters to remove some part of the data, where there is no relevant information or some information that you are not interested in. This gives you a better view of the remaining information, the one you are interested in, and you can focus on it.\n", "\n", "### 5.2 Experiments\n", "\n", "Let us display only a selected number of nodes with the tab `Filters`.\n", "\n", "Let us try the subfield `topology` and:\n", "* degree range\n", "* ego\n", "* K-core\n", "\n", "the subfield `Partition` and:\n", "* modularity\n", "\n", "the subfield `Range` and:\n", "* betweenness centrality\n", "\n", "You can also select a subgraph, copy it and paste it in another workspace." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" } }, "nbformat": 4, "nbformat_minor": 2 }