{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# Core decomposition" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "This notebook illustrates the $k$-core decomposition of graphs." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "from IPython.display import SVG" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2019-07-15T12:29:50.554431Z", "start_time": "2019-07-15T12:29:50.414075Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "from sknetwork.data import karate_club, painters\n", "from sknetwork.topology import get_core_decomposition\n", "from sknetwork.visualization import visualize_graph\n", "from sknetwork.utils import directed2undirected" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Graphs" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2019-07-15T12:29:51.261957Z", "start_time": "2019-07-15T12:29:51.249107Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "graph = karate_club(metadata=True)\n", "adjacency = graph.adjacency\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "values = get_core_decomposition(adjacency)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2019-07-15T12:29:55.341520Z", "start_time": "2019-07-15T12:29:55.026465Z" }, "scrolled": true, "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = visualize_graph(adjacency, position, scores=values)\n", "SVG(image)" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Directed graphs" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2019-07-15T12:29:58.542147Z", "start_time": "2019-07-15T12:29:58.529699Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "graph = painters(metadata=True)\n", "adjacency = graph.adjacency\n", "names = graph.names\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "values = get_core_decomposition(directed2undirected(adjacency))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "scrolled": true, "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "image/svg+xml": [ "Pablo PicassoClaude MonetMichel AngeloEdouard ManetPeter Paul RubensRembrandtGustav KlimtEdgar DegasVincent van GoghLeonardo da VinciHenri MatissePaul CezannePierre-Auguste RenoirEgon Schiele" ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = visualize_graph(adjacency, position, names, scores=values)\n", "SVG(image)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }