Skip to content

Instantly share code, notes, and snippets.

@gerritgr
Created March 15, 2022 15:02
Show Gist options
  • Select an option

  • Save gerritgr/d2bff76485d208ae912922b960b3efe5 to your computer and use it in GitHub Desktop.

Select an option

Save gerritgr/d2bff76485d208ae912922b960b3efe5 to your computer and use it in GitHub Desktop.
Lumpy.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Lumpy.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyNOB3Sg2bWNszqdH71iZbmL",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/gerritgr/d2bff76485d208ae912922b960b3efe5/lumpy.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "PfbRrlBmCUry",
"outputId": "56188b7b-5ee3-4290-99be-7454b388c2ad"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Cloning into 'LumPy'...\n",
"remote: Enumerating objects: 140, done.\u001b[K\n",
"remote: Counting objects: 100% (25/25), done.\u001b[K\n",
"remote: Compressing objects: 100% (25/25), done.\u001b[K\n",
"remote: Total 140 (delta 10), reused 0 (delta 0), pack-reused 115\u001b[K\n",
"Receiving objects: 100% (140/140), 87.20 KiB | 2.56 MiB/s, done.\n",
"Resolving deltas: 100% (71/71), done.\n"
]
}
],
"source": [
"!git clone https://github.com/gerritgr/LumPy"
]
},
{
"cell_type": "markdown",
"source": [
"### You must restart the runtime after the next line is executed!"
],
"metadata": {
"id": "5OOGHDwWEgSY"
}
},
{
"cell_type": "code",
"source": [
"!pip install -r LumPy/requirements.txt"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "NrXTln6QCV14",
"outputId": "e0e47cc8-d214-42f2-fb09-1a8bfa409170"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from -r LumPy/requirements.txt (line 1)) (1.3.5)\n",
"Collecting seaborn==0.8.1\n",
" Downloading seaborn-0.8.1.tar.gz (178 kB)\n",
"\u001b[K |████████████████████████████████| 178 kB 5.2 MB/s \n",
"\u001b[?25hRequirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from -r LumPy/requirements.txt (line 3)) (1.21.5)\n",
"Collecting matplotlib==3.3.4\n",
" Downloading matplotlib-3.3.4-cp37-cp37m-manylinux1_x86_64.whl (11.5 MB)\n",
"\u001b[K |████████████████████████████████| 11.5 MB 37.4 MB/s \n",
"\u001b[?25hCollecting networkx==2.1\n",
" Downloading networkx-2.1.zip (1.6 MB)\n",
"\u001b[K |████████████████████████████████| 1.6 MB 35.5 MB/s \n",
"\u001b[?25hCollecting symengine\n",
" Downloading symengine-0.9.2-cp37-cp37m-manylinux2010_x86_64.whl (37.5 MB)\n",
"\u001b[K |████████████████████████████████| 37.5 MB 1.4 MB/s \n",
"\u001b[?25hRequirement already satisfied: imageio in /usr/local/lib/python3.7/dist-packages (from -r LumPy/requirements.txt (line 7)) (2.4.1)\n",
"Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from -r LumPy/requirements.txt (line 8)) (1.4.1)\n",
"Collecting pathos\n",
" Downloading pathos-0.2.8-py2.py3-none-any.whl (81 kB)\n",
"\u001b[K |████████████████████████████████| 81 kB 5.6 MB/s \n",
"\u001b[?25hCollecting blist\n",
" Downloading blist-1.3.6.tar.gz (122 kB)\n",
"\u001b[K |████████████████████████████████| 122 kB 45.1 MB/s \n",
"\u001b[?25hRequirement already satisfied: sympy in /usr/local/lib/python3.7/dist-packages (from -r LumPy/requirements.txt (line 11)) (1.7.1)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from -r LumPy/requirements.txt (line 12)) (4.63.0)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.4->-r LumPy/requirements.txt (line 4)) (0.11.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.4->-r LumPy/requirements.txt (line 4)) (1.3.2)\n",
"Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.4->-r LumPy/requirements.txt (line 4)) (7.1.2)\n",
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.4->-r LumPy/requirements.txt (line 4)) (3.0.7)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.4->-r LumPy/requirements.txt (line 4)) (2.8.2)\n",
"Requirement already satisfied: decorator>=4.1.0 in /usr/local/lib/python3.7/dist-packages (from networkx==2.1->-r LumPy/requirements.txt (line 5)) (4.4.2)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib==3.3.4->-r LumPy/requirements.txt (line 4)) (1.15.0)\n",
"Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->-r LumPy/requirements.txt (line 1)) (2018.9)\n",
"Requirement already satisfied: multiprocess>=0.70.12 in /usr/local/lib/python3.7/dist-packages (from pathos->-r LumPy/requirements.txt (line 9)) (0.70.12.2)\n",
"Collecting pox>=0.3.0\n",
" Downloading pox-0.3.0-py2.py3-none-any.whl (30 kB)\n",
"Collecting ppft>=1.6.6.4\n",
" Downloading ppft-1.6.6.4-py3-none-any.whl (65 kB)\n",
"\u001b[K |████████████████████████████████| 65 kB 2.7 MB/s \n",
"\u001b[?25hRequirement already satisfied: dill>=0.3.4 in /usr/local/lib/python3.7/dist-packages (from pathos->-r LumPy/requirements.txt (line 9)) (0.3.4)\n",
"Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.7/dist-packages (from sympy->-r LumPy/requirements.txt (line 11)) (1.2.1)\n",
"Building wheels for collected packages: seaborn, networkx, blist\n",
" Building wheel for seaborn (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for seaborn: filename=seaborn-0.8.1-py3-none-any.whl size=184850 sha256=38ddf3f8297508f5cdb522255bc2afd515d4b5e0da150727ce1a38fdf4b1551b\n",
" Stored in directory: /root/.cache/pip/wheels/5f/54/36/8bf02b21dbff2da8fcc84a6d11903cc5fc6cc42a13aa501233\n",
" Building wheel for networkx (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for networkx: filename=networkx-2.1-py2.py3-none-any.whl size=1447361 sha256=808ee338454acc0dbfd73b0007d8d371358bc624c4fb22092cc7b20e32f2259c\n",
" Stored in directory: /root/.cache/pip/wheels/48/b1/c4/94ca0cdd84961331402e857d562d9822ccfcb0567c3d064bf2\n",
" Building wheel for blist (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for blist: filename=blist-1.3.6-cp37-cp37m-linux_x86_64.whl size=130619 sha256=16701505ab957b5f92f1d22930437abc11fa0ba0619c2e7070251b2e00ca721d\n",
" Stored in directory: /root/.cache/pip/wheels/50/2c/17/ae6047bdc296d26322607ef96f49bc0c93b60def0a6dbd258d\n",
"Successfully built seaborn networkx blist\n",
"Installing collected packages: ppft, pox, symengine, seaborn, pathos, networkx, matplotlib, blist\n",
" Attempting uninstall: seaborn\n",
" Found existing installation: seaborn 0.11.2\n",
" Uninstalling seaborn-0.11.2:\n",
" Successfully uninstalled seaborn-0.11.2\n",
" Attempting uninstall: networkx\n",
" Found existing installation: networkx 2.6.3\n",
" Uninstalling networkx-2.6.3:\n",
" Successfully uninstalled networkx-2.6.3\n",
" Attempting uninstall: matplotlib\n",
" Found existing installation: matplotlib 3.2.2\n",
" Uninstalling matplotlib-3.2.2:\n",
" Successfully uninstalled matplotlib-3.2.2\n",
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"albumentations 0.1.12 requires imgaug<0.2.7,>=0.2.5, but you have imgaug 0.2.9 which is incompatible.\u001b[0m\n",
"Successfully installed blist-1.3.6 matplotlib-3.3.4 networkx-2.1 pathos-0.2.8 pox-0.3.0 ppft-1.6.6.4 seaborn-0.8.1 symengine-0.9.2\n"
]
},
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"pip_warning": {
"packages": [
"matplotlib",
"mpl_toolkits"
]
}
}
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"### Run Simulation"
],
"metadata": {
"id": "ZJBXKt3dEur5"
}
},
{
"cell_type": "code",
"source": [
"!cd LumPy && python simulation.py model/SIJS.model"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mJFCUt0DDg-s",
"outputId": "f509ca78-1563-4092-bda0-a1896c5b9e39"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"2022-03-15 14:54:21,395 - INFO - 287 - -------------------------------------------------\n",
"2022-03-15 14:54:21,395 - INFO - 287 - Start Logging \n",
"2022-03-15 14:54:21,395 - INFO - 287 - -------------------------------------------------\n",
"2022-03-15 14:54:22,561 - INFO - 287 - parse file: model/SIJS.model\n",
"2022-03-15 14:54:22,565 - WARNING - 287 - Normalize degree distribution, as it adds up to 1.3383457930192215\n",
"2022-03-15 14:54:22,566 - INFO - 287 - __ parsed model __\n",
"2022-03-15 14:54:22,566 - INFO - 287 - #output_dir output/SIJS\n",
"#bin_num -1\n",
"#maximal_degree_clusters 36\n",
"#number_of_states 3\n",
"#degree_distribution [7.471910512335267e-06, 0.7471910512335267, 0.13208596479228293, 0.047932328285084, 0.02334972035104771, 0.01336615986190155, 0.008473318592110665, 0.005763503508503885, 0.004127686399758842, 0.0030748602931420853, 0.0023628255691935086, 0.0018618725497015973, 0.001497885258908875, 0.0012262337950798001, 0.001018853103563889, 0.00085743955492227, 0.0007296787609702409, 0.0006270603758909276, 0.0005435636411205059, 0.0004748403971198228, 0.00041769249568442346, 0.00036972892245667457, 0.0003291356763997717, 0.00029451815545680256, 0.0002647912060034583, 0.00023910113639472855, 0.00021676955795526048, 0.00019725237977400828, 0.00018010948464074642, 0.00016498203916965115, 0.0001515753309357781, 0.0001396456549724256, 0.0001289901999924638, 0.00011943917975188801, 0.00011084966100146509, 0.0001031006850685858]\n",
"#states ['I', 'J', 'S']\n",
"#initial_distribution [0.025, 0.025, 0.95]\n",
"#k_max 35\n",
"#independent_rules [('I', 'J', 1.0), ('J', 'S', 1.0)]\n",
"#contact_rules [(('S', 'I'), ('I', 'I'), 4.0), (('S', 'J'), ('I', 'J'), 2.0)]\n",
"#horizon 3.0\n",
"#heuristic cluster_subspaceXY\n",
"#name SIJS\n",
"#modeltext --- states = [\"J\", \"I\", \"S\"] --- degree_distribution = lambda x: x**(-2.5) if x > 0 else 0.00001 --- initial_distribution = {'S': 0.95, 'I': 0.025, 'J' :0.025} --- horizon = 3 --- k_max = 35 --- R1: S+I -> I+I with 4.0 --- R2: S+J -> I+J with 2.0 --- R3: I -> J with 1.0 --- R4: J -> S with 1.0 --- --- output_dir = output/SIJS --- bin_num = auto --- \n",
"2022-03-15 14:54:22,566 - INFO - 287 - __ done parsing __\n",
"2022-03-15 14:54:22,566 - INFO - 287 - Start Simulations \tSIJS\n",
"simulation.py:290: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead\n",
" start = time.clock()\n",
"2022-03-15 14:54:22,567 - INFO - 287 - generate random graph\n",
"2022-03-15 14:54:23,054 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.\n",
" import pandas.util.testing as tm\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:54:39,229 - INFO - 287 - generate random graph\n",
"2022-03-15 14:54:39,376 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:54:55,612 - INFO - 287 - generate random graph\n",
"2022-03-15 14:54:55,731 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:55:11,371 - INFO - 287 - generate random graph\n",
"2022-03-15 14:55:11,463 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:55:26,293 - INFO - 287 - generate random graph\n",
"2022-03-15 14:55:26,409 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:55:45,868 - INFO - 287 - generate random graph\n",
"2022-03-15 14:55:45,969 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:56:03,971 - INFO - 287 - generate random graph\n",
"2022-03-15 14:56:04,061 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:56:21,478 - INFO - 287 - generate random graph\n",
"2022-03-15 14:56:21,555 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:56:38,522 - INFO - 287 - generate random graph\n",
"2022-03-15 14:56:38,635 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"2022-03-15 14:56:54,558 - INFO - 287 - generate random graph\n",
"2022-03-15 14:56:54,739 - INFO - 287 - generation successfull\n",
"time is up\n",
"/usr/local/lib/python3.7/dist-packages/seaborn/timeseries.py:183: UserWarning: The tsplot function is deprecated and will be removed or replaced (in a substantially altered version) in a future release.\n",
" warnings.warn(msg, UserWarning)\n",
"simulation.py:312: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead\n",
" model['simulation_time'] = time.clock() - start\n",
"2022-03-15 14:57:09,848 - INFO - 287 - End Simulations \tSIJS\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"### Run AME"
],
"metadata": {
"id": "CC_Rpx45Ewe1"
}
},
{
"cell_type": "code",
"source": [
"#stupid hack\n",
"\n",
"code = open(\"LumPy/ClusterEngine.py\", \"r\").read()\n",
"code = code.replace('plt.scatter(x, y, c=colors, alpha=0.8, s = 10)', '')\n",
"\n",
"f = open(\"LumPy/ClusterEngine.py\", \"a\")\n",
"f.write(code)\n",
"f.close()"
],
"metadata": {
"id": "bRKaFCC4FHZV"
},
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!cd LumPy && python ame.py model/SIJS.model --nolumping"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "MI1J74ByEmLI",
"outputId": "d6e2789a-648b-4df9-ed68-ff0e2e314176"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"2022-03-15 15:02:28,452 - INFO - 414 - -------------------------------------------------\n",
"2022-03-15 15:02:28,452 - INFO - 414 - Start Logging \n",
"2022-03-15 15:02:28,452 - INFO - 414 - -------------------------------------------------\n",
"2022-03-15 15:02:29,347 - INFO - 414 - parse file: model/SIJS.model\n",
"2022-03-15 15:02:29,351 - WARNING - 414 - Normalize degree distribution, as it adds up to 1.3383457930192215\n",
"2022-03-15 15:02:29,352 - INFO - 414 - __ parsed model __\n",
"2022-03-15 15:02:29,352 - INFO - 414 - #output_dir output/SIJS\n",
"#bin_num -1\n",
"#maximal_degree_clusters 36\n",
"#number_of_states 3\n",
"#degree_distribution [7.471910512335267e-06, 0.7471910512335267, 0.13208596479228293, 0.047932328285084, 0.02334972035104771, 0.01336615986190155, 0.008473318592110665, 0.005763503508503885, 0.004127686399758842, 0.0030748602931420853, 0.0023628255691935086, 0.0018618725497015973, 0.001497885258908875, 0.0012262337950798001, 0.001018853103563889, 0.00085743955492227, 0.0007296787609702409, 0.0006270603758909276, 0.0005435636411205059, 0.0004748403971198228, 0.00041769249568442346, 0.00036972892245667457, 0.0003291356763997717, 0.00029451815545680256, 0.0002647912060034583, 0.00023910113639472855, 0.00021676955795526048, 0.00019725237977400828, 0.00018010948464074642, 0.00016498203916965115, 0.0001515753309357781, 0.0001396456549724256, 0.0001289901999924638, 0.00011943917975188801, 0.00011084966100146509, 0.0001031006850685858]\n",
"#states ['I', 'J', 'S']\n",
"#initial_distribution [0.025, 0.025, 0.95]\n",
"#k_max 35\n",
"#independent_rules [('I', 'J', 1.0), ('J', 'S', 1.0)]\n",
"#contact_rules [(('S', 'I'), ('I', 'I'), 4.0), (('S', 'J'), ('I', 'J'), 2.0)]\n",
"#horizon 3.0\n",
"#heuristic cluster_subspaceXY\n",
"#name SIJS\n",
"#modeltext --- states = [\"J\", \"I\", \"S\"] --- degree_distribution = lambda x: x**(-2.5) if x > 0 else 0.00001 --- initial_distribution = {'S': 0.95, 'I': 0.025, 'J' :0.025} --- horizon = 3 --- k_max = 35 --- R1: S+I -> I+I with 4.0 --- R2: S+J -> I+J with 2.0 --- R3: I -> J with 1.0 --- R4: J -> S with 1.0 --- --- output_dir = output/SIJS --- bin_num = auto --- \n",
"2022-03-15 15:02:29,352 - INFO - 414 - __ done parsing __\n",
"2022-03-15 15:02:29,352 - INFO - 414 - Generate ODEs.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {
"id": "9JNRqf9ZFWSH"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment