|
748 | 748 | "</div>" |
749 | 749 | ], |
750 | 750 | "text/plain": [ |
751 | | - " country region_id cal_region2 year EM_ID ibtracsID \n", |
752 | | - "326 MEX 484 NA1 2010 2010-0260 2010176N16278 \\\n", |
| 751 | + " country region_id cal_region2 year EM_ID ibtracsID \\\n", |
| 752 | + "326 MEX 484 NA1 2010 2010-0260 2010176N16278 \n", |
753 | 753 | "331 ATG 28 NA1 2010 2010-0468 2010236N12341 \n", |
754 | 754 | "334 MEX 484 NA1 2010 2010-0494 2010257N16282 \n", |
755 | 755 | "339 LCA 662 NA1 2010 2010-0571 2010302N09306 \n", |
|
777 | 777 | "464 DOM 214 NA1 2017 2017-0383 2017260N12310 \n", |
778 | 778 | "465 PRI 630 NA1 2017 2017-0383 2017260N12310 \n", |
779 | 779 | "\n", |
780 | | - " emdat_impact reference_year emdat_impact_scaled climada_impact ... \n", |
781 | | - "326 2.000000e+09 2014 2.485465e+09 2.478270e+09 ... \\\n", |
| 780 | + " emdat_impact reference_year emdat_impact_scaled climada_impact ... \\\n", |
| 781 | + "326 2.000000e+09 2014 2.485465e+09 2.478270e+09 ... \n", |
782 | 782 | "331 1.260000e+07 2014 1.394594e+07 1.402875e+07 ... \n", |
783 | 783 | "334 3.900000e+09 2014 4.846656e+09 4.857140e+09 ... \n", |
784 | 784 | "339 5.000000e+05 2014 5.486675e+05 5.492871e+05 ... \n", |
|
806 | 806 | "464 6.300000e+07 2014 5.481371e+07 5.493466e+07 ... \n", |
807 | 807 | "465 6.800000e+10 2014 6.700905e+10 6.702718e+10 ... \n", |
808 | 808 | "\n", |
809 | | - " scale log_ratio unique_ID Associated_disaster Surge Rain Flood \n", |
810 | | - "326 1.0 -0.002899 2010-0260MEX True False False True \\\n", |
| 809 | + " scale log_ratio unique_ID Associated_disaster Surge Rain Flood \\\n", |
| 810 | + "326 1.0 -0.002899 2010-0260MEX True False False True \n", |
811 | 811 | "331 1.0 0.005920 2010-0468ATG True False False True \n", |
812 | 812 | "334 1.0 0.002161 2010-0494MEX True False False True \n", |
813 | 813 | "339 1.0 0.001129 2010-0571LCA True False False True \n", |
|
1251 | 1251 | "</div>" |
1252 | 1252 | ], |
1253 | 1253 | "text/plain": [ |
1254 | | - "region_id 484 28 662 670 \n", |
| 1254 | + "region_id 484 28 662 670 \\\n", |
1255 | 1255 | "ibtracsID \n", |
1256 | | - "2010176N16278 2.485465e+09 0.000000e+00 0.0000 0.00 \\\n", |
| 1256 | + "2010176N16278 2.485465e+09 0.000000e+00 0.0000 0.00 \n", |
1257 | 1257 | "2010236N12341 0.000000e+00 1.394594e+07 0.0000 0.00 \n", |
1258 | 1258 | "2010257N16282 4.846656e+09 0.000000e+00 0.0000 0.00 \n", |
1259 | 1259 | "2010302N09306 0.000000e+00 0.000000e+00 548667.5019 26706058.15 \n", |
|
1271 | 1271 | "2017242N16333 0.000000e+00 2.111764e+08 0.0000 0.00 \n", |
1272 | 1272 | "2017260N12310 0.000000e+00 0.000000e+00 0.0000 0.00 \n", |
1273 | 1273 | "\n", |
1274 | | - "region_id 44 214 630 388 \n", |
| 1274 | + "region_id 44 214 630 388 \\\n", |
1275 | 1275 | "ibtracsID \n", |
1276 | | - "2010176N16278 0.000000e+00 0.00 0.000000e+00 0.00 \\\n", |
| 1276 | + "2010176N16278 0.000000e+00 0.00 0.000000e+00 0.00 \n", |
1277 | 1277 | "2010236N12341 0.000000e+00 0.00 0.000000e+00 0.00 \n", |
1278 | 1278 | "2010257N16282 0.000000e+00 0.00 0.000000e+00 0.00 \n", |
1279 | 1279 | "2010302N09306 0.000000e+00 0.00 0.000000e+00 0.00 \n", |
|
1291 | 1291 | "2017242N16333 1.801876e+06 0.00 0.000000e+00 0.00 \n", |
1292 | 1292 | "2017260N12310 0.000000e+00 54813712.03 6.700905e+10 0.00 \n", |
1293 | 1293 | "\n", |
1294 | | - "region_id 132 192 659 796 \n", |
| 1294 | + "region_id 132 192 659 796 \\\n", |
1295 | 1295 | "ibtracsID \n", |
1296 | | - "2010176N16278 0.000 0.000000e+00 0.00 0.0 \\\n", |
| 1296 | + "2010176N16278 0.000 0.000000e+00 0.00 0.0 \n", |
1297 | 1297 | "2010236N12341 0.000 0.000000e+00 0.00 0.0 \n", |
1298 | 1298 | "2010257N16282 0.000 0.000000e+00 0.00 0.0 \n", |
1299 | 1299 | "2010302N09306 0.000 0.000000e+00 0.00 0.0 \n", |
|
1419 | 1419 | "name": "stdout", |
1420 | 1420 | "output_type": "stream", |
1421 | 1421 | "text": [ |
1422 | | - "2023-06-09 12:52:52,649 - climada.hazard.tc_tracks - WARNING - The cached IBTrACS data set dates from 2022-03-08 23:23:51 (older than 180 days). Very likely, a more recent version is available. Consider manually removing the file /Users/ldr.riedel/climada/data/IBTrACS.ALL.v04r00.nc and re-running this function, which will download the most recent version of the IBTrACS data set from the official URL.\n" |
| 1422 | + "2023-06-13 16:36:05,304 - climada.hazard.tc_tracks - WARNING - The cached IBTrACS data set dates from 2022-03-08 23:23:51 (older than 180 days). Very likely, a more recent version is available. Consider manually removing the file /Users/ldr.riedel/climada/data/IBTrACS.ALL.v04r00.nc and re-running this function, which will download the most recent version of the IBTrACS data set from the official URL.\n" |
1423 | 1423 | ] |
1424 | 1424 | }, |
1425 | 1425 | { |
|
1534 | 1534 | "import numpy as np\n", |
1535 | 1535 | "from climada.engine import Impact\n", |
1536 | 1536 | "\n", |
| 1537 | + "# TODO: Dont\n", |
1537 | 1538 | "# Make sure that Hazard.event_id matches indexes of 'data'\n", |
1538 | | - "hazard.event_id = np.asarray(hazard.event_name)\n", |
| 1539 | + "# hazard.event_id = np.asarray(hazard.event_name)\n", |
1539 | 1540 | "\n", |
1540 | 1541 | "def cost_rmse(impact: Impact, data: pd.DataFrame):\n", |
1541 | 1542 | " \"\"\"A cost function computing the RMSE\"\"\"\n", |
|
1624 | 1625 | " cost_func=cost_rmse,\n", |
1625 | 1626 | " impact_func_gen=impact_func_tc,\n", |
1626 | 1627 | " bounds=bounds,\n", |
| 1628 | + " align=False,\n", |
1627 | 1629 | ")\n", |
| 1630 | + "exposure.assign_centroids(hazard)\n", |
1628 | 1631 | "\n", |
1629 | 1632 | "# Create and run the optimizer\n", |
1630 | 1633 | "opt = BayesianOptimizer(input)\n", |
1631 | | - "output = opt.run()\n", |
1632 | | - "output.params # The optimal parameters" |
| 1634 | + "bayesian_output = opt.run()\n", |
| 1635 | + "bayesian_output.params # The optimal parameters" |
1633 | 1636 | ] |
1634 | 1637 | }, |
1635 | 1638 | { |
|
1670 | 1673 | } |
1671 | 1674 | ], |
1672 | 1675 | "source": [ |
1673 | | - "from climada.entity import ImpfTropCyclone\n", |
1674 | | - "\n", |
1675 | | - "ImpfTropCyclone.from_emanuel_usa(**output.params).plot()" |
| 1676 | + "impact_func_tc(**bayesian_output.params).plot()" |
1676 | 1677 | ] |
1677 | 1678 | }, |
1678 | 1679 | { |
|
1683 | 1684 | "The Bayesian Optimizer returns the entire paramter space it sampled.\n", |
1684 | 1685 | "We can find out a lot about the relation of the fitted parameters by investigating how the target function value depends on them.\n", |
1685 | 1686 | "Since we only calibrated two values, we can plot them in a scatter plot.\n", |
1686 | | - "To that end, retrieving the parameter space data via `BayesianOptimizerOutput.param_space_to_dataframe` will help.\n", |
| 1687 | + "To that end, retrieving the parameter space data via `BayesianOptimizerOutput.p_space_to_dataframe` will help.\n", |
1687 | 1688 | "Notice that the optimal parameter set is not necessarily the last entry in the parameter space!" |
1688 | 1689 | ] |
1689 | 1690 | }, |
|
1717 | 1718 | " <th>v_half</th>\n", |
1718 | 1719 | " <th>target</th>\n", |
1719 | 1720 | " </tr>\n", |
| 1721 | + " <tr>\n", |
| 1722 | + " <th>Iteration</th>\n", |
| 1723 | + " <th></th>\n", |
| 1724 | + " <th></th>\n", |
| 1725 | + " <th></th>\n", |
| 1726 | + " </tr>\n", |
1720 | 1727 | " </thead>\n", |
1721 | 1728 | " <tbody>\n", |
1722 | 1729 | " <tr>\n", |
|
1791 | 1798 | "</div>" |
1792 | 1799 | ], |
1793 | 1800 | "text/plain": [ |
1794 | | - " scale v_half target\n", |
1795 | | - "0 0.422852 115.236335 2.405716e-10\n", |
1796 | | - "1 0.010113 63.279939 2.280614e-10\n", |
1797 | | - "2 0.155288 37.177687 3.057439e-10\n", |
1798 | | - "3 0.194398 68.653198 2.637483e-10\n", |
1799 | | - "4 0.402800 92.674920 2.571778e-10\n", |
1800 | | - ".. ... ... ...\n", |
1801 | | - "195 0.980632 47.015299 3.576957e-10\n", |
1802 | | - "196 0.943001 147.501934 2.396817e-10\n", |
1803 | | - "197 0.999377 70.913361 6.412774e-10\n", |
1804 | | - "198 0.997574 64.547339 9.480593e-10\n", |
1805 | | - "199 0.982757 39.948848 2.226480e-10\n", |
| 1801 | + " scale v_half target\n", |
| 1802 | + "Iteration \n", |
| 1803 | + "0 0.422852 115.236335 2.405716e-10\n", |
| 1804 | + "1 0.010113 63.279939 2.280614e-10\n", |
| 1805 | + "2 0.155288 37.177687 3.057439e-10\n", |
| 1806 | + "3 0.194398 68.653198 2.637483e-10\n", |
| 1807 | + "4 0.402800 92.674920 2.571778e-10\n", |
| 1808 | + "... ... ... ...\n", |
| 1809 | + "195 0.980632 47.015299 3.576957e-10\n", |
| 1810 | + "196 0.943001 147.501934 2.396817e-10\n", |
| 1811 | + "197 0.999377 70.913361 6.412774e-10\n", |
| 1812 | + "198 0.997574 64.547339 9.480593e-10\n", |
| 1813 | + "199 0.982757 39.948848 2.226480e-10\n", |
1806 | 1814 | "\n", |
1807 | 1815 | "[200 rows x 3 columns]" |
1808 | 1816 | ] |
|
1813 | 1821 | } |
1814 | 1822 | ], |
1815 | 1823 | "source": [ |
1816 | | - "p_space_df = output.p_space_to_dataframe()\n", |
| 1824 | + "p_space_df = bayesian_output.p_space_to_dataframe()\n", |
1817 | 1825 | "p_space_df" |
1818 | 1826 | ] |
1819 | 1827 | }, |
|
1855 | 1863 | " <th>v_half</th>\n", |
1856 | 1864 | " <th>target</th>\n", |
1857 | 1865 | " </tr>\n", |
| 1866 | + " <tr>\n", |
| 1867 | + " <th>Iteration</th>\n", |
| 1868 | + " <th></th>\n", |
| 1869 | + " <th></th>\n", |
| 1870 | + " <th></th>\n", |
| 1871 | + " </tr>\n", |
1858 | 1872 | " </thead>\n", |
1859 | 1873 | " <tbody>\n", |
1860 | 1874 | " <tr>\n", |
|
1929 | 1943 | "</div>" |
1930 | 1944 | ], |
1931 | 1945 | "text/plain": [ |
1932 | | - " scale v_half target\n", |
1933 | | - "116 0.990320 61.511633 1.013992e-09\n", |
1934 | | - "108 0.988234 61.959510 1.013962e-09\n", |
1935 | | - "110 0.982902 61.693392 1.013046e-09\n", |
1936 | | - "170 0.978972 61.694825 1.011628e-09\n", |
1937 | | - "119 0.997161 61.119598 1.007215e-09\n", |
1938 | | - ".. ... ... ...\n", |
1939 | | - "91 0.755228 33.970485 2.088355e-10\n", |
1940 | | - "194 0.980303 38.162301 1.980600e-10\n", |
1941 | | - "66 0.565420 28.017858 1.792657e-10\n", |
1942 | | - "74 0.564120 27.260708 1.737898e-10\n", |
1943 | | - "174 0.968588 35.695063 1.692841e-10\n", |
| 1946 | + " scale v_half target\n", |
| 1947 | + "Iteration \n", |
| 1948 | + "116 0.990320 61.511633 1.013992e-09\n", |
| 1949 | + "108 0.988234 61.959510 1.013962e-09\n", |
| 1950 | + "110 0.982902 61.693392 1.013046e-09\n", |
| 1951 | + "170 0.978972 61.694825 1.011628e-09\n", |
| 1952 | + "119 0.997161 61.119598 1.007215e-09\n", |
| 1953 | + "... ... ... ...\n", |
| 1954 | + "91 0.755228 33.970485 2.088355e-10\n", |
| 1955 | + "194 0.980303 38.162301 1.980600e-10\n", |
| 1956 | + "66 0.565420 28.017858 1.792657e-10\n", |
| 1957 | + "74 0.564120 27.260708 1.737898e-10\n", |
| 1958 | + "174 0.968588 35.695063 1.692841e-10\n", |
1944 | 1959 | "\n", |
1945 | 1960 | "[200 rows x 3 columns]" |
1946 | 1961 | ] |
|
2422 | 2437 | } |
2423 | 2438 | ], |
2424 | 2439 | "source": [ |
2425 | | - "from climada.entity import ImpactFuncSet, ImpfTropCyclone\n", |
2426 | 2440 | "from climada.engine import ImpactCalc\n", |
2427 | 2441 | "\n", |
2428 | | - "impf = ImpactFuncSet([ImpfTropCyclone.from_emanuel_usa(**output.params)])\n", |
| 2442 | + "impf = impact_func_tc(**bayesian_output.params)\n", |
2429 | 2443 | "impact = ImpactCalc(exposure, impf, hazard).impact(assign_centroids=False)\n", |
2430 | 2444 | "impact_data = impact.impact_at_reg(exposure.gdf[\"region_id\"])\n", |
2431 | 2445 | "impact_data" |
|
2988 | 3002 | "\n", |
2989 | 3003 | "So we present some ideas on how to continue and/or improve the calibration:\n", |
2990 | 3004 | "1. Use a different cost function\n", |
2991 | | - "2. Employ the `ScipyMinimizeOptimizer` instead of the `BayesianOptimizer`" |
| 3005 | + "2. Also calibrate the `v_thresh` parameter. This requires adding constraints, because `v_thresh` < `v_half`.\n", |
| 3006 | + "3. Calibrate different impact functions for houses in Mexico and Puerto Rico within the same optimization task.\n", |
| 3007 | + "4. Employ the `ScipyMinimizeOptimizer` instead of the `BayesianOptimizer`" |
2992 | 3008 | ] |
2993 | 3009 | }, |
2994 | 3010 | { |
|
0 commit comments