diff --git a/notebooks/evaluation_2024.03/epi_scenario3/SEIR_scenario3_petrinet.json b/notebooks/evaluation_2024.03/epi_scenario3/SEIR_scenario3_petrinet.json new file mode 100644 index 00000000..9dab06a8 --- /dev/null +++ b/notebooks/evaluation_2024.03/epi_scenario3/SEIR_scenario3_petrinet.json @@ -0,0 +1,726 @@ +{ + "header": { + "name": "SEIR Scenario 3", + "schema": "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/petrinet_v0.6/petrinet/petrinet_schema.json", + "schema_name": "petrinet", + "description": "SEIR Scenario 3", + "model_version": "0.1" + }, + "properties": {}, + "model": { + "states": [ + { + "id": "S_y", + "name": "S_y", + "grounding": { + "identifiers": { + "ido": "0000514" + }, + "modifiers": { + "status": "young" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "I_y", + "name": "I_y", + "grounding": { + "identifiers": { + "ido": "0000511" + }, + "modifiers": { + "status": "young" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "E_y", + "name": "E_y", + "grounding": { + "identifiers": { + "apollosv": "00000154" + }, + "modifiers": { + "status": "young" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "I_m", + "name": "I_m", + "grounding": { + "identifiers": { + "ido": "0000511" + }, + "modifiers": { + "status": "middle" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "I_o", + "name": "I_o", + "grounding": { + "identifiers": { + "ido": "0000511" + }, + "modifiers": { + "status": "old" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "S_m", + "name": "S_m", + "grounding": { + "identifiers": { + "ido": "0000514" + }, + "modifiers": { + "status": "middle" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "E_m", + "name": "E_m", + "grounding": { + "identifiers": { + "apollosv": "00000154" + }, + "modifiers": { + "status": "middle" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "S_o", + "name": "S_o", + "grounding": { + "identifiers": { + "ido": "0000514" + }, + "modifiers": { + "status": "old" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "E_o", + "name": "E_o", + "grounding": { + "identifiers": { + "apollosv": "00000154" + }, + "modifiers": { + "status": "old" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "R_y", + "name": "R_y", + "grounding": { + "identifiers": { + "ido": "0000592" + }, + "modifiers": { + "status": "young" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "R_m", + "name": "R_m", + "grounding": { + "identifiers": { + "ido": "0000592" + }, + "modifiers": { + "status": "middle" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "R_o", + "name": "R_o", + "grounding": { + "identifiers": { + "ido": "0000592" + }, + "modifiers": { + "status": "old" + } + }, + "units": { + "expression": "person", + "expression_mathml": "person" + } + } + ], + "transitions": [ + { + "id": "t1", + "input": [ + "I_y", + "S_y" + ], + "output": [ + "I_y", + "E_y" + ], + "properties": { + "name": "t1" + } + }, + { + "id": "t2", + "input": [ + "I_m", + "S_y" + ], + "output": [ + "I_m", + "E_y" + ], + "properties": { + "name": "t2" + } + }, + { + "id": "t3", + "input": [ + "I_o", + "S_y" + ], + "output": [ + "I_o", + "E_y" + ], + "properties": { + "name": "t3" + } + }, + { + "id": "t4", + "input": [ + "I_y", + "S_m" + ], + "output": [ + "I_y", + "E_m" + ], + "properties": { + "name": "t4" + } + }, + { + "id": "t5", + "input": [ + "I_m", + "S_m" + ], + "output": [ + "I_m", + "E_m" + ], + "properties": { + "name": "t5" + } + }, + { + "id": "t6", + "input": [ + "I_o", + "S_m" + ], + "output": [ + "I_o", + "E_m" + ], + "properties": { + "name": "t6" + } + }, + { + "id": "t7", + "input": [ + "I_y", + "S_o" + ], + "output": [ + "I_y", + "E_o" + ], + "properties": { + "name": "t7" + } + }, + { + "id": "t8", + "input": [ + "I_m", + "S_o" + ], + "output": [ + "I_m", + "E_o" + ], + "properties": { + "name": "t8" + } + }, + { + "id": "t9", + "input": [ + "I_o", + "S_o" + ], + "output": [ + "I_o", + "E_o" + ], + "properties": { + "name": "t9" + } + }, + { + "id": "t10", + "input": [ + "E_y" + ], + "output": [ + "I_y" + ], + "properties": { + "name": "t10" + } + }, + { + "id": "t11", + "input": [ + "E_m" + ], + "output": [ + "I_m" + ], + "properties": { + "name": "t11" + } + }, + { + "id": "t12", + "input": [ + "E_o" + ], + "output": [ + "I_o" + ], + "properties": { + "name": "t12" + } + }, + { + "id": "t13", + "input": [ + "I_y" + ], + "output": [ + "R_y" + ], + "properties": { + "name": "t13" + } + }, + { + "id": "t14", + "input": [ + "I_m" + ], + "output": [ + "R_m" + ], + "properties": { + "name": "t14" + } + }, + { + "id": "t15", + "input": [ + "I_o" + ], + "output": [ + "R_o" + ], + "properties": { + "name": "t15" + } + } + ] + }, + "semantics": { + "ode": { + "rates": [ + { + "target": "t1", + "expression": "I_y*Myy*S_y*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_yMyyS_ybetamcwmew1N" + }, + { + "target": "t2", + "expression": "I_m*Mym*S_y*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_mMymS_ybetamcwmew1N" + }, + { + "target": "t3", + "expression": "I_o*Myo*S_y*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_oMyoS_ybetamcwmew1N" + }, + { + "target": "t4", + "expression": "I_y*Mmy*S_m*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_yMmyS_mbetamcwmew1N" + }, + { + "target": "t5", + "expression": "I_m*Mmm*S_m*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_mMmmS_mbetamcwmew1N" + }, + { + "target": "t6", + "expression": "I_o*Mmo*S_m*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_oMmoS_mbetamcwmew1N" + }, + { + "target": "t7", + "expression": "I_y*Moy*S_o*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_yMoyS_obetamcwmew1N" + }, + { + "target": "t8", + "expression": "I_m*Mom*S_o*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_mMomS_obetamcwmew1N" + }, + { + "target": "t9", + "expression": "I_o*Moo*S_o*beta*(-mcw*mew + 1)/N", + "expression_mathml": "I_oMooS_obetamcwmew1N" + }, + { + "target": "t10", + "expression": "E_y*r_EI", + "expression_mathml": "E_yr_EI" + }, + { + "target": "t11", + "expression": "E_m*r_EI", + "expression_mathml": "E_mr_EI" + }, + { + "target": "t12", + "expression": "E_o*r_EI", + "expression_mathml": "E_or_EI" + }, + { + "target": "t13", + "expression": "I_y*r_IR", + "expression_mathml": "I_yr_IR" + }, + { + "target": "t14", + "expression": "I_m*r_IR", + "expression_mathml": "I_mr_IR" + }, + { + "target": "t15", + "expression": "I_o*r_IR", + "expression_mathml": "I_or_IR" + } + ], + "initials": [ + { + "target": "S_y", + "expression": "10305660.0", + "expression_mathml": "10305660.0" + }, + { + "target": "I_y", + "expression": "50.0", + "expression_mathml": "50.0" + }, + { + "target": "E_y", + "expression": "50.0", + "expression_mathml": "50.0" + }, + { + "target": "I_m", + "expression": "50.0", + "expression_mathml": "50.0" + }, + { + "target": "I_o", + "expression": "50.0", + "expression_mathml": "50.0" + }, + { + "target": "S_m", + "expression": "15281905.0", + "expression_mathml": "15281905.0" + }, + { + "target": "E_m", + "expression": "50.0", + "expression_mathml": "50.0" + }, + { + "target": "S_o", + "expression": "12154442.0", + "expression_mathml": "12154442.0" + }, + { + "target": "E_o", + "expression": "50.0", + "expression_mathml": "50.0" + }, + { + "target": "R_y", + "expression": "0.0", + "expression_mathml": "0.0" + }, + { + "target": "R_m", + "expression": "0.0", + "expression_mathml": "0.0" + }, + { + "target": "R_o", + "expression": "0.0", + "expression_mathml": "0.0" + } + ], + "parameters": [ + { + "id": "Myy", + "value": 38.62, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "N", + "value": 37742307.0, + "units": { + "expression": "person", + "expression_mathml": "person" + } + }, + { + "id": "beta", + "value": 0.2, + "distribution": { + "type": "StandardUniform1", + "parameters": { + "minimum": 0.05, + "maximum": 0.8 + } + }, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "mcw", + "value": 0.0, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "mew", + "value": 0.0, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Mym", + "value": 20.56, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Myo", + "value": 6.12, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Mmy", + "value": 20.56, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Mmm", + "value": 28.22, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Mmo", + "value": 11.6, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Moy", + "value": 6.12, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Mom", + "value": 11.6, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "Moo", + "value": 20.01, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "r_EI", + "value": 0.08, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + }, + { + "id": "r_IR", + "value": 0.06, + "units": { + "expression": "1/day", + "expression_mathml": "day-1" + } + } + ], + "observables": [ + { + "id": "susceptible", + "name": "susceptible", + "expression": "S_m + S_o + S_y", + "expression_mathml": "S_mS_oS_y" + }, + { + "id": "exposed", + "name": "exposed", + "expression": "E_m + E_o + E_y", + "expression_mathml": "E_mE_oE_y" + }, + { + "id": "infected", + "name": "infected", + "expression": "I_m + I_o + I_y", + "expression_mathml": "I_mI_oI_y" + }, + { + "id": "recovered", + "name": "recovered", + "expression": "R_m + R_o + R_y", + "expression_mathml": "R_mR_oR_y" + } + ], + "time": { + "id": "t", + "units": { + "expression": "day", + "expression_mathml": "day" + } + } + } + }, + "metadata": { + "annotations": { + "license": null, + "authors": [], + "references": [], + "time_scale": null, + "time_start": null, + "time_end": null, + "locations": [], + "pathogens": [], + "diseases": [], + "hosts": [], + "model_types": [] + } + } +} \ No newline at end of file diff --git a/notebooks/evaluation_2024.03/epi_scenario3/epi_eval_sc3_seir.ipynb b/notebooks/evaluation_2024.03/epi_scenario3/epi_eval_sc3_seir.ipynb new file mode 100644 index 00000000..c4717d93 --- /dev/null +++ b/notebooks/evaluation_2024.03/epi_scenario3/epi_eval_sc3_seir.ipynb @@ -0,0 +1,455 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "14d9fa23-f229-4499-889f-8b84bf790223", + "metadata": {}, + "source": [ + "# Scenario 3: Causal Reasoning with Interventions" + ] + }, + { + "cell_type": "markdown", + "id": "80f64161-69df-41c6-a014-3dcd1afbdcb3", + "metadata": {}, + "source": [ + "### Load MIRA dependencies" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "efd146e7-0742-4e39-a374-39fe931df029", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import json\n", + "import sympy\n", + "\n", + "from mira.metamodel import *\n", + "from mira.examples.concepts import susceptible, exposed, infected, recovered\n", + "from mira.modeling import Model\n", + "from mira.modeling.amr.petrinet import AMRPetriNetModel, template_model_to_petrinet_json\n", + "from mira.sources.amr.petrinet import template_model_from_amr_json\n", + "from mira.metamodel.io import model_to_json_file, model_from_json_file" + ] + }, + { + "cell_type": "markdown", + "id": "82328f7c-76da-4eb1-8241-fe0e23b58683", + "metadata": {}, + "source": [ + "## Build SEIR model" + ] + }, + { + "cell_type": "markdown", + "id": "4f42f426-67a8-4ff8-87ae-22dc95e2bbbe", + "metadata": {}, + "source": [ + "### Define units" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "f8d81322-226a-4676-a0b8-923e7220e10d", + "metadata": {}, + "outputs": [], + "source": [ + "person_units = lambda: Unit(expression=sympy.Symbol('person'))\n", + "day_units = lambda: Unit(expression=sympy.Symbol('day'))\n", + "per_day_units = lambda: Unit(expression=1/sympy.Symbol('day'))\n", + "dimensionless_units = lambda: Unit(expression=sympy.Integer('1'))\n", + "per_day_per_person_units = lambda: Unit(expression=1/(sympy.Symbol('day')*sympy.Symbol('person')))" + ] + }, + { + "cell_type": "markdown", + "id": "6900e964-edb2-4427-bab1-d2c9dcdabc82", + "metadata": {}, + "source": [ + "# Define and stratify model concepts" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "5e2c1d9f-51a9-46a4-aa06-5aa862b8b081", + "metadata": {}, + "outputs": [], + "source": [ + "_susceptible = Concept(name='S', units=person_units(), identifiers={'ido': '0000514'})\n", + "_exposed = Concept(name='E', units=person_units(), identifiers={'apollosv': '00000154'})\n", + "_infected = Concept(name='I', units=person_units(), identifiers={'ido': '0000511'})\n", + "_recovered = Concept(name='R', units=person_units(), identifiers={'ido': '0000592'})\n", + "\n", + "c = {\n", + " 'S_y': _susceptible.with_context(status=\"young\"),\n", + " 'S_m': _susceptible.with_context(status=\"middle\"),\n", + " 'S_o': _susceptible.with_context(status=\"old\"),\n", + " 'E_y': _exposed.with_context(status=\"young\"),\n", + " 'E_m': _exposed.with_context(status=\"middle\"),\n", + " 'E_o': _exposed.with_context(status=\"old\"),\n", + " 'I_y': _infected.with_context(status=\"young\"),\n", + " 'I_m': _infected.with_context(status=\"middle\"),\n", + " 'I_o': _infected.with_context(status=\"old\"),\n", + " 'R_y': _recovered.with_context(status=\"young\"),\n", + " 'R_m': _recovered.with_context(status=\"middle\"),\n", + " 'R_o': _recovered.with_context(status=\"old\"),\n", + "}\n", + "\n", + "for concept in c:\n", + " c[concept].name = concept" + ] + }, + { + "cell_type": "markdown", + "id": "4792ddd4-f7bd-43e5-8cc7-a729573b39eb", + "metadata": {}, + "source": [ + "### Define parameters with uncertainty" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "b4774d31-1ad4-4027-a82b-6bee06907e03", + "metadata": {}, + "outputs": [], + "source": [ + "# To add a small distribution around parameters (for Terarium)\n", + "def unif_distribution_create(value: float):\n", + " return Distribution(\n", + " type=\"StandardUniform1\",\n", + " parameters={\"minimum\": value, \"maximum\": value + max(0.01*value,0.1)},\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "a902e806-0dad-4bf6-a264-0172324257b0", + "metadata": {}, + "outputs": [], + "source": [ + "parameters = {\n", + " 'beta': Parameter(name='beta', value=sympy.Float(0.2), units=per_day_units(),\n", + " distribution=Distribution(type='StandardUniform1',\n", + " parameters={'minimum': 0.05,\n", + " 'maximum': 0.8})), # Infection rate\n", + " 'N': Parameter(name='total_population', value=sympy.Float(37742307.0), units=person_units()), # Total population\n", + " 'mew': Parameter(name='mew', value=sympy.Float(0.0), units=per_day_units()), # Mask efficacy\n", + " 'mcw': Parameter(name='mcw', value=sympy.Float(0.0), units=per_day_units()), # Mask compliance\n", + " 'r_EI': Parameter(name='r_EI', value=sympy.Float(0.08), units=per_day_units()), # Rate of progressing E -> I\n", + " 'r_IR': Parameter(name='r_IR', value=sympy.Float(0.06), units=per_day_units()), # Rate of progressing I -> R\n", + " 'Myy': Parameter(name='Myy', value=sympy.Float(38.62), units=per_day_units()), # Contact rate young -> young\n", + " 'Mym': Parameter(name='Mym', value=sympy.Float(20.56), units=per_day_units()), # Contact rate young -> middle\n", + " 'Myo': Parameter(name='Myo', value=sympy.Float(6.12), units=per_day_units()), # Contact rate young -> old\n", + " 'Mmy': Parameter(name='Mmy', value=sympy.Float(20.56), units=per_day_units()), # Contact rate middle -> young\n", + " 'Mmm': Parameter(name='Mmm', value=sympy.Float(28.22), units=per_day_units()), # Contact rate middle -> middle\n", + " 'Mmo': Parameter(name='Mmo', value=sympy.Float(11.6), units=per_day_units()), # Contact rate middle -> old\n", + " 'Moy': Parameter(name='Moy', value=sympy.Float(6.12), units=per_day_units()), # Contact rate old -> young\n", + " 'Mom': Parameter(name='Mom', value=sympy.Float(11.6), units=per_day_units()), # Contact rate old -> middle\n", + " 'Moo': Parameter(name='Moo', value=sympy.Float(20.01), units=per_day_units()), # Contact rate old -> old\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "e0e7b89c-8d24-42b2-afe1-e3bddf0bfc5c", + "metadata": {}, + "source": [ + "### Define variables" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "802ce5dd-9f50-43c3-8d0b-f1e7a692d7b0", + "metadata": {}, + "outputs": [], + "source": [ + "S_y, S_m, S_o, E_y, E_m, E_o, I_y, I_m, I_o, R_y, R_m, R_o, beta, N, mew, mcw, r_EI, r_IR, Myy, Mym, Myo, Mmy, Mmm, Mmo, Moy, Mom, Moo = \\\n", + " sympy.symbols(\n", + " 'S_y S_m S_o E_y E_m E_o I_y I_m I_o R_y R_m R_o beta N mew mcw r_EI r_IR Myy Mym Myo Mmy Mmm Mmo Moy Mom Moo'\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "8d3dceac-1113-4c55-92a3-3b5ab34ee960", + "metadata": {}, + "source": [ + "### Set initial values" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "f892e033-55da-44c6-b309-459dee0cae1a", + "metadata": {}, + "outputs": [], + "source": [ + "initials = {\n", + " \"S_y\": Initial(concept=c[\"S_y\"], expression=10305660.0),\n", + " \"S_m\": Initial(concept=c[\"S_m\"], expression=15281905.0),\n", + " \"S_o\": Initial(concept=c[\"S_o\"], expression=12154442.0),\n", + " \"E_y\": Initial(concept=c[\"E_y\"], expression=50.0),\n", + " \"E_m\": Initial(concept=c[\"E_m\"], expression=50.0),\n", + " \"E_o\": Initial(concept=c[\"E_o\"], expression=50.0),\n", + " \"I_y\": Initial(concept=c[\"I_y\"], expression=50.0),\n", + " \"I_m\": Initial(concept=c[\"I_m\"], expression=50.0),\n", + " \"I_o\": Initial(concept=c[\"I_o\"], expression=50.0),\n", + " \"R_y\": Initial(concept=c[\"R_y\"], expression=0.0),\n", + " \"R_m\": Initial(concept=c[\"R_m\"], expression=0.0),\n", + " \"R_o\": Initial(concept=c[\"R_o\"], expression=0.0),\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "51ea2d61-7dc7-4aa3-849e-9817708158cc", + "metadata": {}, + "source": [ + "### Define templates" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "5f186c10-7b95-4678-8737-ebca86c1f856", + "metadata": {}, + "outputs": [], + "source": [ + "##### S -> E\n", + "# Sy -> Ey by Iy\n", + "syeyiy = ControlledConversion(\n", + " subject=c['S_y'],\n", + " outcome=c['E_y'],\n", + " controller=c['I_y'],\n", + " rate_law=beta*S_y*(1 - mew*mcw)*(Myy*I_y) / N\n", + ")\n", + "# Sy -> Ey by Im\n", + "syeyim = ControlledConversion(\n", + " subject=c['S_y'],\n", + " outcome=c['E_y'],\n", + " controller=c['I_m'],\n", + " rate_law=beta*S_y*(1 - mew*mcw)*(Mym*I_m) / N\n", + ")\n", + "# Sy -> Ey by Io\n", + "syeyio = ControlledConversion(\n", + " subject=c['S_y'],\n", + " outcome=c['E_y'],\n", + " controller=c['I_o'],\n", + " rate_law=beta*S_y*(1 - mew*mcw)*(Myo*I_o) / N\n", + ")\n", + "\n", + "# Sm -> Em by Iy\n", + "smemiy = ControlledConversion(\n", + " subject=c['S_m'],\n", + " outcome=c['E_m'],\n", + " controller=c['I_y'],\n", + " rate_law=beta*S_m*(1 - mew*mcw)*(Mmy*I_y) / N\n", + ")\n", + "# Sm -> Em by Im\n", + "smemim = ControlledConversion(\n", + " subject=c['S_m'],\n", + " outcome=c['E_m'],\n", + " controller=c['I_m'],\n", + " rate_law=beta*S_m*(1 - mew*mcw)*(Mmm*I_m) / N\n", + ")\n", + "# Sm -> Em by Io\n", + "smemio = ControlledConversion(\n", + " subject=c['S_m'],\n", + " outcome=c['E_m'],\n", + " controller=c['I_o'],\n", + " rate_law=beta*S_m*(1 - mew*mcw)*(Mmo*I_o) / N\n", + ")\n", + "\n", + "# So -> Eo by Iy\n", + "soeoiy = ControlledConversion(\n", + " subject=c['S_o'],\n", + " outcome=c['E_o'],\n", + " controller=c['I_y'],\n", + " rate_law=beta*S_o*(1 - mew*mcw)*(Moy*I_y) / N\n", + ")\n", + "# So -> Eo by Im\n", + "soeoim = ControlledConversion(\n", + " subject=c['S_o'],\n", + " outcome=c['E_o'],\n", + " controller=c['I_m'],\n", + " rate_law=beta*S_o*(1 - mew*mcw)*(Mom*I_m) / N\n", + ")\n", + "# So -> Eo by Io\n", + "soeoio = ControlledConversion(\n", + " subject=c['S_o'],\n", + " outcome=c['E_o'],\n", + " controller=c['I_o'],\n", + " rate_law=beta*S_o*(1 - mew*mcw)*(Moo*I_o) / N\n", + ")\n", + "\n", + "#### E -> I\n", + "# Ey -> Iy\n", + "eyiy = NaturalConversion(\n", + " subject=c['E_y'],\n", + " outcome=c['I_y'],\n", + " rate_law=r_EI*E_y\n", + ")\n", + "# Em -> Im\n", + "emim = NaturalConversion(\n", + " subject=c['E_m'],\n", + " outcome=c['I_m'],\n", + " rate_law=r_EI*E_m\n", + ")\n", + "# Eo -> Io\n", + "eoio = NaturalConversion(\n", + " subject=c['E_o'],\n", + " outcome=c['I_o'],\n", + " rate_law=r_EI*E_o\n", + ")\n", + "\n", + "#### I -> R\n", + "# Iy -> Ry\n", + "iyry = NaturalConversion(\n", + " subject=c['I_y'],\n", + " outcome=c['R_y'],\n", + " rate_law=r_IR*I_y\n", + ")\n", + "# Im -> Rm\n", + "imrm = NaturalConversion(\n", + " subject=c['I_m'],\n", + " outcome=c['R_m'],\n", + " rate_law=r_IR*I_m\n", + ")\n", + "# Io -> Ro\n", + "ioro = NaturalConversion(\n", + " subject=c['I_o'],\n", + " outcome=c['R_o'],\n", + " rate_law=r_IR*I_o\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "a845f3f9-fe95-4931-9a4b-c3800774f940", + "metadata": {}, + "source": [ + "### Define observables" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "38e21c50-8b53-4288-a8ef-73f6e02ac63a", + "metadata": {}, + "outputs": [], + "source": [ + "observables_seir = {\n", + " 'susceptible': Observable(name='susceptible', expression=S_y+S_m+S_o),\n", + " 'exposed': Observable(name='exposed', expression=E_y+E_m+E_o),\n", + " 'infected': Observable(name='infected', expression=I_y+I_m+I_o),\n", + " 'recovered': Observable(name='recovered', expression=R_y+R_m+R_o),\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "e0a0a040-600d-45f4-bc68-be57074b6cac", + "metadata": {}, + "source": [ + "### Define template model and save as petrinet AMR" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "4c523830-dfc3-4b8a-b584-5dad7f95c729", + "metadata": {}, + "outputs": [], + "source": [ + "seir_model = TemplateModel(\n", + " templates=[\n", + " syeyiy,\n", + " syeyim,\n", + " syeyio,\n", + " smemiy,\n", + " smemim,\n", + " smemio,\n", + " soeoiy,\n", + " soeoim,\n", + " soeoio,\n", + " eyiy,\n", + " emim,\n", + " eoio,\n", + " iyry,\n", + " imrm,\n", + " ioro,\n", + " ],\n", + " parameters=parameters,\n", + " initials=initials,\n", + " time=Time(name='t', units=day_units()),\n", + " observables=observables_seir,\n", + " annotations=Annotations(name='SEIR Scenario 3')\n", + ")\n", + "\n", + "# Save as JSON\n", + "with open(\"SEIR_scenario3_petrinet.json\", 'w') as fh:\n", + " json.dump(template_model_to_petrinet_json(seir_model), fh, indent=1)" + ] + }, + { + "cell_type": "markdown", + "id": "cedfa54c-a1c6-4eb5-9674-9ac17d823fb3", + "metadata": {}, + "source": [ + "## Change parameter values and uncertainty from the AMR" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "12219f8d-566f-466d-b35e-6bb70af5cea7", + "metadata": {}, + "outputs": [], + "source": [ + "filename = \"SEIR_scenario3_petrinet.json\"\n", + "with open(filename, 'r') as fh:\n", + " tm = template_model_from_amr_json(json.load(fh))\n", + "\n", + "# Change `Myy` parameter value\n", + "tm.parameters[\"Myy\"].value = 50.0\n", + "\n", + "# Change `Myy` distribution\n", + "tm.parameters[\"Myy\"].distribution = Distribution(type='StandardUniform1',\n", + " parameters={'minimum': 40.0, 'maximum': 80.0})\n", + "\n", + "# Save as updated AMR\n", + "with open('update_parameters_example.json', 'w') as fh:\n", + " json.dump(template_model_to_petrinet_json(tm), fh, indent=1)" + ] + } + ], + "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.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}