{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Toy graphs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook shows how to load some toy graphs." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "is_executing": false }, "scrolled": true }, "outputs": [], "source": [ "from IPython.display import SVG" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "from sknetwork.data import house, bow_tie, karate_club, miserables, painters, hourglass, star_wars, movie_actor\n", "from sknetwork.visualization import visualize_graph, visualize_bigraph" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## House graph" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "graph = house(metadata=True)\n", "adjacency = graph.adjacency\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "image = visualize_graph(adjacency, position, scale=0.5)\n", "SVG(image)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "# adjacency matrix only\n", "adjacency = house()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bow tie" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "graph = bow_tie(metadata=True)\n", "adjacency = graph.adjacency\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "image = visualize_graph(adjacency, position, scale=0.5)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SVG(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Karate club" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "graph = karate_club(metadata=True)\n", "adjacency = graph.adjacency\n", "position = graph.position\n", "labels = graph.labels" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "image = visualize_graph(adjacency, position, labels=labels)\n", "SVG(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Les Miserables" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "graph = miserables(metadata=True)\n", "adjacency = graph.adjacency\n", "position = graph.position\n", "names = graph.names" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "image = visualize_graph(adjacency, position, names, scale=2)\n", "SVG(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Painters" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "graph = painters(metadata=True)\n", "adjacency = graph.adjacency\n", "names = graph.names\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "image = visualize_graph(adjacency, position, names)\n", "SVG(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Star wars" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "# bipartite graph\n", "graph = star_wars(metadata=True)\n", "biadjacency = graph.biadjacency\n", "names_row = graph.names_row\n", "names_col = graph.names_col" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "image = visualize_bigraph(biadjacency, names_row, names_col)\n", "SVG(image)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# biadjacency matrix only\n", "biadjacency = star_wars()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Movie-actor" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "# bipartite graph\n", "graph = movie_actor(metadata=True)\n", "biadjacency = graph.biadjacency\n", "names_row = graph.names_row\n", "names_col = graph.names_col" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "image = visualize_bigraph(biadjacency, names_row, names_col)\n", "SVG(image)" ] } ], "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" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } }, "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 }