Bladeren bron

Some minor tests and correcting comments

Martin Horvat 1 jaar geleden
bovenliggende
commit
ec7af14e58

+ 22 - 23
python/bayesian/bayesian.ipynb

@@ -137,7 +137,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 24,
+   "execution_count": 5,
    "id": "9879854b",
    "metadata": {},
    "outputs": [
@@ -186,7 +186,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 25,
+   "execution_count": 6,
    "id": "ad55fcd6",
    "metadata": {},
    "outputs": [
@@ -251,7 +251,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 7,
    "id": "081c152b",
    "metadata": {},
    "outputs": [],
@@ -269,7 +269,7 @@
     "# parsing parameters\n",
     "parse_pars = lambda pars: dict(loc = pars[0], scale = pars[1])\n",
     "\n",
-    "# define function related to choosen distribution\n",
+    "# define function related to chosen distribution\n",
     "log_pdfs,distr_sample = bayesian.setup_scipy_distr(distr_str, 2, parse_pars)\n",
     "\n",
     "# define Bayesian model instance\n",
@@ -279,7 +279,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 8,
    "id": "46484c9e",
    "metadata": {},
    "outputs": [],
@@ -290,7 +290,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 9,
    "id": "fa5fa70e",
    "metadata": {},
    "outputs": [
@@ -349,7 +349,7 @@
          "type": "integer"
         }
        ],
-       "ref": "940dd791-04b6-4472-8717-09c77a744e53",
+       "ref": "595a6472-58d7-4b3b-b692-7af5ca6eccfa",
        "rows": [
         [
          "0",
@@ -424,7 +424,7 @@
        "0   54  "
       ]
      },
-     "execution_count": 10,
+     "execution_count": 9,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -436,7 +436,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 35,
+   "execution_count": 10,
    "id": "46717697",
    "metadata": {},
    "outputs": [
@@ -485,7 +485,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 11,
    "id": "8386c0d0",
    "metadata": {},
    "outputs": [
@@ -500,7 +500,7 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "/home/horvat/Documents/work/medfiz/git/uncertainty_study/python/bayesian/bayesian.py:112: RuntimeWarning: overflow encountered in exp\n",
+      "/home/horvat/Documents/work/medfiz/git/uncertainty_study/python/bayesian/bayesian.py:142: RuntimeWarning: overflow encountered in exp\n",
       "  return np.sum(np.log(1 + np.exp(-S*F)))\n",
       "/home/horvat/venvs/base/lib/python3.12/site-packages/scipy/optimize/_numdiff.py:592: RuntimeWarning: invalid value encountered in subtract\n",
       "  df = fun(x1) - f0\n"
@@ -549,7 +549,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 12,
    "id": "506a1d8d",
    "metadata": {},
    "outputs": [
@@ -582,7 +582,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 13,
    "id": "95681175",
    "metadata": {},
    "outputs": [
@@ -646,13 +646,12 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 14,
    "id": "1248787c",
    "metadata": {},
    "outputs": [],
    "source": [
     "# for testing define distribution we want to use\n",
-    "# normal is not a good distribution!\n",
     "distr_str = \"scipy.stats.betaprime\"\n",
     "\n",
     "# define logarithm of pdfs used on the Bayesian model\n",
@@ -664,7 +663,7 @@
     "# parsing parameters\n",
     "parse_pars = lambda pars: dict(a = pars[0], b = pars[1], scale  =pars[2])\n",
     "\n",
-    "# define function related to choosen distribution\n",
+    "# define function related to chosen distribution\n",
     "log_pdfs,distr_sample = bayesian.setup_scipy_distr(\"scipy.stats.betaprime\", 3, parse_pars)\n",
     "\n",
     "# define Bayesian model instance\n",
@@ -674,7 +673,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 15,
    "id": "a3fcebc3",
    "metadata": {},
    "outputs": [],
@@ -685,7 +684,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 16,
    "id": "2a85bf04",
    "metadata": {},
    "outputs": [
@@ -698,7 +697,7 @@
        " 'cost': 5.940406766675263}"
       ]
      },
-     "execution_count": 7,
+     "execution_count": 16,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -709,7 +708,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 17,
    "id": "b257da7f",
    "metadata": {},
    "outputs": [
@@ -768,7 +767,7 @@
          "type": "integer"
         }
        ],
-       "ref": "2bcba1ab-16c3-4f76-95bd-684add0a7d09",
+       "ref": "1625f89b-fb61-4149-9457-a7002bfbee02",
        "rows": [
         [
          "0",
@@ -843,7 +842,7 @@
        "0   52  "
       ]
      },
-     "execution_count": 29,
+     "execution_count": 17,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -855,7 +854,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 18,
    "id": "57a50c56",
    "metadata": {},
    "outputs": [

+ 10 - 1
python/bayesian/bayesian.py

@@ -1,7 +1,17 @@
 import numpy as np
 import scipy
 
+"""
+    Setting up scipy distribution to be used in Bayesian model
 
+    Input:
+        distr_str: string of scipy distribution
+        n_pars: int, number of parameters
+        parse_pars: function(pars) -> dict
+    
+    Return: 
+        (log_pdf, distr_sample)
+"""
 def setup_scipy_distr(distr_str, n_pars, parse_pars):
     
 
@@ -36,7 +46,6 @@ def setup_scipy_distr(distr_str, n_pars, parse_pars):
 
         O = Prob(Y=0)/Prob(Y=1)
 """
-
 class BayesianModelRegression:
     
     """

BIN
python/bayesian/results/bayesian_CI_cmp.pdf


BIN
python/bayesian/results/bayesian_fit.pdf