From ec93304079425cadadf230dc508916549f555049 Mon Sep 17 00:00:00 2001 From: Rashmil Panchani Date: Mon, 6 Jan 2025 11:53:33 -0600 Subject: [PATCH 1/2] add notebook --- notebooks/galveston_community_app.ipynb | 24 +- notebooks/ml_enabled_galveston_cge.ipynb | 1341 ++++++++++++++++++++++ notebooks/ml_enabled_slc_cge.ipynb | 2 +- 3 files changed, 1354 insertions(+), 13 deletions(-) create mode 100644 notebooks/ml_enabled_galveston_cge.ipynb diff --git a/notebooks/galveston_community_app.ipynb b/notebooks/galveston_community_app.ipynb index 46a4bff1..05e664c2 100644 --- a/notebooks/galveston_community_app.ipynb +++ b/notebooks/galveston_community_app.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "957d73f9", "metadata": {}, "outputs": [], @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "39b41540", "metadata": {}, "outputs": [], @@ -137,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "58b1565c", "metadata": {}, "outputs": [], @@ -175,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "bfb2b053", "metadata": {}, "outputs": [], @@ -214,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "ef7f95aa", "metadata": {}, "outputs": [], @@ -337,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "ed824b73", "metadata": {}, "outputs": [], @@ -405,7 +405,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "da807655", "metadata": {}, "outputs": [], @@ -419,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "46ed6e01", "metadata": {}, "outputs": [], @@ -530,7 +530,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "dbd1a228", "metadata": {}, "outputs": [], @@ -690,7 +690,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "cf28d307", "metadata": {}, "outputs": [], @@ -781,7 +781,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "incore", "language": "python", "name": "python3" }, @@ -795,7 +795,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.19" + "version": "3.11.6" } }, "nbformat": 4, diff --git a/notebooks/ml_enabled_galveston_cge.ipynb b/notebooks/ml_enabled_galveston_cge.ipynb new file mode 100644 index 00000000..9602a460 --- /dev/null +++ b/notebooks/ml_enabled_galveston_cge.ipynb @@ -0,0 +1,1341 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from pyincore import IncoreClient\n", + "from pyincore.analyses.mlenabledcgegalveston import MlEnabledCgeGalveston\n", + "from pyincore import globals as pyglobals\n", + "\n", + "# Supress default INFO logging\n", + "\n", + "import logging\n", + "\n", + "logger = pyglobals.LOGGER\n", + "logger.setLevel(logging.CRITICAL)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Connection successful to IN-CORE services. pyIncore version detected: 1.20.1\n" + ] + } + ], + "source": [ + "client = IncoreClient()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "sector_shocks = \"643adeb634810d74880e7bd5\" # This is the aggregation of building functionality states to capital shocks per sector." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# Create Machine Learning Enabled CGE Salt Lake City Model\n", + "ml_enabled_cge = MlEnabledCgeGalveston(client)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Set analysis input datasets\n", + "ml_enabled_cge.load_remote_input_dataset(\"sector_shocks\", sector_shocks)\n", + "\n", + "# Optional parameters for file naming\n", + "ml_enabled_cge.set_parameter(\"result_name\", \"test_galveston_mlcge_result\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Run Galveston city CGE model analysis\n", + "ml_enabled_cge.run_analysis()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
SectorsDS0DSL
0IAGMIN26.06444825.401881
1IUTIL84.81370181.456728
2ICONS291.795770268.448117
3IMANU440.355302425.729920
4IWHOLE64.65338558.659894
5IRETAIL356.863762300.725250
\n", + "
" + ], + "text/plain": [ + " Sectors DS0 DSL\n", + "0 IAGMIN 26.064448 25.401881\n", + "1 IUTIL 84.813701 81.456728\n", + "2 ICONS 291.795770 268.448117\n", + "3 IMANU 440.355302 425.729920\n", + "4 IWHOLE 64.653385 58.659894\n", + "5 IRETAIL 356.863762 300.725250" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "domestic_supply = ml_enabled_cge.get_output_dataset(\"domestic-supply\")\n", + "ds = domestic_supply.get_dataframe_from_csv()\n", + "# Display top 6 rows of output data\n", + "ds.head(6)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Household GroupY0YL
0HH1WI4.1825514.025747
1HH2WI27.75511725.159567
2HH3WI132.402541119.902432
3HH4WI528.592326467.634796
4HH5WI661.228690551.756431
\n", + "
" + ], + "text/plain": [ + " Household Group Y0 YL\n", + "0 HH1WI 4.182551 4.025747\n", + "1 HH2WI 27.755117 25.159567\n", + "2 HH3WI 132.402541 119.902432\n", + "3 HH4WI 528.592326 467.634796\n", + "4 HH5WI 661.228690 551.756431" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gross_income = ml_enabled_cge.get_output_dataset(\"gross-income\")\n", + "gi = gross_income.get_dataframe_from_csv()\n", + "gi.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Labor GroupIAGMIN_WIIAGMIN_BIIAGMIN_HIIUTIL_WIIUTIL_BIIUTIL_HIICONS_WIICONS_BIICONS_HIIMANU_WIIMANU_BIIMANU_HIIWHOLE_WIIWHOLE_BIIWHOLE_HIIRETAIL_WIIRETAIL_BIIRETAIL_HIITRANS_WIITRANS_BIITRANS_HIIPROFSER_WIIPROFSER_BIIPROFSER_HIIREALE_WIIREALE_BIIREALE_HIIEDU_WIIEDU_BIIEDU_HIIHEALTH_WIIHEALTH_BIIHEALTH_HIIART_WIIART_BIIART_HIIACCO_WIIACCO_BIIACCO_HI...FED_BIMCONS_HMMPROFSER_WMMMANU_HMSTATE_WIMMANU_WMMEDU_WMMUTIL_HMMACCO_HMMAGMIN_WMMEDU_BMMWHOLE_WMMACCO_WMMAGMIN_HMMTRANS_WMSTATE_BMMUTIL_WMMCONS_WMMART_WMCOUNTY_BIMRETAIL_BMSTATE_HIMRETAIL_WMCOUNTY_WIMHEALTH_HMMEDU_HMMWHOLE_BMFED_WMCOUNTY_BMMMANU_BMFED_BMMUTIL_BMCOUNTY_HMFED_WISTATE_HMFED_HMCOUNTY_WMMREALE_BMMART_BMMAGMIN_BM
0L17.04.04.0-1.0-1.05.085.0-1.034.08.0-1.07.037.0-1.0-1.0532.072.0290.0112.035.012.0464.0174.0277.024.0-1.014.0811.0249.0738.0147.0132.0125.0424.0-1.0449.01947.0379.01295.0...-1.0230.01423.090.03.0106.0818.015.01954.031.0253.0253.02938.019.059.0-1.0-1.0573.0360.0-1.0326.02.02401.03.0344.0746.0-1.0-1.0-1.0-1.0-1.0-1.04.0-1.04.0-1.06.0-1.0-1.017.0
1L2-1.0-1.09.03.0-1.065.0121.022.0127.044.0-1.029.074.0-1.0-1.0371.0430.0123.0511.0140.079.0534.0155.0376.081.048.04.01832.0606.0561.0256.0306.0161.0179.0115.025.0350.0420.01193.0...3.0861.01638.0385.042.0580.01850.0219.01799.0-1.0609.0496.0527.044.0271.068.010.0818.0152.037.01943.08.01675.045.0443.0567.0-1.06.073.0-1.05.0-1.018.03.016.01.089.087.098.0-1.0
2L339.0-1.014.040.011.026.0131.07.0237.0128.028.026.059.036.029.0131.044.025.0474.0226.0289.01131.0171.0130.0121.0-1.0212.05387.0467.01325.0825.0206.0222.0126.0-1.098.0352.0-1.055.0...3.01606.03469.0354.0147.01717.05438.087.084.0178.0472.0401.0532.062.0252.071.0135.0889.0106.038.0198.042.0590.0158.0612.01340.0245.022.077.0378.05.036.091.011.084.07.0313.0-1.0-1.0-1.0
3L449.07.010.027.0-1.0-1.097.02.099.0147.010.032.075.0-1.0-1.0104.053.030.0175.051.0-1.0694.094.0174.081.0-1.0-1.01214.0312.0-1.0297.046.0119.0-1.0-1.0-1.08.0-1.0-1.0...2.0669.02128.0432.061.01963.01227.0-1.0-1.0223.0315.0513.012.045.093.044.090.0662.0-1.024.0239.0-1.0468.066.0328.0-1.0-1.09.048.0140.03.0-1.0-1.05.0-1.0-1.0131.0-1.0-1.032.0
\n", + "

4 rows × 97 columns

\n", + "
" + ], + "text/plain": [ + " Labor Group IAGMIN_WI IAGMIN_BI ... MREALE_BM MART_BM MAGMIN_BM\n", + "0 L1 7.0 4.0 ... -1.0 -1.0 17.0\n", + "1 L2 -1.0 -1.0 ... 87.0 98.0 -1.0\n", + "2 L3 39.0 -1.0 ... -1.0 -1.0 -1.0\n", + "3 L4 49.0 7.0 ... -1.0 -1.0 32.0\n", + "\n", + "[4 rows x 97 columns]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pre_factor_demand = ml_enabled_cge.get_output_dataset(\"pre-disaster-factor-demand\")\n", + "pre_fd = pre_factor_demand.get_dataframe_from_csv()\n", + "pre_fd.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Labor GroupIAGMIN_WIIAGMIN_BIIAGMIN_HIIUTIL_WIIUTIL_BIIUTIL_HIICONS_WIICONS_BIICONS_HIIMANU_WIIMANU_BIIMANU_HIIWHOLE_WIIWHOLE_BIIWHOLE_HIIRETAIL_WIIRETAIL_BIIRETAIL_HIITRANS_WIITRANS_BIITRANS_HIIPROFSER_WIIPROFSER_BIIPROFSER_HIIREALE_WIIREALE_BIIREALE_HIIEDU_WIIEDU_BIIEDU_HIIHEALTH_WIIHEALTH_BIIHEALTH_HIIART_WIIART_BIIART_HIIACCO_WIIACCO_BIIACCO_HI...FED_BIMCONS_HMMPROFSER_WMMMANU_HMSTATE_WIMMANU_WMMEDU_WMMUTIL_HMMACCO_HMMAGMIN_WMMEDU_BMMWHOLE_WMMACCO_WMMAGMIN_HMMTRANS_WMSTATE_BMMUTIL_WMMCONS_WMMART_WMCOUNTY_BIMRETAIL_BMSTATE_HIMRETAIL_WMCOUNTY_WIMHEALTH_HMMEDU_HMMWHOLE_BMFED_WMCOUNTY_BMMMANU_BMFED_BMMUTIL_BMCOUNTY_HMFED_WISTATE_HMFED_HMCOUNTY_WMMREALE_BMMART_BMMAGMIN_BM
0L16.9194773.9544153.951989-1.000000-1.0000005.13529483.409028-1.00000033.3125838.164245-1.0000007.13999637.055278-1.000000-1.000000520.49312270.490355283.240339109.87058634.38347911.811113456.948020171.272427272.31476522.608114-1.0000013.196686794.706693243.754900721.725456143.751621128.954759122.027959414.938125-1.000000438.5126101875.163384364.7019881244.799476...-1.0230.01423.090.03.0106.0818.015.01954.031.0253.0253.02938.019.059.0-1.0-1.0573.0360.0-1.0326.02.02401.03.0344.0746.0-1.0-1.0-1.0-1.0-1.0-1.04.0-1.04.0-1.06.0-1.0-1.017.0
1L2-1.000000-1.0000008.8893423.095229-1.00000065.934002118.29751021.532137124.60238644.327897-1.00000029.35631573.902682-1.000000-1.000000361.707187419.289069120.438165498.953783136.83607377.534641523.994299152.233496370.27542975.78778544.956873.8078071788.523202591.786718549.652359249.358478298.054837157.412999174.741813112.32540324.593196335.964388403.1980761148.886593...3.0861.01638.0385.042.0580.01850.0219.01799.0-1.0609.0496.0527.044.0271.068.010.0818.0152.037.01943.08.01675.045.0443.0567.0-1.06.073.0-1.05.0-1.018.03.016.01.089.087.098.0-1.0
2L338.204932-1.00000013.80622940.39997411.12599926.405350127.7795576.814676232.082152128.37797528.02656426.29037958.78395035.64778228.987857127.51427442.66801824.530910461.747211218.955096282.8050281106.854311166.525262127.944948112.882298-1.00000198.4685675246.062152452.1407581295.873104801.188003198.991151216.653146122.783913-1.00000095.952541337.092828-1.00000052.991524...3.01606.03469.0354.0147.01717.05438.087.084.0178.0472.0401.0532.062.0252.071.0135.0889.0106.038.0198.042.0590.0158.0612.01340.0245.022.077.0378.05.036.091.011.084.07.0313.0-1.0-1.0-1.0
3L448.0729026.8448279.80959827.387054-1.000000-1.00000094.8866051.94659796.398064147.84173610.05942332.14044574.933684-1.000000-1.000000101.55040451.25656529.233224171.09179249.441359-1.000000681.25791691.415503170.16635375.828335-1.00000-1.0000001185.812202301.413025-1.000000289.38707944.472489115.507145-1.000000-1.000000-1.0000007.740084-1.000000-1.000000...2.0669.02128.0432.061.01963.01227.0-1.0-1.0223.0315.0513.012.045.093.044.090.0662.0-1.024.0239.0-1.0468.066.0328.0-1.0-1.09.048.0140.03.0-1.0-1.05.0-1.0-1.0131.0-1.0-1.032.0
\n", + "

4 rows × 97 columns

\n", + "
" + ], + "text/plain": [ + " Labor Group IAGMIN_WI IAGMIN_BI ... MREALE_BM MART_BM MAGMIN_BM\n", + "0 L1 6.919477 3.954415 ... -1.0 -1.0 17.0\n", + "1 L2 -1.000000 -1.000000 ... 87.0 98.0 -1.0\n", + "2 L3 38.204932 -1.000000 ... -1.0 -1.0 -1.0\n", + "3 L4 48.072902 6.844827 ... -1.0 -1.0 32.0\n", + "\n", + "[4 rows x 97 columns]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "post_factor_demand = ml_enabled_cge.get_output_dataset(\"post-disaster-factor-demand\")\n", + "pos_fd = post_factor_demand.get_dataframe_from_csv()\n", + "pos_fd.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Household GroupHH0HHL
0HH1WI655.0650.860310
1HH2WI1195.01182.226953
2HH3WI2618.02585.294201
3HH4WI4114.04044.787173
4HH5WI3321.03216.563992
\n", + "
" + ], + "text/plain": [ + " Household Group HH0 HHL\n", + "0 HH1WI 655.0 650.860310\n", + "1 HH2WI 1195.0 1182.226953\n", + "2 HH3WI 2618.0 2585.294201\n", + "3 HH4WI 4114.0 4044.787173\n", + "4 HH5WI 3321.0 3216.563992" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "household_count = ml_enabled_cge.get_output_dataset(\"household-count\")\n", + "hc = household_count.get_dataframe_from_csv()\n", + "hc.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "incore", + "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.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/ml_enabled_slc_cge.ipynb b/notebooks/ml_enabled_slc_cge.ipynb index eced3f5d..5150bd3b 100644 --- a/notebooks/ml_enabled_slc_cge.ipynb +++ b/notebooks/ml_enabled_slc_cge.ipynb @@ -774,7 +774,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "incore", "language": "python", "name": "python3" }, From a22fba0c8b02a92238b00864585b41d98985df26 Mon Sep 17 00:00:00 2001 From: Rashmil Panchani Date: Mon, 6 Jan 2025 12:01:34 -0600 Subject: [PATCH 2/2] add documentation --- CHANGELOG.md | 6 ++ manual_jb/content/_toc.yml | 1 + manual_jb/content/analyses.md | 51 ++++++++-------- .../content/analyses/ml_galveston_cge.md | 59 +++++++++++++++++++ 4 files changed, 92 insertions(+), 25 deletions(-) create mode 100644 manual_jb/content/analyses/ml_galveston_cge.md diff --git a/CHANGELOG.md b/CHANGELOG.md index f79de28d..d3106d35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to the INCORE documents generated by Sphinx package will be The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] + +### Added +- ML enabled Galveston CGE notebook [#437](https://github.com/IN-CORE/incore-docs/issues/437) + ## [4.14.0] - 2024-10-23 ### Added diff --git a/manual_jb/content/_toc.yml b/manual_jb/content/_toc.yml index 7a55ac71..c5a752f5 100644 --- a/manual_jb/content/_toc.yml +++ b/manual_jb/content/_toc.yml @@ -42,6 +42,7 @@ chapters: - file: analyses/joplin_empirical_restoration - file: analyses/mean_dmg - file: analyses/mc_limit_state_prob + - file: analyses/ml_galveston_cge - file: analyses/ml_joplin_cge - file: analyses/ml_slc_cge - file: analyses/multi_retrofit_optimization diff --git a/manual_jb/content/analyses.md b/manual_jb/content/analyses.md index 73f34832..2147f1bf 100644 --- a/manual_jb/content/analyses.md +++ b/manual_jb/content/analyses.md @@ -26,28 +26,29 @@ 24. [Interdependent Network Design Problem](analyses/indp) 25. [Joplin Computable General Equilibrium (CGE)](analyses/joplin_cge) 26. [Joplin empirical building restoration](analyses/joplin_empirical_building_restoration) -27. [Machine Learning Enabled Computable General Equilibrium (CGE) - Joplin](analyses/ml_joplin_cge.md) -28. [Machine Learning Enabled Computable General Equilibrium (CGE) - Salt Lake City](analyses/ml_slc_cge.md) -29. [Mean damage](analyses/mean_dmg) -30. [Monte Carlo limit state probability](analyses/mc_limit_state_prob) -31. [Multi-objective retrofit optimization](analyses/multi_retrofit_optimization) -32. [Network cascading interdependency functionality](analyses/nci_functionality) -33. [Pipeline damage](analyses/pipeline_dmg) -34. [Pipeline damage with repair rate](analyses/pipeline_dmg_w_repair_rate) -35. [Pipeline functionality](analyses/pipeline_functionality) -36. [Pipeline repair cost](analyses/pipeline_repair_cost) -37. [Pipeline restoration](analyses/pipeline_restoration) -38. [Population dislocation](analyses/populationdislocation) -39. [Residential building recovery](analyses/residential_building_recovery) -40. [Road damage](analyses/road_dmg) -41. [Salt Lake City Computable General Equilibrium (CGE)](analyses/slc_cge.md) -42. [Seaside Computable General Equilibrium (CGE)](analyses/seaside_cge) -43. [Social Vulnerability](analyses/social_vulnerability) -44. [Social Vulnerability Score](analyses/social_vulnerability_score) -45. [Tornado electric power network (EPN) damage](analyses/tornadoepn_dmg) -46. [Traffic flow recovery](analyses/traffic_flow_recovery) -47. [Transportation recovery](analyses/transportation_recovery) -48. [Water facility damage](analyses/waterfacility_dmg) -49. [Water network functionality](analyses/wfn_functionality) -50. [Water facility repair cost](analyses/water_facility_repair_cost) -51. [Water facility restoration](analyses/water_facility_restoration) +27. [Machine Learning Enabled Computable General Equilibrium (CGE) - Galveston](analyses/ml_galveston_cge.md) +28. [Machine Learning Enabled Computable General Equilibrium (CGE) - Joplin](analyses/ml_joplin_cge.md) +29. [Machine Learning Enabled Computable General Equilibrium (CGE) - Salt Lake City](analyses/ml_slc_cge.md) +30. [Mean damage](analyses/mean_dmg) +31. [Monte Carlo limit state probability](analyses/mc_limit_state_prob) +32. [Multi-objective retrofit optimization](analyses/multi_retrofit_optimization) +33. [Network cascading interdependency functionality](analyses/nci_functionality) +34. [Pipeline damage](analyses/pipeline_dmg) +35. [Pipeline damage with repair rate](analyses/pipeline_dmg_w_repair_rate) +36. [Pipeline functionality](analyses/pipeline_functionality) +37. [Pipeline repair cost](analyses/pipeline_repair_cost) +38. [Pipeline restoration](analyses/pipeline_restoration) +39. [Population dislocation](analyses/populationdislocation) +40. [Residential building recovery](analyses/residential_building_recovery) +41. [Road damage](analyses/road_dmg) +42. [Salt Lake City Computable General Equilibrium (CGE)](analyses/slc_cge.md) +43. [Seaside Computable General Equilibrium (CGE)](analyses/seaside_cge) +44. [Social Vulnerability](analyses/social_vulnerability) +45. [Social Vulnerability Score](analyses/social_vulnerability_score) +46. [Tornado electric power network (EPN) damage](analyses/tornadoepn_dmg) +47. [Traffic flow recovery](analyses/traffic_flow_recovery) +48. [Transportation recovery](analyses/transportation_recovery) +49. [Water facility damage](analyses/waterfacility_dmg) +50. [Water network functionality](analyses/wfn_functionality) +51. [Water facility repair cost](analyses/water_facility_repair_cost) +52. [Water facility restoration](analyses/water_facility_restoration) diff --git a/manual_jb/content/analyses/ml_galveston_cge.md b/manual_jb/content/analyses/ml_galveston_cge.md new file mode 100644 index 00000000..190363b2 --- /dev/null +++ b/manual_jb/content/analyses/ml_galveston_cge.md @@ -0,0 +1,59 @@ +# Machine Learning Enabled Computable General Equilibrium (CGE) - Galveston + +**Description** + +The "Machine Learning Enabled Computable General Equilibrium (CGE) - Galveston" analysis merges advanced machine learning with traditional CGE models to offer unprecedented insights into the economic impacts of disaster scenarios on Joplin. Trained on a comprehensive dataset of numerous simulated disasters and their economic effects, this hybrid approach excels in predicting the intricate dynamics of the city's economy under various crises. + +A computable general equilibrium (CGE) model is based on fundamental economic principles. A CGE model uses multiple data sources to reflect the interactions of households, firms, and relevant government entities as they contribute to economic activity. The model is based on (1) utility-maximizing households that supply labor and capital, using the proceeds to pay for goods and services (both locally produced and imported) and taxes; (2) the production sector, with perfectly competitive, profit-maximizing firms using intermediate inputs, capital, land, and labor to produce goods and services for both domestic consumption and export; (3) the government sector that collects taxes and uses tax revenues in order to finance the provision of public services; and (4) the rest of the world. + +The output of this analysis are CSV files with domestic supply, gross income, before- and post-disaster factor demand and household count. + +**Contributors** + +- Science: Charles Nicholson, Nushra Zannat, Hwayoung Jeon, Tao Lu, Harvey Cutler, Anita Pena +- Implementation: NCSA IN-CORE Dev Team + + +**Input parameters** + +key name | type | name | description +--- | --- | --- | --- +`result_name` | `str` | Output File Name prefix | Sets the file name prefix for output files. + +**Input datasets** + +key name | type | name | description +--- | --- | --- | --- +`sector_shocks` * | [`incore:capitalShocks`](https://incore.ncsa.illinois.edu/semantics/api/types/incore:capitalShocks) | Capital shocks | Building states to capital
shocks per sector. + +**Output datasets** + +key name | type | name | description +--- | --- | --- | --- +`domestic-supply` * | [`incore:Employment`](https://incore.ncsa.illinois.edu/semantics/api/types/incore:Employment) | Supply results | A dataset containing domestic supply results (format: CSV). +`gross-income` * | [`incore:Employment`](https://incore.ncsa.illinois.edu/semantics/api/types/incore:Employment) | Gross income | A dataset of resulting gross income (format: CSV). +`pre-disaster-factor-demand` * | [`incore:FactorDemand`](https://incore.ncsa.illinois.edu/semantics/api/types/incore:FactorDemand) | Factor demand | A dataset of factor demand before disaster (format: CSV). +`post-disaster-factor-demand` * | [`incore:FactorDemand`](https://incore.ncsa.illinois.edu/semantics/api/types/incore:FactorDemand) | Factor demand | A dataset of factor demand after disaster (format: CSV). +`household-count` * | [`incore:HouseholdCount`](https://incore.ncsa.illinois.edu/semantics/api/types/incore:HouseholdCount) | Household count | A dataset of household count (format: CSV). + +(* required) + +**Execution** + +code snippet: + +``` + # Create Machine Learning Enabled CGE Galveston Model + mlcgegalveston = MlEnabledCgeGalveston(client) + + # Set analysis input datasets + mlcgegalveston.load_remote_input_dataset("sector_shocks", sector_shocks) + + # Optional parameters for file naming + mlcgegalveston.set_parameter("result_name", "test_galveston_mlcge_result") + + # Run Galveston CGE model analysis + mlcgegalveston.run_analysis() +``` + +full analysis: [ml_enabled_jgalveston_cge.ipynb](https://github.com/IN-CORE/incore-docs/blob/main/notebooks/ml_enabled_galveston_cge.ipynb)