Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active April 5, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taruma/5d3ab88893e56f895dc3f36ea19c3e60 to your computer and use it in GitHub Desktop.
Save taruma/5d3ab88893e56f895dc3f36ea19c3e60 to your computer and use it in GitHub Desktop.
taruma_hk124_log_normal.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "taruma_hk124_log_normal.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyMM88b3NgQhwx5J8ITfQQYS",
"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/taruma/5d3ab88893e56f895dc3f36ea19c3e60/taruma_hk124_log_normal.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Berdasarkan isu [#124](https://github.com/hidrokit/hidrokit/issues/124): **anfrek: Log Normal 2 Parameter**\n",
"\n",
"Referensi Isu:\n",
"- Soetopo, W., Montarcih, L., Press, U. B., & Media, U. (2017). Rekayasa Statistika untuk Teknik Pengairan. Universitas Brawijaya Press. https://books.google.co.id/books?id=TzVTDwAAQBAJ\n",
"- Soewarno. (1995). hidrologi: Aplikasi Metode Statistik untuk Analisa Data.NOVA.\n",
"\n",
"Deskripsi Isu:\n",
"- Mencari nilai ekstrim dengan kala ulang tertentu. Penerapan ini bisa digunakan untuk hujan rancangan atau debit banjir rancangan. \n",
"\n",
"Diskusi Isu:\n",
"- [#156](https://github.com/hidrokit/hidrokit/discussions/156) - Bagaimana menghitung periode ulang distribusi (analisis frekuensi) tanpa melihat tabel?\n",
"\n",
"Strategi:\n",
"- Akan mengikuti fungsi log pearson [#126](https://github.com/hidrokit/hidrokit/issues/126) seperti pada [manual](https://gist.github.com/taruma/60725ffca91dc6e741daee9a738a978b)."
],
"metadata": {
"id": "4qHP0pbEKICf"
}
},
{
"cell_type": "markdown",
"source": [
"# PERSIAPAN DAN DATASET"
],
"metadata": {
"id": "8La7dGZzMb7Y"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "AoKIMI-eJ8Pk"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from scipy import stats"
]
},
{
"cell_type": "code",
"source": [
"# contoh data diambil dari buku\n",
"# hidrologi: Aplikasi Metode Statistik untuk Analisa Data hal. 144\n",
"\n",
"_DEBIT = [\n",
" 58.3, 50.5, 46.0, 41.8, 38.2, 37.9, 37.7, 35.3, 35.2, 33.4, 31.9, \n",
" 31.1, 30.9, 30.1, 28.8, 24.7, 23.6, 23.5, 23.1, 22.5, 21.1, 20.5, \n",
" 20.5, 20.3, 20.2, 18.7, 17.2, 14.9, 12.4, 11.8\n",
"]\n",
"\n",
"data = pd.DataFrame(\n",
" data=_DEBIT, columns=['debit'], index=range(1, 31)\n",
")\n",
"\n",
"data"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 990
},
"id": "_OEDaiTOjrTd",
"outputId": "55df90aa-b171-4aff-a908-4edd3f0e7156"
},
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" debit\n",
"1 58.3\n",
"2 50.5\n",
"3 46.0\n",
"4 41.8\n",
"5 38.2\n",
"6 37.9\n",
"7 37.7\n",
"8 35.3\n",
"9 35.2\n",
"10 33.4\n",
"11 31.9\n",
"12 31.1\n",
"13 30.9\n",
"14 30.1\n",
"15 28.8\n",
"16 24.7\n",
"17 23.6\n",
"18 23.5\n",
"19 23.1\n",
"20 22.5\n",
"21 21.1\n",
"22 20.5\n",
"23 20.5\n",
"24 20.3\n",
"25 20.2\n",
"26 18.7\n",
"27 17.2\n",
"28 14.9\n",
"29 12.4\n",
"30 11.8"
],
"text/html": [
"\n",
" <div id=\"df-6e0b1b86-116a-47f7-ad86-60b14d75bab2\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>debit</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>58.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>50.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>41.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>38.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>37.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>37.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>35.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>35.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>33.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>31.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>31.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>30.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>30.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>28.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>24.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>23.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>23.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>23.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>22.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>21.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>20.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>20.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>20.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>20.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>18.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>17.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>14.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>12.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>11.8</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-6e0b1b86-116a-47f7-ad86-60b14d75bab2')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-6e0b1b86-116a-47f7-ad86-60b14d75bab2 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-6e0b1b86-116a-47f7-ad86-60b14d75bab2');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "markdown",
"source": [
"# TABEL\n",
"\n",
"Terdapat 1 tabel untuk modul `hk124` yaitu:\n",
"- `t_normal_sw`: Tabel nilai $k$ dari Tabel 3.3 Nilai Variabel Reduksi Gauss. Sumber: hidrologi: Aplikasi Metode Statistik untuk Analisa Data.\n",
"\n",
"Dalam modul `hk124` nilai $k$ akan dibangkitkan menggunakan `scipy` secara `default`. Mohon diperhatikan jika ingin menggunakan nilai $k$ yang berasal dari sumber lain.\n"
],
"metadata": {
"id": "t-xuUi0o-vG4"
}
},
{
"cell_type": "code",
"source": [
"# Tabel Nilai Variabel Reduksi Gauss\n",
"# Dari buku hidrologi: Aplikasi Metode Statistik untuk Analisa Data. hal.119\n",
"\n",
"# KODE: SW\n",
"\n",
"_DATA_SW = [\n",
" [1.001, 0.999, -3.050],\n",
" [1.005, 0.995, -2.580],\n",
" [1.010, 0.990, -2.330],\n",
" [1.050, 0.950, -1.640],\n",
" [1.110, 0.900, -1.280],\n",
" [1.250, 0.800, -0.840],\n",
" [1.330, 0.750, -0.670],\n",
" [1.430, 0.700, -0.520],\n",
" [1.670, 0.600, -0.250],\n",
" [2.000, 0.500, 0.000],\n",
" [2.500, 0.400, 0.250],\n",
" [3.330, 0.300, 0.520],\n",
" [4.000, 0.250, 0.670],\n",
" [5.000, 0.200, 0.840],\n",
" [10.000, 0.100, 1.280],\n",
" [20.000, 0.050, 1.640],\n",
" [50.000, 0.200, 2.050],\n",
" [100.000, 0.010, 2.330],\n",
" [200.000, 0.005, 2.580],\n",
" [500.000, 0.002, 2.880],\n",
" [1000.000, 0.001, 3.090],\n",
"]\n",
"\n",
"_COL_SW = ['periode_ulang', 'peluang', 'k']\n",
"\n",
"t_normal_sw = pd.DataFrame(\n",
" data=_DATA_SW, columns=_COL_SW\n",
")\n",
"t_normal_sw"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 708
},
"id": "EeNhcyjX-wUh",
"outputId": "2158186d-857b-45e3-89f9-ba49fafe101a"
},
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" periode_ulang peluang k\n",
"0 1.001 0.999 -3.05\n",
"1 1.005 0.995 -2.58\n",
"2 1.010 0.990 -2.33\n",
"3 1.050 0.950 -1.64\n",
"4 1.110 0.900 -1.28\n",
"5 1.250 0.800 -0.84\n",
"6 1.330 0.750 -0.67\n",
"7 1.430 0.700 -0.52\n",
"8 1.670 0.600 -0.25\n",
"9 2.000 0.500 0.00\n",
"10 2.500 0.400 0.25\n",
"11 3.330 0.300 0.52\n",
"12 4.000 0.250 0.67\n",
"13 5.000 0.200 0.84\n",
"14 10.000 0.100 1.28\n",
"15 20.000 0.050 1.64\n",
"16 50.000 0.200 2.05\n",
"17 100.000 0.010 2.33\n",
"18 200.000 0.005 2.58\n",
"19 500.000 0.002 2.88\n",
"20 1000.000 0.001 3.09"
],
"text/html": [
"\n",
" <div id=\"df-d7d73b75-5fbb-4977-969c-ae41b2a4ef67\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>periode_ulang</th>\n",
" <th>peluang</th>\n",
" <th>k</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.001</td>\n",
" <td>0.999</td>\n",
" <td>-3.05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1.005</td>\n",
" <td>0.995</td>\n",
" <td>-2.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1.010</td>\n",
" <td>0.990</td>\n",
" <td>-2.33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1.050</td>\n",
" <td>0.950</td>\n",
" <td>-1.64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.110</td>\n",
" <td>0.900</td>\n",
" <td>-1.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>1.250</td>\n",
" <td>0.800</td>\n",
" <td>-0.84</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>1.330</td>\n",
" <td>0.750</td>\n",
" <td>-0.67</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>1.430</td>\n",
" <td>0.700</td>\n",
" <td>-0.52</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>1.670</td>\n",
" <td>0.600</td>\n",
" <td>-0.25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>2.000</td>\n",
" <td>0.500</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>2.500</td>\n",
" <td>0.400</td>\n",
" <td>0.25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>3.330</td>\n",
" <td>0.300</td>\n",
" <td>0.52</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>4.000</td>\n",
" <td>0.250</td>\n",
" <td>0.67</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>5.000</td>\n",
" <td>0.200</td>\n",
" <td>0.84</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>10.000</td>\n",
" <td>0.100</td>\n",
" <td>1.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>20.000</td>\n",
" <td>0.050</td>\n",
" <td>1.64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>50.000</td>\n",
" <td>0.200</td>\n",
" <td>2.05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>100.000</td>\n",
" <td>0.010</td>\n",
" <td>2.33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>200.000</td>\n",
" <td>0.005</td>\n",
" <td>2.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>500.000</td>\n",
" <td>0.002</td>\n",
" <td>2.88</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>1000.000</td>\n",
" <td>0.001</td>\n",
" <td>3.09</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-d7d73b75-5fbb-4977-969c-ae41b2a4ef67')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-d7d73b75-5fbb-4977-969c-ae41b2a4ef67 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-d7d73b75-5fbb-4977-969c-ae41b2a4ef67');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 3
}
]
},
{
"cell_type": "markdown",
"source": [
"# KODE"
],
"metadata": {
"id": "5BAEWoZakZW9"
}
},
{
"cell_type": "code",
"source": [
"def _find_k_in_table(return_period, table):\n",
" x = table.periode_ulang\n",
" y = table.k\n",
" return np.interp(return_period, x, y)\n",
"\n",
"def _calc_prob_in_table(k, table):\n",
" x = table.k\n",
" y = table.peluang\n",
" return np.interp(k, x, y)"
],
"metadata": {
"id": "dAyTAz4tBq01"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def find_K(return_period, source='scipy'):\n",
" if source.lower() == 'soewarno':\n",
" return _find_k_in_table(return_period, t_normal_sw)\n",
" elif source.lower() == 'scipy':\n",
" return_period = np.array(return_period)\n",
" return stats.norm.ppf(1 - 1/return_period)\n",
"\n",
"def calc_x_lognormal(x, return_period=[5], source='scipy', show_stat=False):\n",
" return_period = np.array(return_period)\n",
" y = np.log10(x)\n",
" y_mean = np.mean(y)\n",
" y_std = np.std(y, ddof=1)\n",
" n = len(y)\n",
"\n",
" k = find_K(return_period, source=source)\n",
"\n",
" if show_stat:\n",
" print(f'y_mean = {y_mean:.5f}')\n",
" print(f'y_std = {y_std:.5f}')\n",
" print(f'k = {k}')\n",
"\n",
" val_y = y_mean + k * y_std\n",
" val_x = np.power(10, val_y)\n",
" return val_x\n",
"\n",
"def freq_lognormal(\n",
" df, col=None,\n",
" return_period=[2, 5, 10, 20, 25, 50, 100], show_stat=False, source='scipy',\n",
" col_name='Log Normal', index_name='Kala Ulang'):\n",
"\n",
" col = df.columns[0] if col is None else col\n",
"\n",
" x = df[col].copy()\n",
"\n",
" arr = calc_x_lognormal(\n",
" x, return_period=return_period, show_stat=show_stat, source=source)\n",
"\n",
" result = pd.DataFrame(\n",
" data=arr, index=return_period, columns=[col_name]\n",
" )\n",
"\n",
" result.index.name = index_name\n",
" return result\n",
"\n",
"def calc_prob(k, source='scipy'):\n",
" if source.lower() == 'soewarno':\n",
" k = np.array(k)\n",
" return 1 - _calc_prob_in_table(k, t_normal_sw)\n",
" elif source.lower() == 'scipy':\n",
" return stats.norm.cdf(k)"
],
"metadata": {
"id": "dupcvjsZkYqk"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# FUNGSI"
],
"metadata": {
"id": "Tk_cHuGcDh0n"
}
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `find_K(return_period, ...)`\n",
"\n",
"Function: `find_K(return_period, source='scipy')`\n",
"\n",
"Fungsi `find_K(...)` digunakan untuk mencari nilai $K$ dari berbagai sumber berdasarkan kala ulang. \n",
"\n",
"- Argumen Posisi:\n",
" - `return_period`: kala ulang. Dapat diisi dengan _scalar_ atau _array_like_.\n",
"- Argumen Opsional:\n",
" - `source`: sumber nilai $k$, `scipy` (default). Sumber yang dapat digunakan antara lain: Soewarno (`'soewarno'`). "
],
"metadata": {
"id": "znnNAig5Di2u"
}
},
{
"cell_type": "code",
"source": [
"find_K(10)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "qAhGBKthEUjT",
"outputId": "8ea5b329-beae-4ebc-c6ad-91566b28ad9c"
},
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1.2815515655446004"
]
},
"metadata": {},
"execution_count": 6
}
]
},
{
"cell_type": "code",
"source": [
"find_K([2, 5, 10], source='soewarno')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tb7FuYg3EWqd",
"outputId": "f611a3c5-581f-4019-ef5b-21d2e80faa0e"
},
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([0. , 0.84, 1.28])"
]
},
"metadata": {},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"source": [
"# perbandingan antara masing-masing sumber\n",
"\n",
"_rp = [2, 5, 10, 15, 20, 25, 27, 50, 100]\n",
"source_test = ['soewarno', 'scipy']\n",
"\n",
"for _source in source_test:\n",
" print(f'k {_source:10}= {find_K(_rp, source=_source)}')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Xo-gtrEwEeCC",
"outputId": "564f0619-f673-4428-8aca-282518f70e29"
},
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"k soewarno = [0. 0.84 1.28 1.46 1.64 1.70833333\n",
" 1.73566667 2.05 2.33 ]\n",
"k scipy = [0. 0.84162123 1.28155157 1.50108595 1.64485363 1.75068607\n",
" 1.78615556 2.05374891 2.32634787]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `calc_x_lognormal(x, ...)`\n",
"\n",
"Function: `calc_x_lognormal(x, return_period=[5], source='scipy', show_stat=False)`\n",
"\n",
"Fungsi `calc_x_lognormal(...)` digunakan untuk mencari besar $X$ berdasarkan kala ulang (_return period_), yang hasilnya dalam bentuk `numpy.array`. \n",
"\n",
"- Argumen Posisi:\n",
" - `x`: _array_.\n",
"- Argumen Opsional:\n",
" - `return_period`: kala ulang (tahun), `[5]` (default).\n",
" - `source`: sumber nilai $k$, `'scipy'` (default). Sumber yang dapat digunakan antara lain: Soewarno (`'soewarno'`).\n",
" - `show_stat`: menampilkan parameter statistik. `False` (default). "
],
"metadata": {
"id": "78n0yoDVE9ZJ"
}
},
{
"cell_type": "code",
"source": [
"calc_x_lognormal(data.debit)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3hPZS2PVGI36",
"outputId": "58e6e899-6c36-4682-e7a8-b5531037b51f"
},
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([37.23254445])"
]
},
"metadata": {},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"source": [
"calc_x_lognormal(data.debit, show_stat=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "UekEPZaDGMb-",
"outputId": "31a231f4-b9a6-4d1f-a976-62302836ae15"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"y_mean = 1.42638\n",
"y_std = 0.17174\n",
"k = [0.84162123]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([37.23254445])"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "code",
"source": [
"calc_x_lognormal(data.debit, return_period=[5, 10, 15, 20, 21], show_stat=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "DA9wCrGMGQrT",
"outputId": "113bca8f-ee79-4f42-cdeb-de4bffc344e7"
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"y_mean = 1.42638\n",
"y_std = 0.17174\n",
"k = [0.84162123 1.28155157 1.50108595 1.64485363 1.66839119]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([37.23254445, 44.30748222, 48.32593502, 51.15300628, 51.63135738])"
]
},
"metadata": {},
"execution_count": 11
}
]
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `freq_lognormal(df, ...)`\n",
"\n",
"Function: `freq_lognormal(df, col=None, return_period=[2, 5, 10, 20, 25, 50, 100], show_stat=False, source='scipy', col_name='Log Normal')`\n",
"\n",
"Fungsi `freq_lognormal(...)` merupakan fungsi kembangan lebih lanjut dari `calc_x_lognormal(...)` yang menerima input `pandas.DataFrame` dan memiliki luaran berupa `pandas.DataFrame`.\n",
"\n",
"- Argumen Posisi:\n",
" - `df`: `pandas.DataFrame`.\n",
"- Argumen Opsional:\n",
" - `col`: nama kolom, `None` (default). Jika tidak diisi menggunakan kolom pertama dalam `df` sebagai data masukan.\n",
" - `return_period`: kala ulang (tahun), `[2, 5, 10, 20, 25, 50, 100]` (default).\n",
" - `source`: sumber nilai $k$, `'scipy'` (default). Sumber yang dapat digunakan antara lain: Soewarno (`'soewarno'`).\n",
" - `show_stat`: menampilkan parameter statistik. `False` (default).\n",
" - `col_name`: nama kolom luaran, `Log Normal` (default). "
],
"metadata": {
"id": "fbvbkNE9GX4b"
}
},
{
"cell_type": "code",
"source": [
"freq_lognormal(data)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "qjJuODkbmuxF",
"outputId": "2de91efb-a53c-44a8-e4e2-1f8a2ccd37c4"
},
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Log Normal\n",
"Kala Ulang \n",
"2 26.692012\n",
"5 37.232544\n",
"10 44.307482\n",
"20 51.153006\n",
"25 53.339262\n",
"50 60.130596\n",
"100 66.974904"
],
"text/html": [
"\n",
" <div id=\"df-c6628044-7253-4b84-bb25-238ab344394d\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Log Normal</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Kala Ulang</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>26.692012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>37.232544</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>44.307482</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>51.153006</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>53.339262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>60.130596</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>66.974904</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c6628044-7253-4b84-bb25-238ab344394d')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-c6628044-7253-4b84-bb25-238ab344394d button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-c6628044-7253-4b84-bb25-238ab344394d');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 12
}
]
},
{
"cell_type": "code",
"source": [
"freq_lognormal(data, source='soewarno', col_name='Log Normal (Soewarno)')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "DhgOUmtSHV5z",
"outputId": "25908b9c-e7db-4bab-e125-b404dbe631d8"
},
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Log Normal (Soewarno)\n",
"Kala Ulang \n",
"2 26.692012\n",
"5 37.208682\n",
"10 44.280305\n",
"20 51.054919\n",
"25 52.453355\n",
"50 60.041518\n",
"100 67.071701"
],
"text/html": [
"\n",
" <div id=\"df-81c05bd3-5101-43a6-bd40-837f585ace24\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Log Normal (Soewarno)</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Kala Ulang</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>26.692012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>37.208682</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>44.280305</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>51.054919</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>52.453355</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>60.041518</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>67.071701</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-81c05bd3-5101-43a6-bd40-837f585ace24')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-81c05bd3-5101-43a6-bd40-837f585ace24 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-81c05bd3-5101-43a6-bd40-837f585ace24');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"source": [
"freq_lognormal(data, 'debit', source='scipy', col_name=f'Log Normal (scipy)', show_stat=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 370
},
"id": "Oc-xPGkVHaL6",
"outputId": "782f7b0b-576a-45c7-cba7-b6db44129aa1"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"y_mean = 1.42638\n",
"y_std = 0.17174\n",
"k = [0. 0.84162123 1.28155157 1.64485363 1.75068607 2.05374891\n",
" 2.32634787]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Log Normal (scipy)\n",
"Kala Ulang \n",
"2 26.692012\n",
"5 37.232544\n",
"10 44.307482\n",
"20 51.153006\n",
"25 53.339262\n",
"50 60.130596\n",
"100 66.974904"
],
"text/html": [
"\n",
" <div id=\"df-4e5cd167-15da-4551-9814-a8c004db1de9\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Log Normal (scipy)</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Kala Ulang</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>26.692012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>37.232544</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>44.307482</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>51.153006</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>53.339262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>60.130596</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>66.974904</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-4e5cd167-15da-4551-9814-a8c004db1de9')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-4e5cd167-15da-4551-9814-a8c004db1de9 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-4e5cd167-15da-4551-9814-a8c004db1de9');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 14
}
]
},
{
"cell_type": "code",
"source": [
"_res = []\n",
"\n",
"for _s in ['soewarno', 'scipy']:\n",
" _res += [freq_lognormal(data, 'debit', source=_s, col_name=f'Log Normal ({_s})')]\n",
"\n",
"pd.concat(_res, axis=1)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "4v8yVxpHHgbM",
"outputId": "c3505874-8d54-405f-fb5e-bf60d8aac730"
},
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Log Normal (soewarno) Log Normal (scipy)\n",
"Kala Ulang \n",
"2 26.692012 26.692012\n",
"5 37.208682 37.232544\n",
"10 44.280305 44.307482\n",
"20 51.054919 51.153006\n",
"25 52.453355 53.339262\n",
"50 60.041518 60.130596\n",
"100 67.071701 66.974904"
],
"text/html": [
"\n",
" <div id=\"df-02c2c6e4-b3c6-4de3-a12c-23d937bc7cc1\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Log Normal (soewarno)</th>\n",
" <th>Log Normal (scipy)</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Kala Ulang</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>26.692012</td>\n",
" <td>26.692012</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>37.208682</td>\n",
" <td>37.232544</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>44.280305</td>\n",
" <td>44.307482</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>51.054919</td>\n",
" <td>51.153006</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>52.453355</td>\n",
" <td>53.339262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>60.041518</td>\n",
" <td>60.130596</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>67.071701</td>\n",
" <td>66.974904</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-02c2c6e4-b3c6-4de3-a12c-23d937bc7cc1')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-02c2c6e4-b3c6-4de3-a12c-23d937bc7cc1 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-02c2c6e4-b3c6-4de3-a12c-23d937bc7cc1');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `calc_prob(k, ...)`\n",
"\n",
"Function: `calc_prob(k, source='scipy')`\n",
"\n",
"Fungsi `calc_prob(...)` digunakan untuk mencari nilai peluang/probabilitas dari berbagai sumber berdasarkan nilai $K$. \n",
"\n",
"- Argumen Posisi:\n",
" - `k`: $K$ (faktor frekuensi).\n",
"- Argumen Opsional:\n",
" - `source`: sumber nilai peluang, `scipy` (default). Sumber yang dapat digunakan antara lain: Soewarno (`'soewarno'`). \n",
"\n",
"Catatan: Fungsi ini sama saja dengan yang di modul [hk172](https://gist.github.com/taruma/91b9fcd8fb92c12f4ea2639320ead116) atau [#172](https://github.com/hidrokit/hidrokit/issues/172) (Anfrek: Normal)."
],
"metadata": {
"id": "TPNThaojk3MZ"
}
},
{
"cell_type": "code",
"source": [
"calc_prob(-0.25)"
],
"metadata": {
"id": "u6Yr6An-lD6S",
"outputId": "230210d4-5f8d-477c-b4a5-2fa72d640e00",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.4012936743170763"
]
},
"metadata": {},
"execution_count": 16
}
]
},
{
"cell_type": "code",
"source": [
"calc_prob(0.52, source='soewarno')"
],
"metadata": {
"id": "Au8VDFlBlEZ5",
"outputId": "121708fe-533e-42f5-df35-52867f36b267",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 17,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.7"
]
},
"metadata": {},
"execution_count": 17
}
]
},
{
"cell_type": "code",
"source": [
"# perbandingan antara masing-masing sumber\n",
"\n",
"_k = [\n",
" -3.09, -2.58, -2.33, -1.67, 0. , 0.84, 1.28, 1.5 , 1.64,\n",
" 1.75, 1.79, 2.05, 2.33\n",
"]\n",
"\n",
"source_test = ['soewarno', 'scipy']\n",
"\n",
"for _source in source_test:\n",
" print(f'prob {_source:10}= {calc_prob(_k, source=_source)}')"
],
"metadata": {
"id": "UvodMnMdlKYt",
"outputId": "e6e8d03b-364a-4852-a73a-4e243f21ee30",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 18,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"prob soewarno = [0.001 0.005 0.01 0.04826087 0.5 0.8\n",
" 0.9 0.93055556 0.95 0.9097561 0.89512195 0.8\n",
" 0.99 ]\n",
"prob scipy = [0.00100078 0.00494002 0.00990308 0.04745968 0.5 0.79954581\n",
" 0.89972743 0.9331928 0.94949742 0.95994084 0.96327304 0.97981778\n",
" 0.99009692]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Changelog\n",
"\n",
"```\n",
"- 20220323 - 1.1.0 - tambah argumen index_name=\"Kala Ulang\" pada fungsi freq_lognormal() untuk penamaan index\n",
"- 20220316 - 1.0.3 - ubah fungsi _calc_prob(...) (hasil menjadi 1-P)\n",
"- 20220315 - 1.0.2 - ubah nama fungsi find_prob -> calc_prob(...)\n",
"- 20220314 - 1.0.1 - Tambah Fungsi find_prob(...)\n",
"- 20220310 - 1.0.0 - Initial\n",
"```\n",
"\n",
"#### Copyright &copy; 2022 [Taruma Sakti Megariansyah](https://taruma.github.io)\n",
"\n",
"Source code in this notebook is licensed under a [MIT License](https://choosealicense.com/licenses/mit/). Data in this notebook is licensed under a [Creative Common Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/). \n"
],
"metadata": {
"id": "mYa4rfsfH54r"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment