Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active April 16, 2022 03:23
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/91b9fcd8fb92c12f4ea2639320ead116 to your computer and use it in GitHub Desktop.
Save taruma/91b9fcd8fb92c12f4ea2639320ead116 to your computer and use it in GitHub Desktop.
taruma_hk172_normal.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "taruma_hk172_normal.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyOB2PARFTdaxsoQ1YyOjS3d",
"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/91b9fcd8fb92c12f4ea2639320ead116/taruma_hk172_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 [#172](https://github.com/hidrokit/hidrokit/issues/172): **anfrek: Normal**\n",
"\n",
"Referensi Isu:\n",
"- Soewarno. (1995). hidrologi: Aplikasi Metode Statistik untuk Analisa Data.NOVA.\n",
"- Natural Resources Conversation Service. (2007). Chapter 5: Stream Hydrology. Part 654 Stream Restoration Design National Engineering Handbook. United States Department of Agriculture. (`7329.pdf`)\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": "qxk1scgwjIlf"
}
},
{
"cell_type": "markdown",
"source": [
"# PERSIAPAN DAN DATASET"
],
"metadata": {
"id": "MMxjEiRkkALT"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "By0Kv-HkjBHz"
},
"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. 12\n",
"\n",
"_DEBIT = [\n",
" 149.4, 132.4, 125.0, 121.0, 114.7, 109.0, 101.7, 99.2, 97.8, 97.4, 91.1, \n",
" 90.0, 89.1, 84.6, 83.8, 83.6, 78.6, 77.8, 73.0, 68.5, 65.0, 45.2, 41.6\n",
"]\n",
"\n",
"# Data aslinya Tabel 3.4\n",
"# 109.0, 125.0, 121.0, 97.4, 78.6, 149.4, 90.0, 114.1, 91.1, 84.6, 132.4, \n",
"# 83.8, 73.0, 65.0, 97.8, 77.8, 45.2, 68.5, 83.6, 191.7, 99.2, 41.6, 89.1\n",
"# terdapat perbedaan nilai (max seharusnya 191.7) dan nilai 114.1 -> 114.7\n",
"\n",
"data = pd.DataFrame(\n",
" data=_DEBIT, columns=['debit'], index=range(1, 24)\n",
")\n",
"\n",
"data"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 771
},
"id": "ORMadhqrkEm5",
"outputId": "2b4e4a31-7871-4881-9b2a-4cd5cd7d263a"
},
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" debit\n",
"1 149.4\n",
"2 132.4\n",
"3 125.0\n",
"4 121.0\n",
"5 114.7\n",
"6 109.0\n",
"7 101.7\n",
"8 99.2\n",
"9 97.8\n",
"10 97.4\n",
"11 91.1\n",
"12 90.0\n",
"13 89.1\n",
"14 84.6\n",
"15 83.8\n",
"16 83.6\n",
"17 78.6\n",
"18 77.8\n",
"19 73.0\n",
"20 68.5\n",
"21 65.0\n",
"22 45.2\n",
"23 41.6"
],
"text/html": [
"\n",
" <div id=\"df-0713babe-d21a-4788-a501-b55b0fd7d1b9\">\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>149.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>132.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>121.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>114.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>109.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>101.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>99.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>97.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>97.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>91.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>89.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>84.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>83.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>83.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>78.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>77.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>73.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>68.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>45.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>41.6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-0713babe-d21a-4788-a501-b55b0fd7d1b9')\"\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-0713babe-d21a-4788-a501-b55b0fd7d1b9 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-0713babe-d21a-4788-a501-b55b0fd7d1b9');\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 `hk172` 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 `hk172` nilai $k$ akan dibangkitkan menggunakan `scipy` secara `default`. Mohon diperhatikan jika ingin menggunakan nilai $k$ yang berasal dari sumber lain.\n"
],
"metadata": {
"id": "3qpRxufkk9Ht"
}
},
{
"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": "72E25PwokxR2",
"outputId": "193032e1-9f89-4187-eede-dce1b5c1275e"
},
"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-b54d654c-3d22-4da2-abcd-bc6aeff99ac9\">\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-b54d654c-3d22-4da2-abcd-bc6aeff99ac9')\"\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-b54d654c-3d22-4da2-abcd-bc6aeff99ac9 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-b54d654c-3d22-4da2-abcd-bc6aeff99ac9');\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": "PH_D6NvAlGQd"
}
},
{
"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": "5yahOdeZlDla"
},
"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_normal(x, return_period=[5], source='scipy', show_stat=False):\n",
" return_period = np.array(return_period)\n",
" x = np.array(x)\n",
" x_mean = np.mean(x)\n",
" x_std = np.std(x, ddof=1)\n",
" n = x.size\n",
"\n",
" k = find_K(return_period, source=source)\n",
"\n",
" if show_stat:\n",
" print(f'x_mean = {x_mean:.5f}')\n",
" print(f'x_std = {x_std:.5f}')\n",
" print(f'k = {k}')\n",
"\n",
" val_x = x_mean + k * x_std\n",
" return val_x\n",
"\n",
"def freq_normal(\n",
" df, col=None,\n",
" return_period=[2, 5, 10, 20, 25, 50, 100], show_stat=False, source='scipy',\n",
" col_name='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_normal(\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": "7XYPX9TIlHnT"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# FUNGSI\n",
"\n",
"## 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'`). \n",
"\n",
"Catatan: Fungsi ini sama dengan `.hk124`."
],
"metadata": {
"id": "gY54-Kazn8Bf"
}
},
{
"cell_type": "code",
"source": [
"find_K(10)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "369KjO-hoDuK",
"outputId": "f9c26b17-a911-474b-98d7-f7a1700c6e54"
},
"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": "ArtCn2zKoG9E",
"outputId": "9717457d-eb9a-4b21-d12f-e3be44ef5fa6"
},
"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": "8-f2UHMdoIFB",
"outputId": "8f53e3ab-2393-42e8-cf88-61b3aa958211"
},
"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_normal(x, ...)`\n",
"\n",
"Function: `calc_x_normal(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": "Uzv5svPkoLuc"
}
},
{
"cell_type": "code",
"source": [
"calc_x_normal(data.debit)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "skpgtwUGoJZX",
"outputId": "3c07417d-14c7-4260-baa6-60a948c594db"
},
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([114.00269627])"
]
},
"metadata": {},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"source": [
"calc_x_normal(data.debit, show_stat=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "RTIG8QQ2oQWb",
"outputId": "b88149fc-ec2b-4f08-fee6-0822c3c93aa6"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"x_mean = 92.15217\n",
"x_std = 25.96242\n",
"k = [0.84162123]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([114.00269627])"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "code",
"source": [
"calc_x_normal(data.debit, return_period=[5, 10, 15, 20, 21], show_stat=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "fF9zHDIaoSgj",
"outputId": "4b871306-6985-418d-d49c-10c6d1ee0e47"
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"x_mean = 92.15217\n",
"x_std = 25.96242\n",
"k = [0.84162123 1.28155157 1.50108595 1.64485363 1.66839119]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([114.00269627, 125.42435149, 131.12399486, 134.85655151,\n",
" 135.46764366])"
]
},
"metadata": {},
"execution_count": 11
}
]
},
{
"cell_type": "markdown",
"source": [
"## Fungsi `freq_normal(df, ...)`\n",
"\n",
"Function: `freq_normal(df, col=None, return_period=[2, 5, 10, 20, 25, 50, 100], show_stat=False, source='scipy', col_name='Normal')`\n",
"\n",
"Fungsi `freq_normal(...)` merupakan fungsi kembangan lebih lanjut dari `calc_x_normal(...)` 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": "0lRD-4pKoYC4"
}
},
{
"cell_type": "code",
"source": [
"freq_normal(data)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "tI6ngrBzoWd4",
"outputId": "692e0bb4-b66d-4b45-f472-4809bbb524b2"
},
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Normal\n",
"Kala Ulang \n",
"2 92.152174\n",
"5 114.002696\n",
"10 125.424351\n",
"20 134.856552\n",
"25 137.604218\n",
"50 145.472462\n",
"100 152.549790"
],
"text/html": [
"\n",
" <div id=\"df-3769a4f9-b965-4df5-a5de-e715a16ac933\">\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>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>92.152174</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>114.002696</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>125.424351</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>134.856552</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>137.604218</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>145.472462</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>152.549790</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-3769a4f9-b965-4df5-a5de-e715a16ac933')\"\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-3769a4f9-b965-4df5-a5de-e715a16ac933 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-3769a4f9-b965-4df5-a5de-e715a16ac933');\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_normal(data, source='soewarno', col_name='Normal (Soewarno)')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "iM9OJNRaoeV4",
"outputId": "6f7a7dd9-e959-495d-e6ec-c5d7984ff2cd"
},
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Normal (Soewarno)\n",
"Kala Ulang \n",
"2 92.152174\n",
"5 113.960605\n",
"10 125.384069\n",
"20 134.730540\n",
"25 136.504638\n",
"50 145.375131\n",
"100 152.644608"
],
"text/html": [
"\n",
" <div id=\"df-21785066-f770-45b3-8905-ffcb6a7f6145\">\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>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>92.152174</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>113.960605</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>125.384069</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>134.730540</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>136.504638</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>145.375131</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>152.644608</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-21785066-f770-45b3-8905-ffcb6a7f6145')\"\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-21785066-f770-45b3-8905-ffcb6a7f6145 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-21785066-f770-45b3-8905-ffcb6a7f6145');\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_normal(data, 'debit', source='scipy', col_name='Normal (scipy)', show_stat=True)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 370
},
"id": "AOGtyPlloiWH",
"outputId": "4a9babdc-4308-4aa1-95bc-5f6cd7f22daf"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"x_mean = 92.15217\n",
"x_std = 25.96242\n",
"k = [0. 0.84162123 1.28155157 1.64485363 1.75068607 2.05374891\n",
" 2.32634787]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Normal (scipy)\n",
"Kala Ulang \n",
"2 92.152174\n",
"5 114.002696\n",
"10 125.424351\n",
"20 134.856552\n",
"25 137.604218\n",
"50 145.472462\n",
"100 152.549790"
],
"text/html": [
"\n",
" <div id=\"df-be292f89-11cb-4cc2-8174-19de54a6c07f\">\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>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>92.152174</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>114.002696</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>125.424351</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>134.856552</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>137.604218</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>145.472462</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>152.549790</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-be292f89-11cb-4cc2-8174-19de54a6c07f')\"\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-be292f89-11cb-4cc2-8174-19de54a6c07f 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-be292f89-11cb-4cc2-8174-19de54a6c07f');\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_normal(data, 'debit', source=_s, col_name=f'Normal ({_s})')]\n",
"\n",
"pd.concat(_res, axis=1)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "7lYWySN7okfm",
"outputId": "41a17434-8ea5-44ae-a2fb-cf99e7b971dc"
},
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Normal (soewarno) Normal (scipy)\n",
"Kala Ulang \n",
"2 92.152174 92.152174\n",
"5 113.960605 114.002696\n",
"10 125.384069 125.424351\n",
"20 134.730540 134.856552\n",
"25 136.504638 137.604218\n",
"50 145.375131 145.472462\n",
"100 152.644608 152.549790"
],
"text/html": [
"\n",
" <div id=\"df-a07954b5-d00a-4cda-950f-06e57fdb8ee8\">\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>Normal (soewarno)</th>\n",
" <th>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>92.152174</td>\n",
" <td>92.152174</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>113.960605</td>\n",
" <td>114.002696</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>125.384069</td>\n",
" <td>125.424351</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>134.730540</td>\n",
" <td>134.856552</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>136.504638</td>\n",
" <td>137.604218</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>145.375131</td>\n",
" <td>145.472462</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>152.644608</td>\n",
" <td>152.549790</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a07954b5-d00a-4cda-950f-06e57fdb8ee8')\"\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-a07954b5-d00a-4cda-950f-06e57fdb8ee8 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-a07954b5-d00a-4cda-950f-06e57fdb8ee8');\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"
],
"metadata": {
"id": "bkQbrB12Yb7Q"
}
},
{
"cell_type": "code",
"source": [
"calc_prob(-0.25)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "31bsuowdY4AD",
"outputId": "525a8e08-9e07-4f23-8daa-88a8cf3f72f0"
},
"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": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mlpbxr9xZ73h",
"outputId": "45df5005-ac13-4a60-874c-4ed9e03a9109"
},
"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": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "23eaNDBkZ_zz",
"outputId": "f7ee8abd-eacd-45bf-877f-5b60535c0dd9"
},
"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",
"- 20220416 - 1.1.1 - koreksi nama kolom\n",
"- 20220323 - 1.1.0 - tambah argumen index_name=\"Kala Ulang\" pada fungsi freq_normal() untuk penamaan index\n",
"- 20220316 - 1.0.5 - ubah fungsi _calc_prob(...) (hasil menjadi 1-P)\n",
"- 20220315 - 1.0.4 - ubah nama fungs _find_prob_in_table -> _calc_prob_in_table(...)\n",
"- 20220315 - 1.0.3 - Ubah nama fungsi find_prob(...) -> calc_prob(...)\n",
"- 20220314 - 1.0.2 - Typo\n",
"- 20220314 - 1.0.1 - Tambah fungsi find_prob(...)\n",
"- 20220311 - 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": "AwoFcQtXoohQ"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment