{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Imports" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from webweb import Web\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Create a SBM network with 3 groups" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "# choose sizes of groups\n", "n1 = 40\n", "n2 = 40\n", "n3 = 70\n", "n = n1+n2+n3\n", "\n", "# group memberships, b\n", "b = np.array([0]*n1 + [1]*n2 + [2]*n3)\n", "\n", "# group affinity matrix\n", "omega = [ [0,0.05,0],\n", " [0.05,0.2,0.05],\n", " [0,0.05,0]]\n", "\n", "# SBM\n", "edge_list = []\n", "for i in range(1,n):\n", " for j in range(i):\n", " if np.random.rand() < omega[b[i]][b[j]]:\n", " edge_list.append([i,j])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Display using webweb" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "web = Web(title='sbm_demo')\n", "web.networks.sbm(\n", " # assign its edgelist\n", " adjacency=edge_list,\n", " # give it the community metadata\n", " metadata={'community': \n", " {\n", " 'values' : list(b),\n", " 'type' : 'categorical',\n", " },\n", " }\n", ")\n", "web.display.colorBy = 'community'\n", "web.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.4" } }, "nbformat": 4, "nbformat_minor": 2 }