{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acd7e98d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "os.environ[\"R_HOME\"] = r\"C:\\Program Files\\R\\R-4.4.2\"  # Use raw string for Windows paths\n",
    "sys.path.append(r\"c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\")\n",
    "\n",
    "\n",
    "from utils import * \n",
    "# Core libraries\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    " \n",
    "\n",
    "# scikit-learn\n",
    "from sklearn.linear_model import LassoCV, RidgeCV\n",
    "from sklearn.metrics import mean_squared_error\n",
    "\n",
    "# rpy2 for R integration\n",
    "import rpy2.robjects as ro\n",
    "from rpy2.robjects import numpy2ri, r\n",
    "from rpy2.robjects.packages import importr\n",
    "\n",
    "# Activate NumPy-to-R conversion\n",
    "numpy2ri.activate()\n",
    "ashr = importr(\"ashr\")\n",
    "\n",
    "# torch (if used later in the project)\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.optim as optim\n",
    "from torch.utils.data import Dataset, DataLoader\n",
    "\n",
    " \n",
    "# Local utilities (if you have a utils.py file)\n",
    "from utils_mix import *\n",
    "from empirical_mdn import emdn_posterior_means\n",
    "from utils_mix import *\n",
    "from numerical_routine import *\n",
    "from distribution_operation import *\n",
    "from posterior_computation import posterior_mean_norm\n",
    "from cash_solver import Cash_posterior_means\n",
    "from ash import call_r_ash_fit_all_with_postmean\n",
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "from sklearn.metrics import mean_squared_error, mean_absolute_error\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "def col_scale(X, with_mean=True, with_std=True):\n",
    "    scaler = StandardScaler(with_mean=with_mean, with_std=with_std)\n",
    "    X_scaled = scaler.fit_transform(X)\n",
    "    return X_scaled, scaler.scale_\n",
    "\n",
    "\n",
    "def call_r_ash_fit_all_with_postmean(beta, sigma):\n",
    "    \"\"\"\n",
    "    Calls R's ash function and returns:\n",
    "    - log mixture weights\n",
    "    - mixture standard deviations\n",
    "    - posterior mean of beta\n",
    "    \"\"\"\n",
    "    from rpy2.rinterface_lib.sexp import NULLType\n",
    "\n",
    "    sebetahat = np.full_like(beta, sigma)\n",
    "    ash_obj = ashr.ash(betahat=beta, sebetahat=sebetahat, mixcompdist=\"normal\")\n",
    "\n",
    "    fitted_g = ash_obj.rx2(\"fitted_g\")\n",
    "    pi_r = np.array(fitted_g.rx2(\"pi\"), dtype=np.float32)\n",
    "    scale_r = np.array(fitted_g.rx2(\"sd\"), dtype=np.float32)\n",
    "\n",
    "    posterior_mean_r = ash_obj.rx2(\"result\").rx2(\"PosteriorMean\")\n",
    "    if isinstance(posterior_mean_r, NULLType):\n",
    "        raise RuntimeError(\"R ash() returned NULL for result$PosteriorMean\")\n",
    "    posterior_mean = np.array(posterior_mean_r, dtype=np.float32)\n",
    "\n",
    "    log_pi = np.log(np.clip(pi_r, 1e-12, 1.0))\n",
    "    return log_pi, scale_r, posterior_mean\n",
    "\n",
    "\n",
    "def get_data_loglik_normal(betahat, sebetahat, location, scale):\n",
    "    var = sebetahat[:, None] ** 2 + scale[None, :] ** 2\n",
    "    return -0.5 * (np.log(2 * np.pi * var) + (betahat[:, None] - location) ** 2 / var)\n",
    "\n",
    "\n",
    "def apply_log_sum_exp(data_loglik, log_pi):\n",
    "    combined_loglik = data_loglik + log_pi\n",
    "    return combined_loglik - logsumexp(combined_loglik, axis=1)[:, None]\n",
    "\n",
    "\n",
    "class PosteriorMeanNorm:\n",
    "    def __init__(self, post_mean, post_mean2, post_sd):\n",
    "        self.post_mean = post_mean\n",
    "        self.post_mean2 = post_mean2\n",
    "        self.post_sd = post_sd\n",
    "\n",
    "\n",
    "def posterior_mean_norm(betahat, sebetahat, log_pi, scale, location=None):\n",
    "    if location is None:\n",
    "        location = np.zeros_like(scale)\n",
    "\n",
    "    data_loglik = get_data_loglik_normal(betahat, sebetahat, location, scale)\n",
    "    log_post_assignment = apply_log_sum_exp(data_loglik, log_pi)\n",
    "\n",
    "    n, K = betahat.shape[0], scale.shape[0]\n",
    "    var = np.zeros((n, K))\n",
    "\n",
    "    if scale[0] == 0:\n",
    "        for i in range(n):\n",
    "            var[i, :] = np.concatenate(([0], 1 / ((1 / sebetahat[i]**2) + (1 / scale[1:]**2))))\n",
    "    else:\n",
    "        for i in range(n):\n",
    "            var[i, :] = 1 / ((1 / sebetahat[i]**2) + (1 / scale**2))\n",
    "\n",
    "    temp = np.zeros((n, K))\n",
    "    for i in range(n):\n",
    "        temp[i, :] = (var[i, :] / sebetahat[i]**2) * betahat[i] + location * (1 - var[i, :] / sebetahat[i]**2)\n",
    "\n",
    "    post_mean = np.sum(np.exp(log_post_assignment) * temp, axis=1)\n",
    "    post_mean2 = np.sum(np.exp(log_post_assignment) * (var + temp**2), axis=1)\n",
    "    post_sd = np.sqrt(post_mean2 - post_mean**2)\n",
    "    return PosteriorMeanNorm(post_mean, post_mean2, post_sd)\n",
    "def nash_mdn(X, y, sideinfo=None, maxit=4, damping=0.99, eb_kwargs=None):\n",
    "    k=0 \n",
    "    X = X.astype(np.float32)\n",
    "    y = y.astype(np.float32).flatten()\n",
    "    X, csd = col_scale(X)\n",
    "    y, ysd = col_scale(y.reshape(-1, 1))\n",
    "    y = y.flatten()\n",
    "\n",
    "    n, p = X.shape\n",
    "    sqn = np.sqrt(n).astype(np.float32)\n",
    "    beta = LassoCV(cv=5, max_iter=5000).fit(X, y).coef_\n",
    "\n",
    "    log_pi, scale, location = None, None, None\n",
    "    td_beta = []\n",
    "    model_param = None\n",
    "    pi0=0\n",
    "    \n",
    "    for o in range(maxit):\n",
    "        betahat_list, sebetahat_list = [], []\n",
    "        for k in range(p):\n",
    "            r = y - X @ beta\n",
    "            beta_new = beta.copy()\n",
    "            xk = X[:, k]\n",
    "            r_k = r + xk * beta_new[k]\n",
    "            betahat_k = np.dot(xk, r_k) / n\n",
    "            sebetahat_k = max(np.std(r_k) / sqn, 1e-4)\n",
    "            if 0<1: \n",
    "\n",
    "                beta_k_new = betahat_k\n",
    "                beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "             \n",
    "            else :\n",
    "                print(o)\n",
    "                pm = posterior_mean_norm(\n",
    "                    betahat=np.array([betahat_k]),\n",
    "                    sebetahat=np.array([sebetahat_k]),\n",
    "                    log_pi=np.log( np.clip( result.pi_np[k, :], 1e-12, 1.0)),\n",
    "                    location=result.location[k, :],\n",
    "                    scale=result.scale[k, :]\n",
    "                    )\n",
    "             \n",
    "                beta_k_new = pm.post_mean[0]\n",
    "\n",
    "            r += xk * (beta_new[k]  - beta_k_new)\n",
    "            beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "            beta_new[k]=beta_k_new\n",
    "            betahat_list.append(betahat_k)\n",
    "            sebetahat_list.append(sebetahat_k) \n",
    "\n",
    "\n",
    "        betahat_arr = np.array(betahat_list)\n",
    "        avg_se = np.mean(sebetahat_list)\n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ beta ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )   \n",
    " \n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ beta ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )\n",
    "        denom = n + p * (1 - pi0)\n",
    "        sigma_0 = np.sqrt(max((res_sq_final + sigma_0_term) / denom, 1e-8)) / sqn\n",
    "\n",
    "        res_sq = np.sum((y - X @ betahat_arr) ** 2)\n",
    "        drift_term = np.dot(betahat_arr,  betahat_arr) / np.sqrt(n + p)\n",
    "        s = np.sqrt((res_sq + drift_term)) / sqn\n",
    "\n",
    "        # Update drift_comp\n",
    "        drift_comp = (1 / (n / s**2 + 1 / sigma_0**2)) * (n / s**2)\n",
    "        if o<1: \n",
    "            # Update beta with ash\n",
    "            ash_input = betahat_arr   \n",
    "            result =emdn_posterior_means(X= sideinfo,\n",
    "                                            betahat= ash_input,\n",
    "                                            sebetahat=np.array(sebetahat_list)   )\n",
    "            emdn_posterior_means(X= sideinfo,\n",
    "                                          betahat= ash_input,\n",
    "                                          sebetahat= np.full_like(ash_input,sigma_0), **(eb_kwargs or {}))\n",
    "        else :\n",
    "            ash_input = drift_comp * betahat_arr + (1 - drift_comp) * result.post_mean\n",
    "            result =emdn_posterior_means(X= sideinfo,\n",
    "                                          betahat= ash_input,\n",
    "                                          sebetahat=np.full_like(ash_input,sigma_0)/sqn   )\n",
    "            log_pi= result.pi_np\n",
    "            beta =   result.post_mean\n",
    "\n",
    "\n",
    "  \n",
    "    out=   ysd *betahat_arr/ csd\n",
    "    return out\n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d580a463",
   "metadata": {},
   "outputs": [],
   "source": [
    " \n",
    "\n",
    " \n",
    "\n",
    "### === NASH main function === ###\n",
    "\n",
    "def nash_noinfo_dynamic_td(X, y, maxit=10,damping = 0.99):\n",
    "    X = X.astype(np.float32)\n",
    "    y = y.astype(np.float32).flatten()\n",
    "\n",
    "    # Standardize\n",
    "    X, csd = col_scale(X)\n",
    "    y, ysd = col_scale(y.reshape(-1, 1))\n",
    "    y = y.flatten()\n",
    "\n",
    "    n, p = X.shape\n",
    "    sqn = np.sqrt(n).astype(np.float32)\n",
    "\n",
    "    # Initialize via Lasso\n",
    "    lasso = LassoCV(cv=5, max_iter=5000)\n",
    "    lasso.fit(X, y)\n",
    "    beta = lasso.coef_\n",
    "\n",
    "    # Initialize prior as None\n",
    "    log_pi, scale, location = None, None, None\n",
    "    td_beta = []\n",
    "    pi0=0\n",
    "    for o in range(maxit):\n",
    "        r = y - X @ beta\n",
    "        beta_new = beta.copy()\n",
    "        betahat_list, sebetahat_list = [], []\n",
    "\n",
    "        for k in range(p):\n",
    "            xk = X[:, k]\n",
    "            r_k = r + xk * beta_new[k]\n",
    "            betahat_k = np.dot(xk, r_k) / n\n",
    "            sebetahat_k = max(np.std(r_k) / sqn, 1e-4)\n",
    "\n",
    "\n",
    "            if log_pi is None:\n",
    "                beta_k_new = betahat_k\n",
    "            else:\n",
    "                pm = posterior_mean_norm(\n",
    "                    betahat=np.array([betahat_k]),\n",
    "                    sebetahat=np.array([sigma_0]) ,  \n",
    "                    log_pi=log_pi,\n",
    "                    scale=scale,\n",
    "                    location=location\n",
    "                )\n",
    "                beta_k_new = pm.post_mean[0]\n",
    "            \n",
    "            r += xk * (beta_new[k]  - beta_k_new)\n",
    "            beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "            beta_new[k]=beta_k_new\n",
    "\n",
    "            betahat_list.append(betahat_k)\n",
    "            sebetahat_list.append(sebetahat_k)\n",
    "\n",
    "       \n",
    "        # Fit ASH on current beta and extract posterior mean\n",
    "        betahat_arr = np.array(betahat_list)\n",
    "        avg_se = np.mean(sebetahat_list)\n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ beta ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )\n",
    "        denom = n + p * (1 - pi0)\n",
    "        if denom <= 1e-8:\n",
    "            denom = n + p * 1e-3  # avoid divide by 0 or small number\n",
    "        sigma_0 = np.sqrt(max((res_sq_final + sigma_0_term) / denom, 1e-8)) / sqn\n",
    "       # residual = y - X @ beta\n",
    "       # residual_variance = np.mean(residual ** 2)\n",
    "       # sigma_0 = np.sqrt(residual_variance)\n",
    "        #print(sigma_0)\n",
    "\n",
    "\n",
    "        res_sq = np.sum((y - X @ betahat_arr) ** 2)\n",
    "        drift_term = np.dot(betahat_arr,  betahat_arr) / np.sqrt(n + p)\n",
    "        s = np.sqrt((res_sq + drift_term)) / sqn\n",
    "\n",
    "        # Update drift_comp\n",
    "        drift_comp = (1 / (n / s**2 + 1 / sigma_0**2)) * (n / s**2)\n",
    "\n",
    "        # Update beta with ash\n",
    "        ash_input = drift_comp * betahat_arr + (1 - drift_comp) * beta\n",
    "        log_pi, scale, postmean = call_r_ash_fit_all_with_postmean(ash_input, sigma_0)\n",
    "        pi0 =np.exp(log_pi[0])\n",
    "        location = np.zeros_like(scale)\n",
    "         # Replace with posterior mean from ASH\n",
    "\n",
    "        td_beta.append(ysd * beta / csd)\n",
    "        print(f\"Iteration {o+1} complete\")\n",
    "    beta = postmean.copy() \n",
    "    final_beta = ysd * beta / csd\n",
    "    #print(\"Final residual variance:\", np.var(y - X @ beta))\n",
    "    return final_beta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae250fd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_name=[\"Airpassenger\"]\n",
    "rmses, mads = [], []\n",
    "k =1\n",
    "\n",
    "base_path = Path(\"C:/Document/Serieux/Travail/Data_analysis_and_papers/nash_experiement/data_split\")\n",
    "result_path = Path(\"C:/Document/Serieux/Travail/Data_analysis_and_papers/nash_experiement/results_realdata\")\n",
    "datasets = [\"Airpassenger\"] \n",
    "dataset_path = Path(\"C:/Document/Serieux/Travail/Data_analysis_and_papers/nash_experiement/data_split/Airpassenger\")\n",
    "X_train = pd.read_csv(dataset_path / f\"X_train{k}.csv\").values.astype(np.float32)\n",
    "y_train = pd.read_csv(dataset_path / f\"y_train{k}.csv\").values.astype(np.float32).flatten()\n",
    "X_test = pd.read_csv(dataset_path / f\"X_test{k}.csv\").values.astype(np.float32)\n",
    "y_test = pd.read_csv(dataset_path / f\"y_test{k}.csv\").values.astype(np.float32).flatten()\n",
    " \n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e28bf7ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "lasso = LassoCV(cv=5, max_iter=5000)\n",
    "lasso.fit(X_train, y_test )\n",
    "betal = lasso.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7996018b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df9509d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = X_train.shape[1]\n",
    "\n",
    "# Create side info: a (p, 1) column vector with values 1 to p\n",
    "sideinfo_array = np.arange(1, p + 1).reshape(-1, 1).astype(np.float32)\n",
    "mu= combined = np.concatenate([ y_test,y_train]).mean()\n",
    "y_test=  y_test-mu\n",
    "y_train=y_train-mu\n",
    "# Now pass sideinfo to your model:\n",
    "beta_est = nash_mdn(X=  np.eye(144) , y=y_train, sideinfo=sideinfo_array, maxit=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d533773a",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_test = pd.read_csv(dataset_path / f\"y_test{k}.csv\").values.astype(np.float32).flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a38c0851",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred_test = X_test @ beta_est\n",
    "\n",
    "        # Metrics\n",
    "rmse = np.sqrt(mean_squared_error(y_test, y_pred_test))\n",
    "rmse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0899e26",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LassoCV\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "def col_scale(X, with_mean=True, with_std=True):\n",
    "    \"\"\"Standardize columns of X (mean=0, std=1).\"\"\"\n",
    "    scaler = StandardScaler(with_mean=with_mean, with_std=with_std)\n",
    "    X_scaled = scaler.fit_transform(X)\n",
    "    return X_scaled.astype(np.float32), scaler.scale_\n",
    "\n",
    "def nash_with_sideinfo(X_train, y_train, sideinfo_array, maxit=10, damping=0.99):\n",
    "    \"\"\"\n",
    "    Run NASH regression with side information using an iterative Empirical Bayes approach.\n",
    "    \n",
    "    Parameters:\n",
    "    - X_train: ndarray (n x p) input features\n",
    "    - y_train: ndarray (n,) response\n",
    "    - sideinfo_array: ndarray (p x d) side info for the prior\n",
    "    - maxit: int, number of coordinate ascent iterations\n",
    "    - damping: float, update damping coefficient in [0, 1]\n",
    "\n",
    "    Returns:\n",
    "    - beta_final: ndarray (p,) posterior mean of beta (rescaled to original y)\n",
    "    \"\"\"\n",
    "    X = np.eye(144) if X_train is None else X_train.astype(np.float32)\n",
    "    y = y_train.astype(np.float32).flatten()\n",
    "    sideinfo = sideinfo_array\n",
    "\n",
    "    # Standardize\n",
    "    X, csd = col_scale(X)\n",
    "    y, ysd = col_scale(y.reshape(-1, 1))\n",
    "    y = y.flatten()\n",
    "\n",
    "    n, p = X.shape\n",
    "    sqn = np.sqrt(n).astype(np.float32)\n",
    "\n",
    "    # Lasso initialization\n",
    "    lasso = LassoCV(cv=5, max_iter=5000)\n",
    "    lasso.fit(X, y)\n",
    "    beta = lasso.coef_\n",
    "\n",
    "    # Prior placeholders\n",
    "    log_pi, scale, location = None, None, None\n",
    "    pi0 = 0\n",
    "\n",
    "    for o in range(maxit):\n",
    "        betahat_list, sebetahat_list = [], []\n",
    "        beta_new = beta.copy()\n",
    "\n",
    "        for k in range(p):\n",
    "            r = y - X @ beta\n",
    "            xk = X[:, k]\n",
    "            r_k = r + xk * beta[k]\n",
    "            betahat_k = np.dot(xk, r_k) / n\n",
    "            sebetahat_k = max(np.std(r_k) / sqn, 1e-4)\n",
    "\n",
    "            if o == 0:\n",
    "                beta_k_new = damping * betahat_k + (1 - damping) * beta[k]\n",
    "            else:\n",
    "                pm = posterior_mean_norm(\n",
    "                    betahat=np.array([betahat_k]),\n",
    "                    sebetahat=np.array([sebetahat_k]),\n",
    "                    log_pi=np.log(np.clip(result.pi_np[k, :], 1e-12, 1.0)),\n",
    "                    location=result.location[k, :],\n",
    "                    scale=result.scale[k, :]\n",
    "                )\n",
    "                beta_k_new = pm.post_mean[0]\n",
    "                beta_k_new = damping * beta_k_new + (1 - damping) * beta[k]\n",
    "\n",
    "            beta_new[k] = beta_k_new\n",
    "            betahat_list.append(betahat_k)\n",
    "            sebetahat_list.append(sebetahat_k)\n",
    "\n",
    "        betahat_arr = np.array(betahat_list)\n",
    "        sebetahat_arr = np.array(sebetahat_list)\n",
    "        beta = beta_new.copy()\n",
    "\n",
    "        # Noise and drift estimation\n",
    "        res_sq = np.sum((y - X @ beta) ** 2)\n",
    "        drift_term = np.dot(betahat_arr, betahat_arr) / np.sqrt(n + p)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr)\n",
    "        sigma_0 = np.sqrt(max((res_sq + sigma_0_term) / (n + p * (1 - pi0)), 1e-8)) / sqn\n",
    "        s = np.sqrt(res_sq + drift_term) / sqn\n",
    "        drift_comp = (1 / (n / s**2 + 1 / sigma_0**2)) * (n / s**2)\n",
    "\n",
    "        # Prior update using Cash\n",
    "        if o == 0:\n",
    "            ash_input = betahat_arr\n",
    "        else:\n",
    "            ash_input = drift_comp * betahat_arr + (1 - drift_comp) * result.post_mean\n",
    "\n",
    "        result = Cash_posterior_means(\n",
    "            X=sideinfo,\n",
    "            betahat=ash_input,\n",
    "            sebetahat=np.full_like(ash_input, sigma_0) / sqn,\n",
    "            n_epochs=50\n",
    "        )\n",
    "\n",
    "        log_pi = result.pi_np\n",
    "        beta = result.post_mean\n",
    "\n",
    "    return ysd.flatten() * result.post_mean\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac33cbf6",
   "metadata": {},
   "outputs": [],
   "source": [
    "sideinfo_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65ee24a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_name=[\"Airpassenger\"]\n",
    "rmses, mads = [], []\n",
    "k =1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a58959b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/50,   Variance Loss: -47.9593\n",
      "Epoch 20/50,   Variance Loss: -71.2640\n",
      "Epoch 30/50,   Variance Loss: -78.3029\n",
      "Epoch 40/50,   Variance Loss: -78.4325\n",
      "Epoch 50/50,   Variance Loss: -78.4341\n",
      "Epoch 10/200,   Variance Loss: -44.4184\n",
      "Epoch 20/200,   Variance Loss: -65.1672\n",
      "Epoch 30/200,   Variance Loss: -72.6428\n",
      "Epoch 40/200,   Variance Loss: -75.2193\n",
      "Epoch 50/200,   Variance Loss: -76.9144\n",
      "Epoch 60/200,   Variance Loss: -79.2865\n",
      "Epoch 70/200,   Variance Loss: -80.1250\n",
      "Epoch 80/200,   Variance Loss: -80.7606\n",
      "Epoch 90/200,   Variance Loss: -81.6864\n",
      "Epoch 100/200,   Variance Loss: -83.1148\n",
      "Epoch 110/200,   Variance Loss: -84.5385\n",
      "Epoch 120/200,   Variance Loss: -84.8833\n",
      "Epoch 130/200,   Variance Loss: -85.7442\n",
      "Epoch 140/200,   Variance Loss: -86.2326\n",
      "Epoch 150/200,   Variance Loss: -86.4014\n",
      "Epoch 160/200,   Variance Loss: -86.9001\n",
      "Epoch 170/200,   Variance Loss: -86.7551\n",
      "Epoch 180/200,   Variance Loss: -86.9546\n",
      "Epoch 190/200,   Variance Loss: -87.0935\n",
      "Epoch 200/200,   Variance Loss: -87.3222\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 24.1757\n",
      "Epoch 20/200,   Variance Loss: -48.4465\n",
      "Epoch 30/200,   Variance Loss: -71.1072\n",
      "Epoch 40/200,   Variance Loss: -72.9101\n",
      "Epoch 50/200,   Variance Loss: -73.5285\n",
      "Epoch 60/200,   Variance Loss: -73.9515\n",
      "Epoch 70/200,   Variance Loss: -74.8136\n",
      "Epoch 80/200,   Variance Loss: -75.7470\n",
      "Epoch 90/200,   Variance Loss: -77.1480\n",
      "Epoch 100/200,   Variance Loss: -79.3679\n",
      "Epoch 110/200,   Variance Loss: -83.1773\n",
      "Epoch 120/200,   Variance Loss: -85.2891\n",
      "Epoch 130/200,   Variance Loss: -86.4096\n",
      "Epoch 140/200,   Variance Loss: -87.0166\n",
      "Epoch 150/200,   Variance Loss: -87.5265\n",
      "Epoch 160/200,   Variance Loss: -87.7643\n",
      "Epoch 170/200,   Variance Loss: -87.9823\n",
      "Epoch 180/200,   Variance Loss: -88.1392\n",
      "Epoch 190/200,   Variance Loss: -88.3306\n",
      "Epoch 200/200,   Variance Loss: -88.4434\n",
      "Epoch 10/200,   Variance Loss: 8.5774\n",
      "Epoch 20/200,   Variance Loss: -66.4128\n",
      "Epoch 30/200,   Variance Loss: -71.5680\n",
      "Epoch 40/200,   Variance Loss: -73.6627\n",
      "Epoch 50/200,   Variance Loss: -74.4708\n",
      "Epoch 60/200,   Variance Loss: -75.1410\n",
      "Epoch 70/200,   Variance Loss: -76.0340\n",
      "Epoch 80/200,   Variance Loss: -77.7434\n",
      "Epoch 90/200,   Variance Loss: -81.0129\n",
      "Epoch 100/200,   Variance Loss: -83.7756\n",
      "Epoch 110/200,   Variance Loss: -84.7890\n",
      "Epoch 120/200,   Variance Loss: -85.6487\n",
      "Epoch 130/200,   Variance Loss: -86.5521\n",
      "Epoch 140/200,   Variance Loss: -87.1523\n",
      "Epoch 150/200,   Variance Loss: -87.3346\n",
      "Epoch 160/200,   Variance Loss: -87.6810\n",
      "Epoch 170/200,   Variance Loss: -87.7971\n",
      "Epoch 180/200,   Variance Loss: -88.1672\n",
      "Epoch 190/200,   Variance Loss: -88.4402\n",
      "Epoch 200/200,   Variance Loss: -88.4528\n",
      "Epoch 10/200,   Variance Loss: 22.7373\n",
      "Epoch 20/200,   Variance Loss: -51.4719\n",
      "Epoch 30/200,   Variance Loss: -70.5659\n",
      "Epoch 40/200,   Variance Loss: -73.2219\n",
      "Epoch 50/200,   Variance Loss: -74.4505\n",
      "Epoch 60/200,   Variance Loss: -75.3480\n",
      "Epoch 70/200,   Variance Loss: -76.8425\n",
      "Epoch 80/200,   Variance Loss: -79.8600\n",
      "Epoch 90/200,   Variance Loss: -83.5113\n",
      "Epoch 100/200,   Variance Loss: -85.4813\n",
      "Epoch 110/200,   Variance Loss: -86.4599\n",
      "Epoch 120/200,   Variance Loss: -86.9060\n",
      "Epoch 130/200,   Variance Loss: -87.3645\n",
      "Epoch 140/200,   Variance Loss: -87.5132\n",
      "Epoch 150/200,   Variance Loss: -87.7479\n",
      "Epoch 160/200,   Variance Loss: -87.7042\n",
      "Epoch 170/200,   Variance Loss: -88.0998\n",
      "Epoch 180/200,   Variance Loss: -88.2993\n",
      "Epoch 190/200,   Variance Loss: -88.3294\n",
      "Epoch 200/200,   Variance Loss: -88.5235\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 10.2188\n",
      "Epoch 20/200,   Variance Loss: -49.5220\n",
      "Epoch 30/200,   Variance Loss: -70.5323\n",
      "Epoch 40/200,   Variance Loss: -72.8917\n",
      "Epoch 50/200,   Variance Loss: -73.6561\n",
      "Epoch 60/200,   Variance Loss: -74.3674\n",
      "Epoch 70/200,   Variance Loss: -75.1030\n",
      "Epoch 80/200,   Variance Loss: -76.4861\n",
      "Epoch 90/200,   Variance Loss: -79.4892\n",
      "Epoch 100/200,   Variance Loss: -83.2961\n",
      "Epoch 110/200,   Variance Loss: -85.3294\n",
      "Epoch 120/200,   Variance Loss: -86.4032\n",
      "Epoch 130/200,   Variance Loss: -87.2278\n",
      "Epoch 140/200,   Variance Loss: -87.3688\n",
      "Epoch 150/200,   Variance Loss: -87.6821\n",
      "Epoch 160/200,   Variance Loss: -88.1746\n",
      "Epoch 170/200,   Variance Loss: -88.3625\n",
      "Epoch 180/200,   Variance Loss: -88.1319\n",
      "Epoch 190/200,   Variance Loss: -88.3528\n",
      "Epoch 200/200,   Variance Loss: -88.2847\n",
      "Epoch 10/200,   Variance Loss: 5.7197\n",
      "Epoch 20/200,   Variance Loss: -63.7725\n",
      "Epoch 30/200,   Variance Loss: -67.6717\n",
      "Epoch 40/200,   Variance Loss: -71.0708\n",
      "Epoch 50/200,   Variance Loss: -73.2204\n",
      "Epoch 60/200,   Variance Loss: -73.8309\n",
      "Epoch 70/200,   Variance Loss: -74.4827\n",
      "Epoch 80/200,   Variance Loss: -76.2138\n",
      "Epoch 90/200,   Variance Loss: -80.3068\n",
      "Epoch 100/200,   Variance Loss: -83.8934\n",
      "Epoch 110/200,   Variance Loss: -84.4288\n",
      "Epoch 120/200,   Variance Loss: -84.5459\n",
      "Epoch 130/200,   Variance Loss: -84.6911\n",
      "Epoch 140/200,   Variance Loss: -85.0838\n",
      "Epoch 150/200,   Variance Loss: -85.9680\n",
      "Epoch 160/200,   Variance Loss: -86.8429\n",
      "Epoch 170/200,   Variance Loss: -87.1495\n",
      "Epoch 180/200,   Variance Loss: -87.5207\n",
      "Epoch 190/200,   Variance Loss: -87.7494\n",
      "Epoch 200/200,   Variance Loss: -87.9983\n",
      "Epoch 10/200,   Variance Loss: 11.6332\n",
      "Epoch 20/200,   Variance Loss: -65.5922\n",
      "Epoch 30/200,   Variance Loss: -69.7017\n",
      "Epoch 40/200,   Variance Loss: -73.7996\n",
      "Epoch 50/200,   Variance Loss: -74.7625\n",
      "Epoch 60/200,   Variance Loss: -75.7492\n",
      "Epoch 70/200,   Variance Loss: -77.0538\n",
      "Epoch 80/200,   Variance Loss: -79.2791\n",
      "Epoch 90/200,   Variance Loss: -82.6052\n",
      "Epoch 100/200,   Variance Loss: -84.8745\n",
      "Epoch 110/200,   Variance Loss: -86.0567\n",
      "Epoch 120/200,   Variance Loss: -86.7856\n",
      "Epoch 130/200,   Variance Loss: -87.2780\n",
      "Epoch 140/200,   Variance Loss: -87.6192\n",
      "Epoch 150/200,   Variance Loss: -87.9365\n",
      "Epoch 160/200,   Variance Loss: -88.0152\n",
      "Epoch 170/200,   Variance Loss: -88.1641\n",
      "Epoch 180/200,   Variance Loss: -88.3337\n",
      "Epoch 190/200,   Variance Loss: -88.4564\n",
      "Epoch 200/200,   Variance Loss: -88.6427\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 16.3129\n",
      "Epoch 20/200,   Variance Loss: -59.4997\n",
      "Epoch 30/200,   Variance Loss: -71.7137\n",
      "Epoch 40/200,   Variance Loss: -73.9092\n",
      "Epoch 50/200,   Variance Loss: -74.2919\n",
      "Epoch 60/200,   Variance Loss: -74.9846\n",
      "Epoch 70/200,   Variance Loss: -76.0084\n",
      "Epoch 80/200,   Variance Loss: -77.6395\n",
      "Epoch 90/200,   Variance Loss: -80.7771\n",
      "Epoch 100/200,   Variance Loss: -83.5678\n",
      "Epoch 110/200,   Variance Loss: -84.4837\n",
      "Epoch 120/200,   Variance Loss: -84.9218\n",
      "Epoch 130/200,   Variance Loss: -85.7539\n",
      "Epoch 140/200,   Variance Loss: -86.6014\n",
      "Epoch 150/200,   Variance Loss: -87.0021\n",
      "Epoch 160/200,   Variance Loss: -87.0950\n",
      "Epoch 170/200,   Variance Loss: -87.5919\n",
      "Epoch 180/200,   Variance Loss: -87.8921\n",
      "Epoch 190/200,   Variance Loss: -88.2190\n",
      "Epoch 200/200,   Variance Loss: -88.2436\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 15.9499\n",
      "Epoch 20/200,   Variance Loss: -62.1604\n",
      "Epoch 30/200,   Variance Loss: -71.0156\n",
      "Epoch 40/200,   Variance Loss: -73.2374\n",
      "Epoch 50/200,   Variance Loss: -74.4083\n",
      "Epoch 60/200,   Variance Loss: -75.2637\n",
      "Epoch 70/200,   Variance Loss: -76.6052\n",
      "Epoch 80/200,   Variance Loss: -78.9584\n",
      "Epoch 90/200,   Variance Loss: -83.0351\n",
      "Epoch 100/200,   Variance Loss: -85.5541\n",
      "Epoch 110/200,   Variance Loss: -86.6826\n",
      "Epoch 120/200,   Variance Loss: -87.2271\n",
      "Epoch 130/200,   Variance Loss: -87.5552\n",
      "Epoch 140/200,   Variance Loss: -87.9502\n",
      "Epoch 150/200,   Variance Loss: -88.1898\n",
      "Epoch 160/200,   Variance Loss: -88.3219\n",
      "Epoch 170/200,   Variance Loss: -88.2252\n",
      "Epoch 180/200,   Variance Loss: -88.5643\n",
      "Epoch 190/200,   Variance Loss: -88.6447\n",
      "Epoch 200/200,   Variance Loss: -88.8771\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -41.1361\n",
      "Epoch 20/50,   Variance Loss: -61.5010\n",
      "Epoch 30/50,   Variance Loss: -76.0802\n",
      "Epoch 40/50,   Variance Loss: -78.3067\n",
      "Epoch 50/50,   Variance Loss: -78.3966\n",
      "Epoch 10/200,   Variance Loss: -41.1110\n",
      "Epoch 20/200,   Variance Loss: -68.2491\n",
      "Epoch 30/200,   Variance Loss: -73.0208\n",
      "Epoch 40/200,   Variance Loss: -75.6634\n",
      "Epoch 50/200,   Variance Loss: -76.3126\n",
      "Epoch 60/200,   Variance Loss: -77.1585\n",
      "Epoch 70/200,   Variance Loss: -77.7538\n",
      "Epoch 80/200,   Variance Loss: -78.5015\n",
      "Epoch 90/200,   Variance Loss: -78.9753\n",
      "Epoch 100/200,   Variance Loss: -80.0352\n",
      "Epoch 110/200,   Variance Loss: -81.2153\n",
      "Epoch 120/200,   Variance Loss: -82.5103\n",
      "Epoch 130/200,   Variance Loss: -83.5112\n",
      "Epoch 140/200,   Variance Loss: -84.2804\n",
      "Epoch 150/200,   Variance Loss: -84.8759\n",
      "Epoch 160/200,   Variance Loss: -84.8550\n",
      "Epoch 170/200,   Variance Loss: -85.4043\n",
      "Epoch 180/200,   Variance Loss: -85.5418\n",
      "Epoch 190/200,   Variance Loss: -85.2801\n",
      "Epoch 200/200,   Variance Loss: -85.7261\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 2.4612\n",
      "Epoch 20/200,   Variance Loss: -73.2373\n",
      "Epoch 30/200,   Variance Loss: -72.2043\n",
      "Epoch 40/200,   Variance Loss: -75.1349\n",
      "Epoch 50/200,   Variance Loss: -75.4257\n",
      "Epoch 60/200,   Variance Loss: -75.7284\n",
      "Epoch 70/200,   Variance Loss: -76.1746\n",
      "Epoch 80/200,   Variance Loss: -76.8141\n",
      "Epoch 90/200,   Variance Loss: -78.9288\n",
      "Epoch 100/200,   Variance Loss: -82.2846\n",
      "Epoch 110/200,   Variance Loss: -83.2915\n",
      "Epoch 120/200,   Variance Loss: -83.8262\n",
      "Epoch 130/200,   Variance Loss: -84.2218\n",
      "Epoch 140/200,   Variance Loss: -84.5921\n",
      "Epoch 150/200,   Variance Loss: -84.9156\n",
      "Epoch 160/200,   Variance Loss: -85.2417\n",
      "Epoch 170/200,   Variance Loss: -85.7610\n",
      "Epoch 180/200,   Variance Loss: -86.8653\n",
      "Epoch 190/200,   Variance Loss: -89.3345\n",
      "Epoch 200/200,   Variance Loss: -90.7988\n",
      "Epoch 10/200,   Variance Loss: 13.9619\n",
      "Epoch 20/200,   Variance Loss: -58.8270\n",
      "Epoch 30/200,   Variance Loss: -70.4402\n",
      "Epoch 40/200,   Variance Loss: -73.6033\n",
      "Epoch 50/200,   Variance Loss: -75.8106\n",
      "Epoch 60/200,   Variance Loss: -78.0352\n",
      "Epoch 70/200,   Variance Loss: -81.5432\n",
      "Epoch 80/200,   Variance Loss: -82.8999\n",
      "Epoch 90/200,   Variance Loss: -83.4942\n",
      "Epoch 100/200,   Variance Loss: -83.7930\n",
      "Epoch 110/200,   Variance Loss: -84.1671\n",
      "Epoch 120/200,   Variance Loss: -84.4301\n",
      "Epoch 130/200,   Variance Loss: -84.8573\n",
      "Epoch 140/200,   Variance Loss: -85.2065\n",
      "Epoch 150/200,   Variance Loss: -85.5807\n",
      "Epoch 160/200,   Variance Loss: -85.9097\n",
      "Epoch 170/200,   Variance Loss: -86.2493\n",
      "Epoch 180/200,   Variance Loss: -87.0856\n",
      "Epoch 190/200,   Variance Loss: -87.9201\n",
      "Epoch 200/200,   Variance Loss: -89.0316\n",
      "Epoch 10/200,   Variance Loss: 4.2776\n",
      "Epoch 20/200,   Variance Loss: -62.5411\n",
      "Epoch 30/200,   Variance Loss: -71.9443\n",
      "Epoch 40/200,   Variance Loss: -74.5010\n",
      "Epoch 50/200,   Variance Loss: -74.8231\n",
      "Epoch 60/200,   Variance Loss: -74.9607\n",
      "Epoch 70/200,   Variance Loss: -75.2500\n",
      "Epoch 80/200,   Variance Loss: -75.5849\n",
      "Epoch 90/200,   Variance Loss: -76.0967\n",
      "Epoch 100/200,   Variance Loss: -76.4479\n",
      "Epoch 110/200,   Variance Loss: -77.0005\n",
      "Epoch 120/200,   Variance Loss: -78.6565\n",
      "Epoch 130/200,   Variance Loss: -81.8919\n",
      "Epoch 140/200,   Variance Loss: -83.0793\n",
      "Epoch 150/200,   Variance Loss: -83.5143\n",
      "Epoch 160/200,   Variance Loss: -83.7491\n",
      "Epoch 170/200,   Variance Loss: -84.0842\n",
      "Epoch 180/200,   Variance Loss: -84.3896\n",
      "Epoch 190/200,   Variance Loss: -84.7620\n",
      "Epoch 200/200,   Variance Loss: -84.9240\n",
      "Epoch 10/200,   Variance Loss: 16.2337\n",
      "Epoch 20/200,   Variance Loss: -54.0747\n",
      "Epoch 30/200,   Variance Loss: -71.3711\n",
      "Epoch 40/200,   Variance Loss: -73.3456\n",
      "Epoch 50/200,   Variance Loss: -75.0579\n",
      "Epoch 60/200,   Variance Loss: -75.5986\n",
      "Epoch 70/200,   Variance Loss: -76.3749\n",
      "Epoch 80/200,   Variance Loss: -78.3046\n",
      "Epoch 90/200,   Variance Loss: -81.4500\n",
      "Epoch 100/200,   Variance Loss: -82.7254\n",
      "Epoch 110/200,   Variance Loss: -83.3031\n",
      "Epoch 120/200,   Variance Loss: -83.6294\n",
      "Epoch 130/200,   Variance Loss: -83.8711\n",
      "Epoch 140/200,   Variance Loss: -84.2384\n",
      "Epoch 150/200,   Variance Loss: -84.4521\n",
      "Epoch 160/200,   Variance Loss: -84.5486\n",
      "Epoch 170/200,   Variance Loss: -84.9686\n",
      "Epoch 180/200,   Variance Loss: -85.3000\n",
      "Epoch 190/200,   Variance Loss: -85.4994\n",
      "Epoch 200/200,   Variance Loss: -85.7419\n",
      "Epoch 10/200,   Variance Loss: 3.0203\n",
      "Epoch 20/200,   Variance Loss: -67.2381\n",
      "Epoch 30/200,   Variance Loss: -71.7529\n",
      "Epoch 40/200,   Variance Loss: -74.8677\n",
      "Epoch 50/200,   Variance Loss: -75.4076\n",
      "Epoch 60/200,   Variance Loss: -76.4350\n",
      "Epoch 70/200,   Variance Loss: -79.0146\n",
      "Epoch 80/200,   Variance Loss: -82.1709\n",
      "Epoch 90/200,   Variance Loss: -83.0523\n",
      "Epoch 100/200,   Variance Loss: -83.3758\n",
      "Epoch 110/200,   Variance Loss: -83.7055\n",
      "Epoch 120/200,   Variance Loss: -83.7642\n",
      "Epoch 130/200,   Variance Loss: -84.0449\n",
      "Epoch 140/200,   Variance Loss: -84.2995\n",
      "Epoch 150/200,   Variance Loss: -84.5954\n",
      "Epoch 160/200,   Variance Loss: -84.7868\n",
      "Epoch 170/200,   Variance Loss: -85.1841\n",
      "Epoch 180/200,   Variance Loss: -85.4570\n",
      "Epoch 190/200,   Variance Loss: -85.6981\n",
      "Epoch 200/200,   Variance Loss: -85.9650\n",
      "Epoch 10/200,   Variance Loss: 1.5145\n",
      "Epoch 20/200,   Variance Loss: -69.5251\n",
      "Epoch 30/200,   Variance Loss: -72.0547\n",
      "Epoch 40/200,   Variance Loss: -74.5715\n",
      "Epoch 50/200,   Variance Loss: -75.1437\n",
      "Epoch 60/200,   Variance Loss: -75.9133\n",
      "Epoch 70/200,   Variance Loss: -77.8700\n",
      "Epoch 80/200,   Variance Loss: -81.3295\n",
      "Epoch 90/200,   Variance Loss: -82.4166\n",
      "Epoch 100/200,   Variance Loss: -82.8993\n",
      "Epoch 110/200,   Variance Loss: -83.1145\n",
      "Epoch 120/200,   Variance Loss: -83.3222\n",
      "Epoch 130/200,   Variance Loss: -83.4183\n",
      "Epoch 140/200,   Variance Loss: -83.8122\n",
      "Epoch 150/200,   Variance Loss: -84.0976\n",
      "Epoch 160/200,   Variance Loss: -84.3647\n",
      "Epoch 170/200,   Variance Loss: -84.7264\n",
      "Epoch 180/200,   Variance Loss: -84.9943\n",
      "Epoch 190/200,   Variance Loss: -85.2618\n",
      "Epoch 200/200,   Variance Loss: -85.5338\n",
      "Epoch 10/200,   Variance Loss: 14.6620\n",
      "Epoch 20/200,   Variance Loss: -68.8814\n",
      "Epoch 30/200,   Variance Loss: -72.8011\n",
      "Epoch 40/200,   Variance Loss: -74.8283\n",
      "Epoch 50/200,   Variance Loss: -75.2492\n",
      "Epoch 60/200,   Variance Loss: -75.9258\n",
      "Epoch 70/200,   Variance Loss: -77.3751\n",
      "Epoch 80/200,   Variance Loss: -80.6649\n",
      "Epoch 90/200,   Variance Loss: -82.2281\n",
      "Epoch 100/200,   Variance Loss: -82.5500\n",
      "Epoch 110/200,   Variance Loss: -82.9102\n",
      "Epoch 120/200,   Variance Loss: -82.8863\n",
      "Epoch 130/200,   Variance Loss: -83.1106\n",
      "Epoch 140/200,   Variance Loss: -83.3233\n",
      "Epoch 150/200,   Variance Loss: -83.5821\n",
      "Epoch 160/200,   Variance Loss: -84.2761\n",
      "Epoch 170/200,   Variance Loss: -85.7214\n",
      "Epoch 180/200,   Variance Loss: -86.9117\n",
      "Epoch 190/200,   Variance Loss: -87.3776\n",
      "Epoch 200/200,   Variance Loss: -87.8601\n",
      "Epoch 10/200,   Variance Loss: -5.2104\n",
      "Epoch 20/200,   Variance Loss: -72.2126\n",
      "Epoch 30/200,   Variance Loss: -73.2017\n",
      "Epoch 40/200,   Variance Loss: -75.3139\n",
      "Epoch 50/200,   Variance Loss: -75.6819\n",
      "Epoch 60/200,   Variance Loss: -76.1278\n",
      "Epoch 70/200,   Variance Loss: -76.7554\n",
      "Epoch 80/200,   Variance Loss: -78.0752\n",
      "Epoch 90/200,   Variance Loss: -80.9145\n",
      "Epoch 100/200,   Variance Loss: -82.7513\n",
      "Epoch 110/200,   Variance Loss: -83.2125\n",
      "Epoch 120/200,   Variance Loss: -83.5051\n",
      "Epoch 130/200,   Variance Loss: -83.6382\n",
      "Epoch 140/200,   Variance Loss: -83.7959\n",
      "Epoch 150/200,   Variance Loss: -84.0271\n",
      "Epoch 160/200,   Variance Loss: -84.4455\n",
      "Epoch 170/200,   Variance Loss: -85.0187\n",
      "Epoch 180/200,   Variance Loss: -85.9278\n",
      "Epoch 190/200,   Variance Loss: -88.1883\n",
      "Epoch 200/200,   Variance Loss: -89.5445\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -49.9392\n",
      "Epoch 20/50,   Variance Loss: -73.5338\n",
      "Epoch 30/50,   Variance Loss: -78.3977\n",
      "Epoch 40/50,   Variance Loss: -78.4035\n",
      "Epoch 50/50,   Variance Loss: -78.4037\n",
      "Epoch 10/200,   Variance Loss: -44.6795\n",
      "Epoch 20/200,   Variance Loss: -65.9133\n",
      "Epoch 30/200,   Variance Loss: -74.2849\n",
      "Epoch 40/200,   Variance Loss: -76.6569\n",
      "Epoch 50/200,   Variance Loss: -78.0753\n",
      "Epoch 60/200,   Variance Loss: -80.3891\n",
      "Epoch 70/200,   Variance Loss: -84.6006\n",
      "Epoch 80/200,   Variance Loss: -86.1220\n",
      "Epoch 90/200,   Variance Loss: -86.6258\n",
      "Epoch 100/200,   Variance Loss: -87.1969\n",
      "Epoch 110/200,   Variance Loss: -87.7537\n",
      "Epoch 120/200,   Variance Loss: -88.4878\n",
      "Epoch 130/200,   Variance Loss: -88.7781\n",
      "Epoch 140/200,   Variance Loss: -89.0187\n",
      "Epoch 150/200,   Variance Loss: -89.1195\n",
      "Epoch 160/200,   Variance Loss: -89.0032\n",
      "Epoch 170/200,   Variance Loss: -89.1313\n",
      "Epoch 180/200,   Variance Loss: -89.2921\n",
      "Epoch 190/200,   Variance Loss: -89.4998\n",
      "Epoch 200/200,   Variance Loss: -89.4524\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -45.5581\n",
      "Epoch 20/200,   Variance Loss: -69.6197\n",
      "Epoch 30/200,   Variance Loss: -74.8885\n",
      "Epoch 40/200,   Variance Loss: -77.3380\n",
      "Epoch 50/200,   Variance Loss: -79.5061\n",
      "Epoch 60/200,   Variance Loss: -83.4088\n",
      "Epoch 70/200,   Variance Loss: -86.1984\n",
      "Epoch 80/200,   Variance Loss: -87.2463\n",
      "Epoch 90/200,   Variance Loss: -88.0863\n",
      "Epoch 100/200,   Variance Loss: -88.6079\n",
      "Epoch 110/200,   Variance Loss: -88.9280\n",
      "Epoch 120/200,   Variance Loss: -89.3827\n",
      "Epoch 130/200,   Variance Loss: -89.4371\n",
      "Epoch 140/200,   Variance Loss: -89.6391\n",
      "Epoch 150/200,   Variance Loss: -89.6640\n",
      "Epoch 160/200,   Variance Loss: -89.8098\n",
      "Epoch 170/200,   Variance Loss: -89.8669\n",
      "Epoch 180/200,   Variance Loss: -89.8184\n",
      "Epoch 190/200,   Variance Loss: -89.8685\n",
      "Epoch 200/200,   Variance Loss: -89.8752\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 20.9431\n",
      "Epoch 20/200,   Variance Loss: -58.7749\n",
      "Epoch 30/200,   Variance Loss: -71.5925\n",
      "Epoch 40/200,   Variance Loss: -73.8666\n",
      "Epoch 50/200,   Variance Loss: -75.1624\n",
      "Epoch 60/200,   Variance Loss: -75.8064\n",
      "Epoch 70/200,   Variance Loss: -76.5134\n",
      "Epoch 80/200,   Variance Loss: -77.4138\n",
      "Epoch 90/200,   Variance Loss: -78.2012\n",
      "Epoch 100/200,   Variance Loss: -79.7091\n",
      "Epoch 110/200,   Variance Loss: -81.6152\n",
      "Epoch 120/200,   Variance Loss: -83.9079\n",
      "Epoch 130/200,   Variance Loss: -85.8999\n",
      "Epoch 140/200,   Variance Loss: -86.9627\n",
      "Epoch 150/200,   Variance Loss: -87.9916\n",
      "Epoch 160/200,   Variance Loss: -88.6708\n",
      "Epoch 170/200,   Variance Loss: -88.8156\n",
      "Epoch 180/200,   Variance Loss: -89.2167\n",
      "Epoch 190/200,   Variance Loss: -89.5690\n",
      "Epoch 200/200,   Variance Loss: -89.9525\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 16.3323\n",
      "Epoch 20/200,   Variance Loss: -57.7219\n",
      "Epoch 30/200,   Variance Loss: -70.7716\n",
      "Epoch 40/200,   Variance Loss: -74.9696\n",
      "Epoch 50/200,   Variance Loss: -75.9074\n",
      "Epoch 60/200,   Variance Loss: -76.8941\n",
      "Epoch 70/200,   Variance Loss: -78.1491\n",
      "Epoch 80/200,   Variance Loss: -79.9276\n",
      "Epoch 90/200,   Variance Loss: -82.6493\n",
      "Epoch 100/200,   Variance Loss: -85.1735\n",
      "Epoch 110/200,   Variance Loss: -86.0690\n",
      "Epoch 120/200,   Variance Loss: -86.7214\n",
      "Epoch 130/200,   Variance Loss: -87.6502\n",
      "Epoch 140/200,   Variance Loss: -88.4352\n",
      "Epoch 150/200,   Variance Loss: -88.7833\n",
      "Epoch 160/200,   Variance Loss: -89.0158\n",
      "Epoch 170/200,   Variance Loss: -89.4432\n",
      "Epoch 180/200,   Variance Loss: -89.7348\n",
      "Epoch 190/200,   Variance Loss: -90.0274\n",
      "Epoch 200/200,   Variance Loss: -89.9660\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 22.3314\n",
      "Epoch 20/200,   Variance Loss: -46.3929\n",
      "Epoch 30/200,   Variance Loss: -62.0353\n",
      "Epoch 40/200,   Variance Loss: -69.0296\n",
      "Epoch 50/200,   Variance Loss: -73.4491\n",
      "Epoch 60/200,   Variance Loss: -74.1124\n",
      "Epoch 70/200,   Variance Loss: -74.3318\n",
      "Epoch 80/200,   Variance Loss: -74.6802\n",
      "Epoch 90/200,   Variance Loss: -75.2895\n",
      "Epoch 100/200,   Variance Loss: -76.0771\n",
      "Epoch 110/200,   Variance Loss: -77.7115\n",
      "Epoch 120/200,   Variance Loss: -80.7870\n",
      "Epoch 130/200,   Variance Loss: -84.9089\n",
      "Epoch 140/200,   Variance Loss: -86.8479\n",
      "Epoch 150/200,   Variance Loss: -88.1504\n",
      "Epoch 160/200,   Variance Loss: -88.8129\n",
      "Epoch 170/200,   Variance Loss: -89.1193\n",
      "Epoch 180/200,   Variance Loss: -89.4903\n",
      "Epoch 190/200,   Variance Loss: -89.8441\n",
      "Epoch 200/200,   Variance Loss: -90.0659\n",
      "Epoch 10/200,   Variance Loss: 11.7586\n",
      "Epoch 20/200,   Variance Loss: -70.4755\n",
      "Epoch 30/200,   Variance Loss: -73.6361\n",
      "Epoch 40/200,   Variance Loss: -75.4322\n",
      "Epoch 50/200,   Variance Loss: -76.3107\n",
      "Epoch 60/200,   Variance Loss: -77.1659\n",
      "Epoch 70/200,   Variance Loss: -78.1573\n",
      "Epoch 80/200,   Variance Loss: -79.6435\n",
      "Epoch 90/200,   Variance Loss: -81.7022\n",
      "Epoch 100/200,   Variance Loss: -84.4592\n",
      "Epoch 110/200,   Variance Loss: -86.0986\n",
      "Epoch 120/200,   Variance Loss: -87.2958\n",
      "Epoch 130/200,   Variance Loss: -87.9281\n",
      "Epoch 140/200,   Variance Loss: -88.7429\n",
      "Epoch 150/200,   Variance Loss: -88.7913\n",
      "Epoch 160/200,   Variance Loss: -89.4531\n",
      "Epoch 170/200,   Variance Loss: -89.7999\n",
      "Epoch 180/200,   Variance Loss: -90.0887\n",
      "Epoch 190/200,   Variance Loss: -90.4150\n",
      "Epoch 200/200,   Variance Loss: -90.1709\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 23.7227\n",
      "Epoch 20/200,   Variance Loss: -55.8697\n",
      "Epoch 30/200,   Variance Loss: -71.4826\n",
      "Epoch 40/200,   Variance Loss: -73.6503\n",
      "Epoch 50/200,   Variance Loss: -75.0208\n",
      "Epoch 60/200,   Variance Loss: -75.7655\n",
      "Epoch 70/200,   Variance Loss: -77.2458\n",
      "Epoch 80/200,   Variance Loss: -79.8711\n",
      "Epoch 90/200,   Variance Loss: -83.8997\n",
      "Epoch 100/200,   Variance Loss: -85.3044\n",
      "Epoch 110/200,   Variance Loss: -85.4972\n",
      "Epoch 120/200,   Variance Loss: -85.5705\n",
      "Epoch 130/200,   Variance Loss: -86.1134\n",
      "Epoch 140/200,   Variance Loss: -86.7691\n",
      "Epoch 150/200,   Variance Loss: -87.6138\n",
      "Epoch 160/200,   Variance Loss: -88.6057\n",
      "Epoch 170/200,   Variance Loss: -89.3328\n",
      "Epoch 180/200,   Variance Loss: -89.6162\n",
      "Epoch 190/200,   Variance Loss: -89.8787\n",
      "Epoch 200/200,   Variance Loss: -90.1025\n",
      "Epoch 10/200,   Variance Loss: 4.0956\n",
      "Epoch 20/200,   Variance Loss: -70.4038\n",
      "Epoch 30/200,   Variance Loss: -72.4051\n",
      "Epoch 40/200,   Variance Loss: -74.3880\n",
      "Epoch 50/200,   Variance Loss: -75.1338\n",
      "Epoch 60/200,   Variance Loss: -76.2097\n",
      "Epoch 70/200,   Variance Loss: -77.9829\n",
      "Epoch 80/200,   Variance Loss: -81.6109\n",
      "Epoch 90/200,   Variance Loss: -84.9111\n",
      "Epoch 100/200,   Variance Loss: -86.2828\n",
      "Epoch 110/200,   Variance Loss: -87.2865\n",
      "Epoch 120/200,   Variance Loss: -88.1553\n",
      "Epoch 130/200,   Variance Loss: -88.4660\n",
      "Epoch 140/200,   Variance Loss: -88.8811\n",
      "Epoch 150/200,   Variance Loss: -89.2995\n",
      "Epoch 160/200,   Variance Loss: -89.6779\n",
      "Epoch 170/200,   Variance Loss: -90.0468\n",
      "Epoch 180/200,   Variance Loss: -90.1050\n",
      "Epoch 190/200,   Variance Loss: -90.1688\n",
      "Epoch 200/200,   Variance Loss: -90.4011\n",
      "Epoch 10/200,   Variance Loss: 20.6067\n",
      "Epoch 20/200,   Variance Loss: -66.2958\n",
      "Epoch 30/200,   Variance Loss: -72.0978\n",
      "Epoch 40/200,   Variance Loss: -74.3871\n",
      "Epoch 50/200,   Variance Loss: -75.5312\n",
      "Epoch 60/200,   Variance Loss: -76.5519\n",
      "Epoch 70/200,   Variance Loss: -78.1552\n",
      "Epoch 80/200,   Variance Loss: -81.1663\n",
      "Epoch 90/200,   Variance Loss: -84.5058\n",
      "Epoch 100/200,   Variance Loss: -86.1928\n",
      "Epoch 110/200,   Variance Loss: -87.1621\n",
      "Epoch 120/200,   Variance Loss: -88.0015\n",
      "Epoch 130/200,   Variance Loss: -88.4944\n",
      "Epoch 140/200,   Variance Loss: -88.5371\n",
      "Epoch 150/200,   Variance Loss: -88.9928\n",
      "Epoch 160/200,   Variance Loss: -89.0433\n",
      "Epoch 170/200,   Variance Loss: -89.6272\n",
      "Epoch 180/200,   Variance Loss: -89.9937\n",
      "Epoch 190/200,   Variance Loss: -90.1777\n",
      "Epoch 200/200,   Variance Loss: -90.2326\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -48.3008\n",
      "Epoch 20/50,   Variance Loss: -75.8863\n",
      "Epoch 30/50,   Variance Loss: -77.9030\n",
      "Epoch 40/50,   Variance Loss: -78.3843\n",
      "Epoch 50/50,   Variance Loss: -78.3993\n",
      "Epoch 10/200,   Variance Loss: -50.8380\n",
      "Epoch 20/200,   Variance Loss: -73.3394\n",
      "Epoch 30/200,   Variance Loss: -75.4565\n",
      "Epoch 40/200,   Variance Loss: -76.3402\n",
      "Epoch 50/200,   Variance Loss: -77.3352\n",
      "Epoch 60/200,   Variance Loss: -79.5667\n",
      "Epoch 70/200,   Variance Loss: -81.0165\n",
      "Epoch 80/200,   Variance Loss: -81.7504\n",
      "Epoch 90/200,   Variance Loss: -83.2530\n",
      "Epoch 100/200,   Variance Loss: -84.9345\n",
      "Epoch 110/200,   Variance Loss: -85.5948\n",
      "Epoch 120/200,   Variance Loss: -85.7046\n",
      "Epoch 130/200,   Variance Loss: -85.6944\n",
      "Epoch 140/200,   Variance Loss: -85.8940\n",
      "Epoch 150/200,   Variance Loss: -85.9920\n",
      "Epoch 160/200,   Variance Loss: -85.9824\n",
      "Epoch 170/200,   Variance Loss: -85.9969\n",
      "Epoch 180/200,   Variance Loss: -86.1836\n",
      "Epoch 190/200,   Variance Loss: -86.1457\n",
      "Epoch 200/200,   Variance Loss: -86.2653\n",
      "Epoch 10/200,   Variance Loss: 18.7441\n",
      "Epoch 20/200,   Variance Loss: -64.3423\n",
      "Epoch 30/200,   Variance Loss: -70.7852\n",
      "Epoch 40/200,   Variance Loss: -72.6527\n",
      "Epoch 50/200,   Variance Loss: -73.7293\n",
      "Epoch 60/200,   Variance Loss: -75.4783\n",
      "Epoch 70/200,   Variance Loss: -78.2713\n",
      "Epoch 80/200,   Variance Loss: -80.3548\n",
      "Epoch 90/200,   Variance Loss: -82.4947\n",
      "Epoch 100/200,   Variance Loss: -83.9021\n",
      "Epoch 110/200,   Variance Loss: -85.2694\n",
      "Epoch 120/200,   Variance Loss: -86.4385\n",
      "Epoch 130/200,   Variance Loss: -87.0703\n",
      "Epoch 140/200,   Variance Loss: -87.4188\n",
      "Epoch 150/200,   Variance Loss: -87.5169\n",
      "Epoch 160/200,   Variance Loss: -87.6312\n",
      "Epoch 170/200,   Variance Loss: -87.7079\n",
      "Epoch 180/200,   Variance Loss: -87.9581\n",
      "Epoch 190/200,   Variance Loss: -88.1901\n",
      "Epoch 200/200,   Variance Loss: -88.2201\n",
      "Epoch 10/200,   Variance Loss: 9.0557\n",
      "Epoch 20/200,   Variance Loss: -66.6881\n",
      "Epoch 30/200,   Variance Loss: -71.2339\n",
      "Epoch 40/200,   Variance Loss: -72.5354\n",
      "Epoch 50/200,   Variance Loss: -73.1081\n",
      "Epoch 60/200,   Variance Loss: -73.5265\n",
      "Epoch 70/200,   Variance Loss: -74.7350\n",
      "Epoch 80/200,   Variance Loss: -77.9722\n",
      "Epoch 90/200,   Variance Loss: -80.4301\n",
      "Epoch 100/200,   Variance Loss: -80.7743\n",
      "Epoch 110/200,   Variance Loss: -80.8268\n",
      "Epoch 120/200,   Variance Loss: -80.7806\n",
      "Epoch 130/200,   Variance Loss: -80.8015\n",
      "Epoch 140/200,   Variance Loss: -80.6868\n",
      "Epoch 150/200,   Variance Loss: -80.9181\n",
      "Epoch 160/200,   Variance Loss: -80.9019\n",
      "Epoch 170/200,   Variance Loss: -80.8999\n",
      "Epoch 180/200,   Variance Loss: -81.1180\n",
      "Epoch 190/200,   Variance Loss: -81.2909\n",
      "Epoch 200/200,   Variance Loss: -81.4806\n",
      "Epoch 10/200,   Variance Loss: 12.9915\n",
      "Epoch 20/200,   Variance Loss: -56.8308\n",
      "Epoch 30/200,   Variance Loss: -70.1876\n",
      "Epoch 40/200,   Variance Loss: -72.3907\n",
      "Epoch 50/200,   Variance Loss: -73.0632\n",
      "Epoch 60/200,   Variance Loss: -73.5958\n",
      "Epoch 70/200,   Variance Loss: -75.1042\n",
      "Epoch 80/200,   Variance Loss: -78.9571\n",
      "Epoch 90/200,   Variance Loss: -80.7008\n",
      "Epoch 100/200,   Variance Loss: -80.9442\n",
      "Epoch 110/200,   Variance Loss: -80.9102\n",
      "Epoch 120/200,   Variance Loss: -80.9252\n",
      "Epoch 130/200,   Variance Loss: -80.9880\n",
      "Epoch 140/200,   Variance Loss: -80.7781\n",
      "Epoch 150/200,   Variance Loss: -80.9352\n",
      "Epoch 160/200,   Variance Loss: -80.8073\n",
      "Epoch 170/200,   Variance Loss: -81.0578\n",
      "Epoch 180/200,   Variance Loss: -81.0037\n",
      "Epoch 190/200,   Variance Loss: -81.0165\n",
      "Epoch 200/200,   Variance Loss: -81.0947\n",
      "Epoch 10/200,   Variance Loss: 6.2458\n",
      "Epoch 20/200,   Variance Loss: -65.2343\n",
      "Epoch 30/200,   Variance Loss: -71.3163\n",
      "Epoch 40/200,   Variance Loss: -72.8848\n",
      "Epoch 50/200,   Variance Loss: -73.9100\n",
      "Epoch 60/200,   Variance Loss: -74.6796\n",
      "Epoch 70/200,   Variance Loss: -75.7519\n",
      "Epoch 80/200,   Variance Loss: -77.4706\n",
      "Epoch 90/200,   Variance Loss: -79.5286\n",
      "Epoch 100/200,   Variance Loss: -81.0505\n",
      "Epoch 110/200,   Variance Loss: -81.7311\n",
      "Epoch 120/200,   Variance Loss: -82.8515\n",
      "Epoch 130/200,   Variance Loss: -86.1217\n",
      "Epoch 140/200,   Variance Loss: -87.1305\n",
      "Epoch 150/200,   Variance Loss: -87.2394\n",
      "Epoch 160/200,   Variance Loss: -87.5822\n",
      "Epoch 170/200,   Variance Loss: -87.4124\n",
      "Epoch 180/200,   Variance Loss: -87.8394\n",
      "Epoch 190/200,   Variance Loss: -88.0748\n",
      "Epoch 200/200,   Variance Loss: -88.2312\n",
      "Epoch 10/200,   Variance Loss: -1.4691\n",
      "Epoch 20/200,   Variance Loss: -67.5615\n",
      "Epoch 30/200,   Variance Loss: -71.2116\n",
      "Epoch 40/200,   Variance Loss: -73.1309\n",
      "Epoch 50/200,   Variance Loss: -73.7912\n",
      "Epoch 60/200,   Variance Loss: -75.2766\n",
      "Epoch 70/200,   Variance Loss: -78.6585\n",
      "Epoch 80/200,   Variance Loss: -80.6167\n",
      "Epoch 90/200,   Variance Loss: -82.4229\n",
      "Epoch 100/200,   Variance Loss: -83.5014\n",
      "Epoch 110/200,   Variance Loss: -83.7396\n",
      "Epoch 120/200,   Variance Loss: -83.7853\n",
      "Epoch 130/200,   Variance Loss: -83.8953\n",
      "Epoch 140/200,   Variance Loss: -83.9756\n",
      "Epoch 150/200,   Variance Loss: -83.9532\n",
      "Epoch 160/200,   Variance Loss: -83.9760\n",
      "Epoch 170/200,   Variance Loss: -84.0040\n",
      "Epoch 180/200,   Variance Loss: -84.1185\n",
      "Epoch 190/200,   Variance Loss: -84.1480\n",
      "Epoch 200/200,   Variance Loss: -84.2386\n",
      "Epoch 10/200,   Variance Loss: 11.1980\n",
      "Epoch 20/200,   Variance Loss: -64.5667\n",
      "Epoch 30/200,   Variance Loss: -71.4860\n",
      "Epoch 40/200,   Variance Loss: -72.9115\n",
      "Epoch 50/200,   Variance Loss: -73.7982\n",
      "Epoch 60/200,   Variance Loss: -74.4946\n",
      "Epoch 70/200,   Variance Loss: -75.8104\n",
      "Epoch 80/200,   Variance Loss: -78.4446\n",
      "Epoch 90/200,   Variance Loss: -82.1234\n",
      "Epoch 100/200,   Variance Loss: -83.6146\n",
      "Epoch 110/200,   Variance Loss: -84.2266\n",
      "Epoch 120/200,   Variance Loss: -84.7392\n",
      "Epoch 130/200,   Variance Loss: -85.1931\n",
      "Epoch 140/200,   Variance Loss: -85.6820\n",
      "Epoch 150/200,   Variance Loss: -86.6958\n",
      "Epoch 160/200,   Variance Loss: -87.1738\n",
      "Epoch 170/200,   Variance Loss: -87.4083\n",
      "Epoch 180/200,   Variance Loss: -87.5452\n",
      "Epoch 190/200,   Variance Loss: -87.7151\n",
      "Epoch 200/200,   Variance Loss: -87.7533\n",
      "Epoch 10/200,   Variance Loss: 20.7778\n",
      "Epoch 20/200,   Variance Loss: -60.6757\n",
      "Epoch 30/200,   Variance Loss: -68.7109\n",
      "Epoch 40/200,   Variance Loss: -72.5222\n",
      "Epoch 50/200,   Variance Loss: -73.3601\n",
      "Epoch 60/200,   Variance Loss: -73.9380\n",
      "Epoch 70/200,   Variance Loss: -74.5985\n",
      "Epoch 80/200,   Variance Loss: -76.1872\n",
      "Epoch 90/200,   Variance Loss: -78.4220\n",
      "Epoch 100/200,   Variance Loss: -81.8243\n",
      "Epoch 110/200,   Variance Loss: -84.4936\n",
      "Epoch 120/200,   Variance Loss: -86.0685\n",
      "Epoch 130/200,   Variance Loss: -86.9215\n",
      "Epoch 140/200,   Variance Loss: -87.3653\n",
      "Epoch 150/200,   Variance Loss: -87.5114\n",
      "Epoch 160/200,   Variance Loss: -87.7038\n",
      "Epoch 170/200,   Variance Loss: -87.7131\n",
      "Epoch 180/200,   Variance Loss: -87.6644\n",
      "Epoch 190/200,   Variance Loss: -87.9377\n",
      "Epoch 200/200,   Variance Loss: -88.0087\n",
      "Epoch 10/200,   Variance Loss: 12.4773\n",
      "Epoch 20/200,   Variance Loss: -69.1774\n",
      "Epoch 30/200,   Variance Loss: -70.9499\n",
      "Epoch 40/200,   Variance Loss: -73.2221\n",
      "Epoch 50/200,   Variance Loss: -73.7356\n",
      "Epoch 60/200,   Variance Loss: -74.5916\n",
      "Epoch 70/200,   Variance Loss: -76.2761\n",
      "Epoch 80/200,   Variance Loss: -79.1673\n",
      "Epoch 90/200,   Variance Loss: -80.5141\n",
      "Epoch 100/200,   Variance Loss: -80.8126\n",
      "Epoch 110/200,   Variance Loss: -80.8103\n",
      "Epoch 120/200,   Variance Loss: -80.9086\n",
      "Epoch 130/200,   Variance Loss: -80.8644\n",
      "Epoch 140/200,   Variance Loss: -80.8482\n",
      "Epoch 150/200,   Variance Loss: -80.9509\n",
      "Epoch 160/200,   Variance Loss: -80.9427\n",
      "Epoch 170/200,   Variance Loss: -81.0466\n",
      "Epoch 180/200,   Variance Loss: -80.8790\n",
      "Epoch 190/200,   Variance Loss: -81.0635\n",
      "Epoch 200/200,   Variance Loss: -80.8060\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -48.4032\n",
      "Epoch 20/50,   Variance Loss: -77.7763\n",
      "Epoch 30/50,   Variance Loss: -78.4457\n",
      "Epoch 40/50,   Variance Loss: -78.4467\n",
      "Epoch 50/50,   Variance Loss: -78.4469\n",
      "Epoch 10/200,   Variance Loss: -45.7464\n",
      "Epoch 20/200,   Variance Loss: -68.6845\n",
      "Epoch 30/200,   Variance Loss: -74.1628\n",
      "Epoch 40/200,   Variance Loss: -75.9264\n",
      "Epoch 50/200,   Variance Loss: -77.4878\n",
      "Epoch 60/200,   Variance Loss: -81.6424\n",
      "Epoch 70/200,   Variance Loss: -84.5482\n",
      "Epoch 80/200,   Variance Loss: -86.1831\n",
      "Epoch 90/200,   Variance Loss: -86.9250\n",
      "Epoch 100/200,   Variance Loss: -87.4588\n",
      "Epoch 110/200,   Variance Loss: -87.7614\n",
      "Epoch 120/200,   Variance Loss: -88.0486\n",
      "Epoch 130/200,   Variance Loss: -88.6272\n",
      "Epoch 140/200,   Variance Loss: -88.9416\n",
      "Epoch 150/200,   Variance Loss: -89.2047\n",
      "Epoch 160/200,   Variance Loss: -88.7040\n",
      "Epoch 170/200,   Variance Loss: -89.1598\n",
      "Epoch 180/200,   Variance Loss: -89.3886\n",
      "Epoch 190/200,   Variance Loss: -89.3845\n",
      "Epoch 200/200,   Variance Loss: -89.3382\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 15.3262\n",
      "Epoch 20/200,   Variance Loss: -50.3465\n",
      "Epoch 30/200,   Variance Loss: -65.3071\n",
      "Epoch 40/200,   Variance Loss: -69.6921\n",
      "Epoch 50/200,   Variance Loss: -72.6595\n",
      "Epoch 60/200,   Variance Loss: -73.3725\n",
      "Epoch 70/200,   Variance Loss: -73.8609\n",
      "Epoch 80/200,   Variance Loss: -74.7539\n",
      "Epoch 90/200,   Variance Loss: -77.1513\n",
      "Epoch 100/200,   Variance Loss: -79.6639\n",
      "Epoch 110/200,   Variance Loss: -79.9397\n",
      "Epoch 120/200,   Variance Loss: -80.2371\n",
      "Epoch 130/200,   Variance Loss: -80.1577\n",
      "Epoch 140/200,   Variance Loss: -80.2563\n",
      "Epoch 150/200,   Variance Loss: -80.2876\n",
      "Epoch 160/200,   Variance Loss: -80.3102\n",
      "Epoch 170/200,   Variance Loss: -80.2509\n",
      "Epoch 180/200,   Variance Loss: -80.1750\n",
      "Epoch 190/200,   Variance Loss: -80.3473\n",
      "Epoch 200/200,   Variance Loss: -80.3338\n",
      "Epoch 10/200,   Variance Loss: 13.2694\n",
      "Epoch 20/200,   Variance Loss: -60.3785\n",
      "Epoch 30/200,   Variance Loss: -71.5764\n",
      "Epoch 40/200,   Variance Loss: -73.7985\n",
      "Epoch 50/200,   Variance Loss: -74.8622\n",
      "Epoch 60/200,   Variance Loss: -76.0883\n",
      "Epoch 70/200,   Variance Loss: -78.4464\n",
      "Epoch 80/200,   Variance Loss: -81.4322\n",
      "Epoch 90/200,   Variance Loss: -83.7295\n",
      "Epoch 100/200,   Variance Loss: -85.1928\n",
      "Epoch 110/200,   Variance Loss: -86.3455\n",
      "Epoch 120/200,   Variance Loss: -87.1922\n",
      "Epoch 130/200,   Variance Loss: -87.4790\n",
      "Epoch 140/200,   Variance Loss: -87.9239\n",
      "Epoch 150/200,   Variance Loss: -88.1406\n",
      "Epoch 160/200,   Variance Loss: -88.2422\n",
      "Epoch 170/200,   Variance Loss: -88.3445\n",
      "Epoch 180/200,   Variance Loss: -88.4038\n",
      "Epoch 190/200,   Variance Loss: -88.5983\n",
      "Epoch 200/200,   Variance Loss: -88.5664\n",
      "Epoch 10/200,   Variance Loss: 9.1969\n",
      "Epoch 20/200,   Variance Loss: -66.9059\n",
      "Epoch 30/200,   Variance Loss: -71.4653\n",
      "Epoch 40/200,   Variance Loss: -73.0104\n",
      "Epoch 50/200,   Variance Loss: -73.4512\n",
      "Epoch 60/200,   Variance Loss: -73.6060\n",
      "Epoch 70/200,   Variance Loss: -74.1024\n",
      "Epoch 80/200,   Variance Loss: -74.7549\n",
      "Epoch 90/200,   Variance Loss: -76.1103\n",
      "Epoch 100/200,   Variance Loss: -79.8952\n",
      "Epoch 110/200,   Variance Loss: -83.9570\n",
      "Epoch 120/200,   Variance Loss: -85.3663\n",
      "Epoch 130/200,   Variance Loss: -86.7978\n",
      "Epoch 140/200,   Variance Loss: -87.6590\n",
      "Epoch 150/200,   Variance Loss: -87.8484\n",
      "Epoch 160/200,   Variance Loss: -87.9093\n",
      "Epoch 170/200,   Variance Loss: -88.2437\n",
      "Epoch 180/200,   Variance Loss: -88.3083\n",
      "Epoch 190/200,   Variance Loss: -88.3209\n",
      "Epoch 200/200,   Variance Loss: -88.5815\n",
      "Epoch 10/200,   Variance Loss: 23.1632\n",
      "Epoch 20/200,   Variance Loss: -31.4341\n",
      "Epoch 30/200,   Variance Loss: -67.6691\n",
      "Epoch 40/200,   Variance Loss: -71.8465\n",
      "Epoch 50/200,   Variance Loss: -74.2238\n",
      "Epoch 60/200,   Variance Loss: -75.0973\n",
      "Epoch 70/200,   Variance Loss: -75.8657\n",
      "Epoch 80/200,   Variance Loss: -76.9018\n",
      "Epoch 90/200,   Variance Loss: -77.9396\n",
      "Epoch 100/200,   Variance Loss: -79.5000\n",
      "Epoch 110/200,   Variance Loss: -81.8208\n",
      "Epoch 120/200,   Variance Loss: -84.5222\n",
      "Epoch 130/200,   Variance Loss: -85.8366\n",
      "Epoch 140/200,   Variance Loss: -86.6532\n",
      "Epoch 150/200,   Variance Loss: -87.2710\n",
      "Epoch 160/200,   Variance Loss: -87.2370\n",
      "Epoch 170/200,   Variance Loss: -87.8216\n",
      "Epoch 180/200,   Variance Loss: -88.1342\n",
      "Epoch 190/200,   Variance Loss: -88.2902\n",
      "Epoch 200/200,   Variance Loss: -88.3479\n",
      "Epoch 10/200,   Variance Loss: 5.1227\n",
      "Epoch 20/200,   Variance Loss: -67.2211\n",
      "Epoch 30/200,   Variance Loss: -71.5263\n",
      "Epoch 40/200,   Variance Loss: -73.0006\n",
      "Epoch 50/200,   Variance Loss: -73.3521\n",
      "Epoch 60/200,   Variance Loss: -73.8335\n",
      "Epoch 70/200,   Variance Loss: -74.5486\n",
      "Epoch 80/200,   Variance Loss: -76.2346\n",
      "Epoch 90/200,   Variance Loss: -79.2434\n",
      "Epoch 100/200,   Variance Loss: -83.3521\n",
      "Epoch 110/200,   Variance Loss: -84.1445\n",
      "Epoch 120/200,   Variance Loss: -84.2202\n",
      "Epoch 130/200,   Variance Loss: -84.3476\n",
      "Epoch 140/200,   Variance Loss: -84.3738\n",
      "Epoch 150/200,   Variance Loss: -84.3229\n",
      "Epoch 160/200,   Variance Loss: -84.5880\n",
      "Epoch 170/200,   Variance Loss: -84.5840\n",
      "Epoch 180/200,   Variance Loss: -84.6621\n",
      "Epoch 190/200,   Variance Loss: -84.7763\n",
      "Epoch 200/200,   Variance Loss: -84.7956\n",
      "Epoch 10/200,   Variance Loss: -4.9069\n",
      "Epoch 20/200,   Variance Loss: -67.3207\n",
      "Epoch 30/200,   Variance Loss: -71.2732\n",
      "Epoch 40/200,   Variance Loss: -73.7183\n",
      "Epoch 50/200,   Variance Loss: -76.0107\n",
      "Epoch 60/200,   Variance Loss: -79.3473\n",
      "Epoch 70/200,   Variance Loss: -80.1151\n",
      "Epoch 80/200,   Variance Loss: -80.1627\n",
      "Epoch 90/200,   Variance Loss: -80.2365\n",
      "Epoch 100/200,   Variance Loss: -80.2788\n",
      "Epoch 110/200,   Variance Loss: -80.2579\n",
      "Epoch 120/200,   Variance Loss: -80.1309\n",
      "Epoch 130/200,   Variance Loss: -80.2857\n",
      "Epoch 140/200,   Variance Loss: -80.3693\n",
      "Epoch 150/200,   Variance Loss: -80.2506\n",
      "Epoch 160/200,   Variance Loss: -80.3323\n",
      "Epoch 170/200,   Variance Loss: -80.3984\n",
      "Epoch 180/200,   Variance Loss: -80.3633\n",
      "Epoch 190/200,   Variance Loss: -80.2592\n",
      "Epoch 200/200,   Variance Loss: -80.2699\n",
      "Epoch 10/200,   Variance Loss: 11.2076\n",
      "Epoch 20/200,   Variance Loss: -55.7434\n",
      "Epoch 30/200,   Variance Loss: -67.7493\n",
      "Epoch 40/200,   Variance Loss: -72.2940\n",
      "Epoch 50/200,   Variance Loss: -73.0643\n",
      "Epoch 60/200,   Variance Loss: -73.3552\n",
      "Epoch 70/200,   Variance Loss: -73.5815\n",
      "Epoch 80/200,   Variance Loss: -74.0974\n",
      "Epoch 90/200,   Variance Loss: -75.3820\n",
      "Epoch 100/200,   Variance Loss: -79.4064\n",
      "Epoch 110/200,   Variance Loss: -83.7389\n",
      "Epoch 120/200,   Variance Loss: -85.4966\n",
      "Epoch 130/200,   Variance Loss: -87.0671\n",
      "Epoch 140/200,   Variance Loss: -87.6194\n",
      "Epoch 150/200,   Variance Loss: -87.9083\n",
      "Epoch 160/200,   Variance Loss: -88.1723\n",
      "Epoch 170/200,   Variance Loss: -88.4411\n",
      "Epoch 180/200,   Variance Loss: -88.6438\n",
      "Epoch 190/200,   Variance Loss: -88.4799\n",
      "Epoch 200/200,   Variance Loss: -88.8324\n",
      "Epoch 10/200,   Variance Loss: 13.4759\n",
      "Epoch 20/200,   Variance Loss: -62.8956\n",
      "Epoch 30/200,   Variance Loss: -70.8844\n",
      "Epoch 40/200,   Variance Loss: -72.9234\n",
      "Epoch 50/200,   Variance Loss: -73.8456\n",
      "Epoch 60/200,   Variance Loss: -74.7560\n",
      "Epoch 70/200,   Variance Loss: -76.3769\n",
      "Epoch 80/200,   Variance Loss: -79.2162\n",
      "Epoch 90/200,   Variance Loss: -80.1912\n",
      "Epoch 100/200,   Variance Loss: -80.2797\n",
      "Epoch 110/200,   Variance Loss: -80.2860\n",
      "Epoch 120/200,   Variance Loss: -80.4172\n",
      "Epoch 130/200,   Variance Loss: -80.5082\n",
      "Epoch 140/200,   Variance Loss: -80.4905\n",
      "Epoch 150/200,   Variance Loss: -81.2680\n",
      "Epoch 160/200,   Variance Loss: -82.5520\n",
      "Epoch 170/200,   Variance Loss: -83.4433\n",
      "Epoch 180/200,   Variance Loss: -83.7307\n",
      "Epoch 190/200,   Variance Loss: -83.7897\n",
      "Epoch 200/200,   Variance Loss: -84.2904\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -46.4068\n",
      "Epoch 20/50,   Variance Loss: -69.1435\n",
      "Epoch 30/50,   Variance Loss: -78.1487\n",
      "Epoch 40/50,   Variance Loss: -78.4282\n",
      "Epoch 50/50,   Variance Loss: -78.4351\n",
      "Epoch 10/200,   Variance Loss: -45.1166\n",
      "Epoch 20/200,   Variance Loss: -67.4311\n",
      "Epoch 30/200,   Variance Loss: -74.8043\n",
      "Epoch 40/200,   Variance Loss: -78.0344\n",
      "Epoch 50/200,   Variance Loss: -80.1853\n",
      "Epoch 60/200,   Variance Loss: -83.4137\n",
      "Epoch 70/200,   Variance Loss: -85.1407\n",
      "Epoch 80/200,   Variance Loss: -85.8018\n",
      "Epoch 90/200,   Variance Loss: -85.9855\n",
      "Epoch 100/200,   Variance Loss: -86.3059\n",
      "Epoch 110/200,   Variance Loss: -86.5709\n",
      "Epoch 120/200,   Variance Loss: -86.7500\n",
      "Epoch 130/200,   Variance Loss: -86.9616\n",
      "Epoch 140/200,   Variance Loss: -86.9695\n",
      "Epoch 150/200,   Variance Loss: -87.1974\n",
      "Epoch 160/200,   Variance Loss: -87.4242\n",
      "Epoch 170/200,   Variance Loss: -87.5757\n",
      "Epoch 180/200,   Variance Loss: -87.4124\n",
      "Epoch 190/200,   Variance Loss: -87.6039\n",
      "Epoch 200/200,   Variance Loss: -87.6741\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -46.8359\n",
      "Epoch 20/200,   Variance Loss: -73.2875\n",
      "Epoch 30/200,   Variance Loss: -75.4234\n",
      "Epoch 40/200,   Variance Loss: -77.6106\n",
      "Epoch 50/200,   Variance Loss: -78.7039\n",
      "Epoch 60/200,   Variance Loss: -80.0456\n",
      "Epoch 70/200,   Variance Loss: -81.9029\n",
      "Epoch 80/200,   Variance Loss: -84.9079\n",
      "Epoch 90/200,   Variance Loss: -86.4807\n",
      "Epoch 100/200,   Variance Loss: -86.8316\n",
      "Epoch 110/200,   Variance Loss: -87.0448\n",
      "Epoch 120/200,   Variance Loss: -87.3577\n",
      "Epoch 130/200,   Variance Loss: -87.5361\n",
      "Epoch 140/200,   Variance Loss: -87.5738\n",
      "Epoch 150/200,   Variance Loss: -87.7404\n",
      "Epoch 160/200,   Variance Loss: -87.7721\n",
      "Epoch 170/200,   Variance Loss: -87.8893\n",
      "Epoch 180/200,   Variance Loss: -87.6797\n",
      "Epoch 190/200,   Variance Loss: -88.1229\n",
      "Epoch 200/200,   Variance Loss: -88.2161\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -45.7763\n",
      "Epoch 20/200,   Variance Loss: -71.3794\n",
      "Epoch 30/200,   Variance Loss: -76.1009\n",
      "Epoch 40/200,   Variance Loss: -78.2836\n",
      "Epoch 50/200,   Variance Loss: -79.8204\n",
      "Epoch 60/200,   Variance Loss: -82.1881\n",
      "Epoch 70/200,   Variance Loss: -85.7444\n",
      "Epoch 80/200,   Variance Loss: -86.6920\n",
      "Epoch 90/200,   Variance Loss: -86.8865\n",
      "Epoch 100/200,   Variance Loss: -87.2106\n",
      "Epoch 110/200,   Variance Loss: -87.3781\n",
      "Epoch 120/200,   Variance Loss: -87.6297\n",
      "Epoch 130/200,   Variance Loss: -87.7722\n",
      "Epoch 140/200,   Variance Loss: -87.6737\n",
      "Epoch 150/200,   Variance Loss: -87.9515\n",
      "Epoch 160/200,   Variance Loss: -88.1403\n",
      "Epoch 170/200,   Variance Loss: -88.0945\n",
      "Epoch 180/200,   Variance Loss: -88.4429\n",
      "Epoch 190/200,   Variance Loss: -88.3685\n",
      "Epoch 200/200,   Variance Loss: -88.7561\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -46.0806\n",
      "Epoch 20/200,   Variance Loss: -71.6788\n",
      "Epoch 30/200,   Variance Loss: -75.1952\n",
      "Epoch 40/200,   Variance Loss: -77.0202\n",
      "Epoch 50/200,   Variance Loss: -77.8209\n",
      "Epoch 60/200,   Variance Loss: -79.6915\n",
      "Epoch 70/200,   Variance Loss: -82.2416\n",
      "Epoch 80/200,   Variance Loss: -83.3956\n",
      "Epoch 90/200,   Variance Loss: -86.1504\n",
      "Epoch 100/200,   Variance Loss: -86.9019\n",
      "Epoch 110/200,   Variance Loss: -87.1127\n",
      "Epoch 120/200,   Variance Loss: -87.4200\n",
      "Epoch 130/200,   Variance Loss: -87.6096\n",
      "Epoch 140/200,   Variance Loss: -87.8313\n",
      "Epoch 150/200,   Variance Loss: -87.8959\n",
      "Epoch 160/200,   Variance Loss: -88.0676\n",
      "Epoch 170/200,   Variance Loss: -88.2064\n",
      "Epoch 180/200,   Variance Loss: -88.2826\n",
      "Epoch 190/200,   Variance Loss: -88.5392\n",
      "Epoch 200/200,   Variance Loss: -88.6710\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 11.0305\n",
      "Epoch 20/200,   Variance Loss: -64.6200\n",
      "Epoch 30/200,   Variance Loss: -71.7840\n",
      "Epoch 40/200,   Variance Loss: -74.6799\n",
      "Epoch 50/200,   Variance Loss: -75.5866\n",
      "Epoch 60/200,   Variance Loss: -76.0980\n",
      "Epoch 70/200,   Variance Loss: -76.6970\n",
      "Epoch 80/200,   Variance Loss: -77.3517\n",
      "Epoch 90/200,   Variance Loss: -78.2813\n",
      "Epoch 100/200,   Variance Loss: -79.7064\n",
      "Epoch 110/200,   Variance Loss: -81.8400\n",
      "Epoch 120/200,   Variance Loss: -84.6704\n",
      "Epoch 130/200,   Variance Loss: -86.5635\n",
      "Epoch 140/200,   Variance Loss: -87.0769\n",
      "Epoch 150/200,   Variance Loss: -87.4242\n",
      "Epoch 160/200,   Variance Loss: -87.6172\n",
      "Epoch 170/200,   Variance Loss: -87.9739\n",
      "Epoch 180/200,   Variance Loss: -88.1315\n",
      "Epoch 190/200,   Variance Loss: -88.4298\n",
      "Epoch 200/200,   Variance Loss: -88.6613\n",
      "Epoch 10/200,   Variance Loss: 7.4713\n",
      "Epoch 20/200,   Variance Loss: -69.9967\n",
      "Epoch 30/200,   Variance Loss: -71.8916\n",
      "Epoch 40/200,   Variance Loss: -74.6511\n",
      "Epoch 50/200,   Variance Loss: -75.6497\n",
      "Epoch 60/200,   Variance Loss: -77.6368\n",
      "Epoch 70/200,   Variance Loss: -81.4708\n",
      "Epoch 80/200,   Variance Loss: -85.2785\n",
      "Epoch 90/200,   Variance Loss: -86.0506\n",
      "Epoch 100/200,   Variance Loss: -86.4193\n",
      "Epoch 110/200,   Variance Loss: -86.8925\n",
      "Epoch 120/200,   Variance Loss: -87.2776\n",
      "Epoch 130/200,   Variance Loss: -87.8492\n",
      "Epoch 140/200,   Variance Loss: -88.2177\n",
      "Epoch 150/200,   Variance Loss: -88.5384\n",
      "Epoch 160/200,   Variance Loss: -88.7316\n",
      "Epoch 170/200,   Variance Loss: -89.0689\n",
      "Epoch 180/200,   Variance Loss: -89.2547\n",
      "Epoch 190/200,   Variance Loss: -89.1334\n",
      "Epoch 200/200,   Variance Loss: -89.3986\n",
      "Epoch 10/200,   Variance Loss: -0.4970\n",
      "Epoch 20/200,   Variance Loss: -67.3740\n",
      "Epoch 30/200,   Variance Loss: -71.9686\n",
      "Epoch 40/200,   Variance Loss: -74.5018\n",
      "Epoch 50/200,   Variance Loss: -75.3945\n",
      "Epoch 60/200,   Variance Loss: -76.8547\n",
      "Epoch 70/200,   Variance Loss: -79.3729\n",
      "Epoch 80/200,   Variance Loss: -81.3793\n",
      "Epoch 90/200,   Variance Loss: -81.9086\n",
      "Epoch 100/200,   Variance Loss: -83.9673\n",
      "Epoch 110/200,   Variance Loss: -85.9583\n",
      "Epoch 120/200,   Variance Loss: -86.4371\n",
      "Epoch 130/200,   Variance Loss: -86.6805\n",
      "Epoch 140/200,   Variance Loss: -87.1051\n",
      "Epoch 150/200,   Variance Loss: -87.4381\n",
      "Epoch 160/200,   Variance Loss: -88.1420\n",
      "Epoch 170/200,   Variance Loss: -88.5326\n",
      "Epoch 180/200,   Variance Loss: -88.7326\n",
      "Epoch 190/200,   Variance Loss: -88.8211\n",
      "Epoch 200/200,   Variance Loss: -88.8856\n",
      "Epoch 10/200,   Variance Loss: 7.8598\n",
      "Epoch 20/200,   Variance Loss: -71.0033\n",
      "Epoch 30/200,   Variance Loss: -71.8070\n",
      "Epoch 40/200,   Variance Loss: -75.0158\n",
      "Epoch 50/200,   Variance Loss: -75.8580\n",
      "Epoch 60/200,   Variance Loss: -77.4237\n",
      "Epoch 70/200,   Variance Loss: -81.0660\n",
      "Epoch 80/200,   Variance Loss: -85.1892\n",
      "Epoch 90/200,   Variance Loss: -86.0514\n",
      "Epoch 100/200,   Variance Loss: -86.6340\n",
      "Epoch 110/200,   Variance Loss: -86.9860\n",
      "Epoch 120/200,   Variance Loss: -87.2848\n",
      "Epoch 130/200,   Variance Loss: -87.8469\n",
      "Epoch 140/200,   Variance Loss: -88.0441\n",
      "Epoch 150/200,   Variance Loss: -88.4619\n",
      "Epoch 160/200,   Variance Loss: -88.5808\n",
      "Epoch 170/200,   Variance Loss: -88.7884\n",
      "Epoch 180/200,   Variance Loss: -89.2297\n",
      "Epoch 190/200,   Variance Loss: -89.2384\n",
      "Epoch 200/200,   Variance Loss: -89.5474\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 14.9383\n",
      "Epoch 20/200,   Variance Loss: -55.5514\n",
      "Epoch 30/200,   Variance Loss: -71.8860\n",
      "Epoch 40/200,   Variance Loss: -74.7641\n",
      "Epoch 50/200,   Variance Loss: -76.1147\n",
      "Epoch 60/200,   Variance Loss: -77.0522\n",
      "Epoch 70/200,   Variance Loss: -78.4944\n",
      "Epoch 80/200,   Variance Loss: -81.1670\n",
      "Epoch 90/200,   Variance Loss: -84.6960\n",
      "Epoch 100/200,   Variance Loss: -85.8817\n",
      "Epoch 110/200,   Variance Loss: -86.3724\n",
      "Epoch 120/200,   Variance Loss: -86.6077\n",
      "Epoch 130/200,   Variance Loss: -87.0397\n",
      "Epoch 140/200,   Variance Loss: -87.4645\n",
      "Epoch 150/200,   Variance Loss: -87.7847\n",
      "Epoch 160/200,   Variance Loss: -88.1133\n",
      "Epoch 170/200,   Variance Loss: -88.0577\n",
      "Epoch 180/200,   Variance Loss: -88.5539\n",
      "Epoch 190/200,   Variance Loss: -88.8407\n",
      "Epoch 200/200,   Variance Loss: -88.6311\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -44.2917\n",
      "Epoch 20/50,   Variance Loss: -63.3705\n",
      "Epoch 30/50,   Variance Loss: -76.9553\n",
      "Epoch 40/50,   Variance Loss: -78.3295\n",
      "Epoch 50/50,   Variance Loss: -78.4220\n",
      "Epoch 10/200,   Variance Loss: -45.2220\n",
      "Epoch 20/200,   Variance Loss: -69.1288\n",
      "Epoch 30/200,   Variance Loss: -74.8053\n",
      "Epoch 40/200,   Variance Loss: -76.1866\n",
      "Epoch 50/200,   Variance Loss: -76.6165\n",
      "Epoch 60/200,   Variance Loss: -77.3445\n",
      "Epoch 70/200,   Variance Loss: -79.2067\n",
      "Epoch 80/200,   Variance Loss: -81.3729\n",
      "Epoch 90/200,   Variance Loss: -82.2241\n",
      "Epoch 100/200,   Variance Loss: -82.6213\n",
      "Epoch 110/200,   Variance Loss: -82.7325\n",
      "Epoch 120/200,   Variance Loss: -83.0115\n",
      "Epoch 130/200,   Variance Loss: -83.4122\n",
      "Epoch 140/200,   Variance Loss: -83.4219\n",
      "Epoch 150/200,   Variance Loss: -83.3272\n",
      "Epoch 160/200,   Variance Loss: -83.5783\n",
      "Epoch 170/200,   Variance Loss: -83.6181\n",
      "Epoch 180/200,   Variance Loss: -83.7206\n",
      "Epoch 190/200,   Variance Loss: -83.5520\n",
      "Epoch 200/200,   Variance Loss: -83.7243\n",
      "Epoch 10/200,   Variance Loss: -39.8293\n",
      "Epoch 20/200,   Variance Loss: -58.9803\n",
      "Epoch 30/200,   Variance Loss: -72.2503\n",
      "Epoch 40/200,   Variance Loss: -74.7023\n",
      "Epoch 50/200,   Variance Loss: -75.5402\n",
      "Epoch 60/200,   Variance Loss: -76.5225\n",
      "Epoch 70/200,   Variance Loss: -77.6471\n",
      "Epoch 80/200,   Variance Loss: -78.3815\n",
      "Epoch 90/200,   Variance Loss: -78.6133\n",
      "Epoch 100/200,   Variance Loss: -78.9250\n",
      "Epoch 110/200,   Variance Loss: -79.5357\n",
      "Epoch 120/200,   Variance Loss: -80.1210\n",
      "Epoch 130/200,   Variance Loss: -80.7432\n",
      "Epoch 140/200,   Variance Loss: -80.8078\n",
      "Epoch 150/200,   Variance Loss: -80.6943\n",
      "Epoch 160/200,   Variance Loss: -81.1385\n",
      "Epoch 170/200,   Variance Loss: -81.0580\n",
      "Epoch 180/200,   Variance Loss: -80.9361\n",
      "Epoch 190/200,   Variance Loss: -81.0892\n",
      "Epoch 200/200,   Variance Loss: -81.3178\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -42.1046\n",
      "Epoch 20/200,   Variance Loss: -71.0155\n",
      "Epoch 30/200,   Variance Loss: -73.9066\n",
      "Epoch 40/200,   Variance Loss: -75.4843\n",
      "Epoch 50/200,   Variance Loss: -76.2241\n",
      "Epoch 60/200,   Variance Loss: -77.4711\n",
      "Epoch 70/200,   Variance Loss: -78.5910\n",
      "Epoch 80/200,   Variance Loss: -79.4931\n",
      "Epoch 90/200,   Variance Loss: -80.3297\n",
      "Epoch 100/200,   Variance Loss: -80.7102\n",
      "Epoch 110/200,   Variance Loss: -80.8346\n",
      "Epoch 120/200,   Variance Loss: -80.8368\n",
      "Epoch 130/200,   Variance Loss: -80.7499\n",
      "Epoch 140/200,   Variance Loss: -80.7611\n",
      "Epoch 150/200,   Variance Loss: -80.7976\n",
      "Epoch 160/200,   Variance Loss: -80.7848\n",
      "Epoch 170/200,   Variance Loss: -80.9343\n",
      "Epoch 180/200,   Variance Loss: -80.8890\n",
      "Epoch 190/200,   Variance Loss: -80.8638\n",
      "Epoch 200/200,   Variance Loss: -80.6990\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -40.7617\n",
      "Epoch 20/200,   Variance Loss: -64.6304\n",
      "Epoch 30/200,   Variance Loss: -70.1117\n",
      "Epoch 40/200,   Variance Loss: -74.1156\n",
      "Epoch 50/200,   Variance Loss: -81.3770\n",
      "Epoch 60/200,   Variance Loss: -83.9624\n",
      "Epoch 70/200,   Variance Loss: -84.4277\n",
      "Epoch 80/200,   Variance Loss: -85.5832\n",
      "Epoch 90/200,   Variance Loss: -86.3583\n",
      "Epoch 100/200,   Variance Loss: -86.7130\n",
      "Epoch 110/200,   Variance Loss: -86.8028\n",
      "Epoch 120/200,   Variance Loss: -87.0445\n",
      "Epoch 130/200,   Variance Loss: -87.2041\n",
      "Epoch 140/200,   Variance Loss: -87.0073\n",
      "Epoch 150/200,   Variance Loss: -87.0672\n",
      "Epoch 160/200,   Variance Loss: -87.3484\n",
      "Epoch 170/200,   Variance Loss: -87.5131\n",
      "Epoch 180/200,   Variance Loss: -87.4538\n",
      "Epoch 190/200,   Variance Loss: -87.4420\n",
      "Epoch 200/200,   Variance Loss: -87.4821\n",
      "Epoch 10/200,   Variance Loss: -41.3162\n",
      "Epoch 20/200,   Variance Loss: -64.6523\n",
      "Epoch 30/200,   Variance Loss: -73.6596\n",
      "Epoch 40/200,   Variance Loss: -75.8950\n",
      "Epoch 50/200,   Variance Loss: -77.0247\n",
      "Epoch 60/200,   Variance Loss: -78.7214\n",
      "Epoch 70/200,   Variance Loss: -81.9316\n",
      "Epoch 80/200,   Variance Loss: -84.7299\n",
      "Epoch 90/200,   Variance Loss: -85.5748\n",
      "Epoch 100/200,   Variance Loss: -85.8181\n",
      "Epoch 110/200,   Variance Loss: -86.3171\n",
      "Epoch 120/200,   Variance Loss: -86.7413\n",
      "Epoch 130/200,   Variance Loss: -87.0057\n",
      "Epoch 140/200,   Variance Loss: -87.1566\n",
      "Epoch 150/200,   Variance Loss: -87.3161\n",
      "Epoch 160/200,   Variance Loss: -87.3276\n",
      "Epoch 170/200,   Variance Loss: -87.5105\n",
      "Epoch 180/200,   Variance Loss: -87.6116\n",
      "Epoch 190/200,   Variance Loss: -87.5488\n",
      "Epoch 200/200,   Variance Loss: -87.6175\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -44.0819\n",
      "Epoch 20/200,   Variance Loss: -69.6206\n",
      "Epoch 30/200,   Variance Loss: -73.7003\n",
      "Epoch 40/200,   Variance Loss: -76.1402\n",
      "Epoch 50/200,   Variance Loss: -78.2918\n",
      "Epoch 60/200,   Variance Loss: -80.2346\n",
      "Epoch 70/200,   Variance Loss: -80.6591\n",
      "Epoch 80/200,   Variance Loss: -80.6675\n",
      "Epoch 90/200,   Variance Loss: -81.0183\n",
      "Epoch 100/200,   Variance Loss: -80.9919\n",
      "Epoch 110/200,   Variance Loss: -80.9474\n",
      "Epoch 120/200,   Variance Loss: -81.1546\n",
      "Epoch 130/200,   Variance Loss: -80.7582\n",
      "Epoch 140/200,   Variance Loss: -81.1401\n",
      "Epoch 150/200,   Variance Loss: -81.1805\n",
      "Epoch 160/200,   Variance Loss: -81.2916\n",
      "Epoch 170/200,   Variance Loss: -80.8189\n",
      "Epoch 180/200,   Variance Loss: -81.2606\n",
      "Epoch 190/200,   Variance Loss: -81.4042\n",
      "Epoch 200/200,   Variance Loss: -81.1579\n",
      "Epoch 10/200,   Variance Loss: -44.3633\n",
      "Epoch 20/200,   Variance Loss: -70.9762\n",
      "Epoch 30/200,   Variance Loss: -73.6993\n",
      "Epoch 40/200,   Variance Loss: -75.4470\n",
      "Epoch 50/200,   Variance Loss: -77.0320\n",
      "Epoch 60/200,   Variance Loss: -78.0495\n",
      "Epoch 70/200,   Variance Loss: -78.4738\n",
      "Epoch 80/200,   Variance Loss: -79.0602\n",
      "Epoch 90/200,   Variance Loss: -79.6893\n",
      "Epoch 100/200,   Variance Loss: -78.7430\n",
      "Epoch 110/200,   Variance Loss: -80.7722\n",
      "Epoch 120/200,   Variance Loss: -80.8667\n",
      "Epoch 130/200,   Variance Loss: -80.9924\n",
      "Epoch 140/200,   Variance Loss: -81.1210\n",
      "Epoch 150/200,   Variance Loss: -81.1180\n",
      "Epoch 160/200,   Variance Loss: -81.0744\n",
      "Epoch 170/200,   Variance Loss: -81.0431\n",
      "Epoch 180/200,   Variance Loss: -81.0658\n",
      "Epoch 190/200,   Variance Loss: -81.0664\n",
      "Epoch 200/200,   Variance Loss: -81.2109\n",
      "Epoch 10/200,   Variance Loss: 10.8512\n",
      "Epoch 20/200,   Variance Loss: -65.8551\n",
      "Epoch 30/200,   Variance Loss: -71.7560\n",
      "Epoch 40/200,   Variance Loss: -73.4409\n",
      "Epoch 50/200,   Variance Loss: -74.2537\n",
      "Epoch 60/200,   Variance Loss: -75.6303\n",
      "Epoch 70/200,   Variance Loss: -77.6190\n",
      "Epoch 80/200,   Variance Loss: -79.5121\n",
      "Epoch 90/200,   Variance Loss: -80.6153\n",
      "Epoch 100/200,   Variance Loss: -81.1645\n",
      "Epoch 110/200,   Variance Loss: -81.4256\n",
      "Epoch 120/200,   Variance Loss: -81.6536\n",
      "Epoch 130/200,   Variance Loss: -81.8731\n",
      "Epoch 140/200,   Variance Loss: -82.0498\n",
      "Epoch 150/200,   Variance Loss: -82.2170\n",
      "Epoch 160/200,   Variance Loss: -82.3030\n",
      "Epoch 170/200,   Variance Loss: -82.5860\n",
      "Epoch 180/200,   Variance Loss: -83.2555\n",
      "Epoch 190/200,   Variance Loss: -86.8628\n",
      "Epoch 200/200,   Variance Loss: -87.3166\n",
      "Epoch 10/200,   Variance Loss: 14.5031\n",
      "Epoch 20/200,   Variance Loss: -59.9624\n",
      "Epoch 30/200,   Variance Loss: -70.6634\n",
      "Epoch 40/200,   Variance Loss: -73.1224\n",
      "Epoch 50/200,   Variance Loss: -73.7755\n",
      "Epoch 60/200,   Variance Loss: -74.3708\n",
      "Epoch 70/200,   Variance Loss: -75.1241\n",
      "Epoch 80/200,   Variance Loss: -76.6376\n",
      "Epoch 90/200,   Variance Loss: -78.7816\n",
      "Epoch 100/200,   Variance Loss: -81.5342\n",
      "Epoch 110/200,   Variance Loss: -84.3607\n",
      "Epoch 120/200,   Variance Loss: -85.7315\n",
      "Epoch 130/200,   Variance Loss: -86.5538\n",
      "Epoch 140/200,   Variance Loss: -87.0513\n",
      "Epoch 150/200,   Variance Loss: -87.4760\n",
      "Epoch 160/200,   Variance Loss: -87.8967\n",
      "Epoch 170/200,   Variance Loss: -88.1803\n",
      "Epoch 180/200,   Variance Loss: -88.8628\n",
      "Epoch 190/200,   Variance Loss: -89.0667\n",
      "Epoch 200/200,   Variance Loss: -89.3777\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -47.0342\n",
      "Epoch 20/50,   Variance Loss: -73.7846\n",
      "Epoch 30/50,   Variance Loss: -77.9037\n",
      "Epoch 40/50,   Variance Loss: -78.1273\n",
      "Epoch 50/50,   Variance Loss: -78.2755\n",
      "Epoch 10/200,   Variance Loss: -42.5650\n",
      "Epoch 20/200,   Variance Loss: -68.7507\n",
      "Epoch 30/200,   Variance Loss: -74.5118\n",
      "Epoch 40/200,   Variance Loss: -75.7923\n",
      "Epoch 50/200,   Variance Loss: -76.1242\n",
      "Epoch 60/200,   Variance Loss: -77.0282\n",
      "Epoch 70/200,   Variance Loss: -78.7677\n",
      "Epoch 80/200,   Variance Loss: -81.0446\n",
      "Epoch 90/200,   Variance Loss: -84.1006\n",
      "Epoch 100/200,   Variance Loss: -85.4086\n",
      "Epoch 110/200,   Variance Loss: -85.6202\n",
      "Epoch 120/200,   Variance Loss: -85.6222\n",
      "Epoch 130/200,   Variance Loss: -85.6250\n",
      "Epoch 140/200,   Variance Loss: -85.7097\n",
      "Epoch 150/200,   Variance Loss: -85.8546\n",
      "Epoch 160/200,   Variance Loss: -86.0023\n",
      "Epoch 170/200,   Variance Loss: -86.0492\n",
      "Epoch 180/200,   Variance Loss: -85.8545\n",
      "Epoch 190/200,   Variance Loss: -86.2652\n",
      "Epoch 200/200,   Variance Loss: -86.3322\n",
      "Epoch 10/200,   Variance Loss: 18.6731\n",
      "Epoch 20/200,   Variance Loss: -61.9586\n",
      "Epoch 30/200,   Variance Loss: -70.9703\n",
      "Epoch 40/200,   Variance Loss: -73.5713\n",
      "Epoch 50/200,   Variance Loss: -73.9800\n",
      "Epoch 60/200,   Variance Loss: -74.5175\n",
      "Epoch 70/200,   Variance Loss: -75.1128\n",
      "Epoch 80/200,   Variance Loss: -76.3336\n",
      "Epoch 90/200,   Variance Loss: -78.9184\n",
      "Epoch 100/200,   Variance Loss: -80.5905\n",
      "Epoch 110/200,   Variance Loss: -81.3413\n",
      "Epoch 120/200,   Variance Loss: -81.4427\n",
      "Epoch 130/200,   Variance Loss: -81.4389\n",
      "Epoch 140/200,   Variance Loss: -81.4758\n",
      "Epoch 150/200,   Variance Loss: -81.2827\n",
      "Epoch 160/200,   Variance Loss: -81.3736\n",
      "Epoch 170/200,   Variance Loss: -81.5294\n",
      "Epoch 180/200,   Variance Loss: -81.4635\n",
      "Epoch 190/200,   Variance Loss: -81.6231\n",
      "Epoch 200/200,   Variance Loss: -81.6465\n",
      "Epoch 10/200,   Variance Loss: 6.8529\n",
      "Epoch 20/200,   Variance Loss: -70.4839\n",
      "Epoch 30/200,   Variance Loss: -71.6511\n",
      "Epoch 40/200,   Variance Loss: -73.4211\n",
      "Epoch 50/200,   Variance Loss: -74.0259\n",
      "Epoch 60/200,   Variance Loss: -75.6010\n",
      "Epoch 70/200,   Variance Loss: -78.6805\n",
      "Epoch 80/200,   Variance Loss: -80.7948\n",
      "Epoch 90/200,   Variance Loss: -81.2342\n",
      "Epoch 100/200,   Variance Loss: -81.4474\n",
      "Epoch 110/200,   Variance Loss: -81.6014\n",
      "Epoch 120/200,   Variance Loss: -81.5309\n",
      "Epoch 130/200,   Variance Loss: -81.5323\n",
      "Epoch 140/200,   Variance Loss: -81.4394\n",
      "Epoch 150/200,   Variance Loss: -81.4615\n",
      "Epoch 160/200,   Variance Loss: -81.6347\n",
      "Epoch 170/200,   Variance Loss: -81.2891\n",
      "Epoch 180/200,   Variance Loss: -81.3669\n",
      "Epoch 190/200,   Variance Loss: -81.3751\n",
      "Epoch 200/200,   Variance Loss: -81.7856\n",
      "Epoch 10/200,   Variance Loss: 13.4713\n",
      "Epoch 20/200,   Variance Loss: -66.8344\n",
      "Epoch 30/200,   Variance Loss: -67.3801\n",
      "Epoch 40/200,   Variance Loss: -70.6106\n",
      "Epoch 50/200,   Variance Loss: -73.7146\n",
      "Epoch 60/200,   Variance Loss: -75.5375\n",
      "Epoch 70/200,   Variance Loss: -79.1881\n",
      "Epoch 80/200,   Variance Loss: -81.1757\n",
      "Epoch 90/200,   Variance Loss: -81.4049\n",
      "Epoch 100/200,   Variance Loss: -81.4416\n",
      "Epoch 110/200,   Variance Loss: -81.4813\n",
      "Epoch 120/200,   Variance Loss: -81.5839\n",
      "Epoch 130/200,   Variance Loss: -81.5005\n",
      "Epoch 140/200,   Variance Loss: -81.3529\n",
      "Epoch 150/200,   Variance Loss: -81.5096\n",
      "Epoch 160/200,   Variance Loss: -81.5562\n",
      "Epoch 170/200,   Variance Loss: -81.5891\n",
      "Epoch 180/200,   Variance Loss: -81.6139\n",
      "Epoch 190/200,   Variance Loss: -81.6731\n",
      "Epoch 200/200,   Variance Loss: -81.4080\n",
      "Epoch 10/200,   Variance Loss: 17.6088\n",
      "Epoch 20/200,   Variance Loss: -52.9380\n",
      "Epoch 30/200,   Variance Loss: -71.0539\n",
      "Epoch 40/200,   Variance Loss: -72.8059\n",
      "Epoch 50/200,   Variance Loss: -73.4196\n",
      "Epoch 60/200,   Variance Loss: -73.9066\n",
      "Epoch 70/200,   Variance Loss: -74.8672\n",
      "Epoch 80/200,   Variance Loss: -77.5364\n",
      "Epoch 90/200,   Variance Loss: -81.8050\n",
      "Epoch 100/200,   Variance Loss: -83.9125\n",
      "Epoch 110/200,   Variance Loss: -84.5753\n",
      "Epoch 120/200,   Variance Loss: -85.5235\n",
      "Epoch 130/200,   Variance Loss: -86.2179\n",
      "Epoch 140/200,   Variance Loss: -86.6528\n",
      "Epoch 150/200,   Variance Loss: -86.7612\n",
      "Epoch 160/200,   Variance Loss: -86.7004\n",
      "Epoch 170/200,   Variance Loss: -86.8762\n",
      "Epoch 180/200,   Variance Loss: -86.8185\n",
      "Epoch 190/200,   Variance Loss: -86.8537\n",
      "Epoch 200/200,   Variance Loss: -86.9259\n",
      "Epoch 10/200,   Variance Loss: 16.7085\n",
      "Epoch 20/200,   Variance Loss: -69.4014\n",
      "Epoch 30/200,   Variance Loss: -71.2189\n",
      "Epoch 40/200,   Variance Loss: -72.9912\n",
      "Epoch 50/200,   Variance Loss: -73.6080\n",
      "Epoch 60/200,   Variance Loss: -74.3149\n",
      "Epoch 70/200,   Variance Loss: -76.5460\n",
      "Epoch 80/200,   Variance Loss: -79.9432\n",
      "Epoch 90/200,   Variance Loss: -81.3701\n",
      "Epoch 100/200,   Variance Loss: -81.4203\n",
      "Epoch 110/200,   Variance Loss: -81.6863\n",
      "Epoch 120/200,   Variance Loss: -81.4338\n",
      "Epoch 130/200,   Variance Loss: -81.6217\n",
      "Epoch 140/200,   Variance Loss: -81.3912\n",
      "Epoch 150/200,   Variance Loss: -81.5585\n",
      "Epoch 160/200,   Variance Loss: -81.4015\n",
      "Epoch 170/200,   Variance Loss: -81.6965\n",
      "Epoch 180/200,   Variance Loss: -81.4814\n",
      "Epoch 190/200,   Variance Loss: -81.8619\n",
      "Epoch 200/200,   Variance Loss: -81.8972\n",
      "Epoch 10/200,   Variance Loss: 12.3793\n",
      "Epoch 20/200,   Variance Loss: -65.6183\n",
      "Epoch 30/200,   Variance Loss: -70.5574\n",
      "Epoch 40/200,   Variance Loss: -72.7515\n",
      "Epoch 50/200,   Variance Loss: -73.2606\n",
      "Epoch 60/200,   Variance Loss: -73.5268\n",
      "Epoch 70/200,   Variance Loss: -73.8118\n",
      "Epoch 80/200,   Variance Loss: -74.5011\n",
      "Epoch 90/200,   Variance Loss: -76.3535\n",
      "Epoch 100/200,   Variance Loss: -79.9734\n",
      "Epoch 110/200,   Variance Loss: -81.2770\n",
      "Epoch 120/200,   Variance Loss: -81.4271\n",
      "Epoch 130/200,   Variance Loss: -81.4899\n",
      "Epoch 140/200,   Variance Loss: -81.4669\n",
      "Epoch 150/200,   Variance Loss: -81.3580\n",
      "Epoch 160/200,   Variance Loss: -81.5133\n",
      "Epoch 170/200,   Variance Loss: -81.5543\n",
      "Epoch 180/200,   Variance Loss: -81.3963\n",
      "Epoch 190/200,   Variance Loss: -81.5811\n",
      "Epoch 200/200,   Variance Loss: -81.5555\n",
      "Epoch 10/200,   Variance Loss: 23.5973\n",
      "Epoch 20/200,   Variance Loss: -49.1484\n",
      "Epoch 30/200,   Variance Loss: -70.3930\n",
      "Epoch 40/200,   Variance Loss: -72.3039\n",
      "Epoch 50/200,   Variance Loss: -73.6053\n",
      "Epoch 60/200,   Variance Loss: -74.3526\n",
      "Epoch 70/200,   Variance Loss: -75.9320\n",
      "Epoch 80/200,   Variance Loss: -79.0169\n",
      "Epoch 90/200,   Variance Loss: -83.0031\n",
      "Epoch 100/200,   Variance Loss: -84.9329\n",
      "Epoch 110/200,   Variance Loss: -85.9946\n",
      "Epoch 120/200,   Variance Loss: -86.4254\n",
      "Epoch 130/200,   Variance Loss: -86.6561\n",
      "Epoch 140/200,   Variance Loss: -86.8811\n",
      "Epoch 150/200,   Variance Loss: -87.0193\n",
      "Epoch 160/200,   Variance Loss: -87.1124\n",
      "Epoch 170/200,   Variance Loss: -87.2590\n",
      "Epoch 180/200,   Variance Loss: -87.2422\n",
      "Epoch 190/200,   Variance Loss: -87.1865\n",
      "Epoch 200/200,   Variance Loss: -87.3866\n",
      "Epoch 10/200,   Variance Loss: 13.4228\n",
      "Epoch 20/200,   Variance Loss: -67.8151\n",
      "Epoch 30/200,   Variance Loss: -70.7477\n",
      "Epoch 40/200,   Variance Loss: -73.0190\n",
      "Epoch 50/200,   Variance Loss: -73.6181\n",
      "Epoch 60/200,   Variance Loss: -74.0810\n",
      "Epoch 70/200,   Variance Loss: -75.1697\n",
      "Epoch 80/200,   Variance Loss: -77.5814\n",
      "Epoch 90/200,   Variance Loss: -80.4756\n",
      "Epoch 100/200,   Variance Loss: -81.2664\n",
      "Epoch 110/200,   Variance Loss: -80.8658\n",
      "Epoch 120/200,   Variance Loss: -81.3322\n",
      "Epoch 130/200,   Variance Loss: -81.3789\n",
      "Epoch 140/200,   Variance Loss: -81.4697\n",
      "Epoch 150/200,   Variance Loss: -81.4079\n",
      "Epoch 160/200,   Variance Loss: -81.4764\n",
      "Epoch 170/200,   Variance Loss: -81.4852\n",
      "Epoch 180/200,   Variance Loss: -81.6542\n",
      "Epoch 190/200,   Variance Loss: -81.6798\n",
      "Epoch 200/200,   Variance Loss: -81.6522\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -49.0590\n",
      "Epoch 20/50,   Variance Loss: -75.4030\n",
      "Epoch 30/50,   Variance Loss: -78.4179\n",
      "Epoch 40/50,   Variance Loss: -78.4270\n",
      "Epoch 50/50,   Variance Loss: -78.4274\n",
      "Epoch 10/200,   Variance Loss: -44.0094\n",
      "Epoch 20/200,   Variance Loss: -67.2979\n",
      "Epoch 30/200,   Variance Loss: -74.4894\n",
      "Epoch 40/200,   Variance Loss: -77.1551\n",
      "Epoch 50/200,   Variance Loss: -79.1616\n",
      "Epoch 60/200,   Variance Loss: -82.7645\n",
      "Epoch 70/200,   Variance Loss: -85.6578\n",
      "Epoch 80/200,   Variance Loss: -86.2399\n",
      "Epoch 90/200,   Variance Loss: -86.8081\n",
      "Epoch 100/200,   Variance Loss: -87.1759\n",
      "Epoch 110/200,   Variance Loss: -87.5226\n",
      "Epoch 120/200,   Variance Loss: -87.6793\n",
      "Epoch 130/200,   Variance Loss: -87.9129\n",
      "Epoch 140/200,   Variance Loss: -88.0799\n",
      "Epoch 150/200,   Variance Loss: -88.0998\n",
      "Epoch 160/200,   Variance Loss: -88.1923\n",
      "Epoch 170/200,   Variance Loss: -88.2819\n",
      "Epoch 180/200,   Variance Loss: -87.9724\n",
      "Epoch 190/200,   Variance Loss: -88.2084\n",
      "Epoch 200/200,   Variance Loss: -88.3640\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 11.4888\n",
      "Epoch 20/200,   Variance Loss: -65.0493\n",
      "Epoch 30/200,   Variance Loss: -71.7055\n",
      "Epoch 40/200,   Variance Loss: -73.3176\n",
      "Epoch 50/200,   Variance Loss: -73.8937\n",
      "Epoch 60/200,   Variance Loss: -74.2416\n",
      "Epoch 70/200,   Variance Loss: -74.9946\n",
      "Epoch 80/200,   Variance Loss: -76.6809\n",
      "Epoch 90/200,   Variance Loss: -79.8877\n",
      "Epoch 100/200,   Variance Loss: -83.8068\n",
      "Epoch 110/200,   Variance Loss: -85.2465\n",
      "Epoch 120/200,   Variance Loss: -86.5413\n",
      "Epoch 130/200,   Variance Loss: -87.7088\n",
      "Epoch 140/200,   Variance Loss: -88.2744\n",
      "Epoch 150/200,   Variance Loss: -88.6595\n",
      "Epoch 160/200,   Variance Loss: -88.8546\n",
      "Epoch 170/200,   Variance Loss: -89.1070\n",
      "Epoch 180/200,   Variance Loss: -89.1987\n",
      "Epoch 190/200,   Variance Loss: -89.3336\n",
      "Epoch 200/200,   Variance Loss: -89.4679\n",
      "Epoch 10/200,   Variance Loss: 22.6081\n",
      "Epoch 20/200,   Variance Loss: -50.3937\n",
      "Epoch 30/200,   Variance Loss: -71.0026\n",
      "Epoch 40/200,   Variance Loss: -74.0060\n",
      "Epoch 50/200,   Variance Loss: -74.8685\n",
      "Epoch 60/200,   Variance Loss: -75.4399\n",
      "Epoch 70/200,   Variance Loss: -76.1804\n",
      "Epoch 80/200,   Variance Loss: -77.1579\n",
      "Epoch 90/200,   Variance Loss: -78.5013\n",
      "Epoch 100/200,   Variance Loss: -81.0841\n",
      "Epoch 110/200,   Variance Loss: -84.2292\n",
      "Epoch 120/200,   Variance Loss: -85.9020\n",
      "Epoch 130/200,   Variance Loss: -87.5734\n",
      "Epoch 140/200,   Variance Loss: -88.2774\n",
      "Epoch 150/200,   Variance Loss: -88.7028\n",
      "Epoch 160/200,   Variance Loss: -89.0079\n",
      "Epoch 170/200,   Variance Loss: -88.9765\n",
      "Epoch 180/200,   Variance Loss: -89.4590\n",
      "Epoch 190/200,   Variance Loss: -89.6129\n",
      "Epoch 200/200,   Variance Loss: -89.5275\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 23.0660\n",
      "Epoch 20/200,   Variance Loss: -45.0203\n",
      "Epoch 30/200,   Variance Loss: -72.5844\n",
      "Epoch 40/200,   Variance Loss: -74.3548\n",
      "Epoch 50/200,   Variance Loss: -75.7467\n",
      "Epoch 60/200,   Variance Loss: -77.0545\n",
      "Epoch 70/200,   Variance Loss: -79.0509\n",
      "Epoch 80/200,   Variance Loss: -82.2794\n",
      "Epoch 90/200,   Variance Loss: -84.1911\n",
      "Epoch 100/200,   Variance Loss: -84.5890\n",
      "Epoch 110/200,   Variance Loss: -84.8727\n",
      "Epoch 120/200,   Variance Loss: -84.9763\n",
      "Epoch 130/200,   Variance Loss: -85.0382\n",
      "Epoch 140/200,   Variance Loss: -85.0462\n",
      "Epoch 150/200,   Variance Loss: -85.1802\n",
      "Epoch 160/200,   Variance Loss: -85.1848\n",
      "Epoch 170/200,   Variance Loss: -85.2499\n",
      "Epoch 180/200,   Variance Loss: -85.2913\n",
      "Epoch 190/200,   Variance Loss: -85.4088\n",
      "Epoch 200/200,   Variance Loss: -85.4308\n",
      "Epoch 10/200,   Variance Loss: 12.5968\n",
      "Epoch 20/200,   Variance Loss: -66.3111\n",
      "Epoch 30/200,   Variance Loss: -72.0181\n",
      "Epoch 40/200,   Variance Loss: -73.8692\n",
      "Epoch 50/200,   Variance Loss: -74.5553\n",
      "Epoch 60/200,   Variance Loss: -75.2155\n",
      "Epoch 70/200,   Variance Loss: -76.3403\n",
      "Epoch 80/200,   Variance Loss: -77.9784\n",
      "Epoch 90/200,   Variance Loss: -80.9893\n",
      "Epoch 100/200,   Variance Loss: -83.8637\n",
      "Epoch 110/200,   Variance Loss: -84.6340\n",
      "Epoch 120/200,   Variance Loss: -84.9044\n",
      "Epoch 130/200,   Variance Loss: -85.1175\n",
      "Epoch 140/200,   Variance Loss: -85.6242\n",
      "Epoch 150/200,   Variance Loss: -86.8792\n",
      "Epoch 160/200,   Variance Loss: -88.0874\n",
      "Epoch 170/200,   Variance Loss: -88.6465\n",
      "Epoch 180/200,   Variance Loss: -88.8178\n",
      "Epoch 190/200,   Variance Loss: -89.0774\n",
      "Epoch 200/200,   Variance Loss: -89.1860\n",
      "Epoch 10/200,   Variance Loss: 12.4295\n",
      "Epoch 20/200,   Variance Loss: -64.4189\n",
      "Epoch 30/200,   Variance Loss: -71.6279\n",
      "Epoch 40/200,   Variance Loss: -73.5622\n",
      "Epoch 50/200,   Variance Loss: -74.6387\n",
      "Epoch 60/200,   Variance Loss: -75.7326\n",
      "Epoch 70/200,   Variance Loss: -77.7457\n",
      "Epoch 80/200,   Variance Loss: -79.6939\n",
      "Epoch 90/200,   Variance Loss: -82.6937\n",
      "Epoch 100/200,   Variance Loss: -84.3381\n",
      "Epoch 110/200,   Variance Loss: -84.7919\n",
      "Epoch 120/200,   Variance Loss: -85.0603\n",
      "Epoch 130/200,   Variance Loss: -85.1748\n",
      "Epoch 140/200,   Variance Loss: -85.3105\n",
      "Epoch 150/200,   Variance Loss: -85.9120\n",
      "Epoch 160/200,   Variance Loss: -87.4697\n",
      "Epoch 170/200,   Variance Loss: -88.2793\n",
      "Epoch 180/200,   Variance Loss: -88.7648\n",
      "Epoch 190/200,   Variance Loss: -88.9797\n",
      "Epoch 200/200,   Variance Loss: -89.0106\n",
      "Epoch 10/200,   Variance Loss: 7.7645\n",
      "Epoch 20/200,   Variance Loss: -64.3921\n",
      "Epoch 30/200,   Variance Loss: -71.6614\n",
      "Epoch 40/200,   Variance Loss: -73.5442\n",
      "Epoch 50/200,   Variance Loss: -74.0669\n",
      "Epoch 60/200,   Variance Loss: -74.6357\n",
      "Epoch 70/200,   Variance Loss: -75.3701\n",
      "Epoch 80/200,   Variance Loss: -77.1247\n",
      "Epoch 90/200,   Variance Loss: -80.9742\n",
      "Epoch 100/200,   Variance Loss: -84.4888\n",
      "Epoch 110/200,   Variance Loss: -86.0246\n",
      "Epoch 120/200,   Variance Loss: -87.4879\n",
      "Epoch 130/200,   Variance Loss: -88.2246\n",
      "Epoch 140/200,   Variance Loss: -88.6251\n",
      "Epoch 150/200,   Variance Loss: -88.9048\n",
      "Epoch 160/200,   Variance Loss: -89.0140\n",
      "Epoch 170/200,   Variance Loss: -89.1207\n",
      "Epoch 180/200,   Variance Loss: -89.2210\n",
      "Epoch 190/200,   Variance Loss: -89.5793\n",
      "Epoch 200/200,   Variance Loss: -89.6352\n",
      "Epoch 10/200,   Variance Loss: 11.6001\n",
      "Epoch 20/200,   Variance Loss: -67.4931\n",
      "Epoch 30/200,   Variance Loss: -71.5508\n",
      "Epoch 40/200,   Variance Loss: -73.7719\n",
      "Epoch 50/200,   Variance Loss: -74.4592\n",
      "Epoch 60/200,   Variance Loss: -75.0741\n",
      "Epoch 70/200,   Variance Loss: -76.1315\n",
      "Epoch 80/200,   Variance Loss: -78.6928\n",
      "Epoch 90/200,   Variance Loss: -83.1742\n",
      "Epoch 100/200,   Variance Loss: -85.1280\n",
      "Epoch 110/200,   Variance Loss: -86.2300\n",
      "Epoch 120/200,   Variance Loss: -87.6246\n",
      "Epoch 130/200,   Variance Loss: -88.2571\n",
      "Epoch 140/200,   Variance Loss: -88.6586\n",
      "Epoch 150/200,   Variance Loss: -88.9032\n",
      "Epoch 160/200,   Variance Loss: -89.1119\n",
      "Epoch 170/200,   Variance Loss: -89.3675\n",
      "Epoch 180/200,   Variance Loss: -89.3881\n",
      "Epoch 190/200,   Variance Loss: -89.5404\n",
      "Epoch 200/200,   Variance Loss: -89.6999\n",
      "Epoch 10/200,   Variance Loss: 4.2778\n",
      "Epoch 20/200,   Variance Loss: -64.6501\n",
      "Epoch 30/200,   Variance Loss: -67.7796\n",
      "Epoch 40/200,   Variance Loss: -71.3083\n",
      "Epoch 50/200,   Variance Loss: -73.1977\n",
      "Epoch 60/200,   Variance Loss: -74.1145\n",
      "Epoch 70/200,   Variance Loss: -74.8900\n",
      "Epoch 80/200,   Variance Loss: -76.0406\n",
      "Epoch 90/200,   Variance Loss: -77.4458\n",
      "Epoch 100/200,   Variance Loss: -79.4083\n",
      "Epoch 110/200,   Variance Loss: -80.2861\n",
      "Epoch 120/200,   Variance Loss: -80.2371\n",
      "Epoch 130/200,   Variance Loss: -80.3257\n",
      "Epoch 140/200,   Variance Loss: -80.2837\n",
      "Epoch 150/200,   Variance Loss: -80.4453\n",
      "Epoch 160/200,   Variance Loss: -80.4549\n",
      "Epoch 170/200,   Variance Loss: -80.1012\n",
      "Epoch 180/200,   Variance Loss: -80.3734\n",
      "Epoch 190/200,   Variance Loss: -80.4112\n",
      "Epoch 200/200,   Variance Loss: -80.1471\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n",
      "Epoch 10/50,   Variance Loss: -46.2085\n",
      "Epoch 20/50,   Variance Loss: -76.2153\n",
      "Epoch 30/50,   Variance Loss: -78.4105\n",
      "Epoch 40/50,   Variance Loss: -78.4216\n",
      "Epoch 50/50,   Variance Loss: -78.4224\n",
      "Epoch 10/200,   Variance Loss: -44.5639\n",
      "Epoch 20/200,   Variance Loss: -66.5824\n",
      "Epoch 30/200,   Variance Loss: -74.4465\n",
      "Epoch 40/200,   Variance Loss: -75.8533\n",
      "Epoch 50/200,   Variance Loss: -76.2522\n",
      "Epoch 60/200,   Variance Loss: -76.6267\n",
      "Epoch 70/200,   Variance Loss: -77.7408\n",
      "Epoch 80/200,   Variance Loss: -80.3141\n",
      "Epoch 90/200,   Variance Loss: -81.4066\n",
      "Epoch 100/200,   Variance Loss: -82.3210\n",
      "Epoch 110/200,   Variance Loss: -84.1004\n",
      "Epoch 120/200,   Variance Loss: -85.4574\n",
      "Epoch 130/200,   Variance Loss: -86.4095\n",
      "Epoch 140/200,   Variance Loss: -86.6540\n",
      "Epoch 150/200,   Variance Loss: -86.7164\n",
      "Epoch 160/200,   Variance Loss: -87.0021\n",
      "Epoch 170/200,   Variance Loss: -86.9907\n",
      "Epoch 180/200,   Variance Loss: -87.3654\n",
      "Epoch 190/200,   Variance Loss: -87.7508\n",
      "Epoch 200/200,   Variance Loss: -87.8718\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -42.3655\n",
      "Epoch 20/200,   Variance Loss: -65.4035\n",
      "Epoch 30/200,   Variance Loss: -73.7072\n",
      "Epoch 40/200,   Variance Loss: -76.2533\n",
      "Epoch 50/200,   Variance Loss: -77.2303\n",
      "Epoch 60/200,   Variance Loss: -78.3247\n",
      "Epoch 70/200,   Variance Loss: -80.5503\n",
      "Epoch 80/200,   Variance Loss: -84.1264\n",
      "Epoch 90/200,   Variance Loss: -86.4121\n",
      "Epoch 100/200,   Variance Loss: -86.7757\n",
      "Epoch 110/200,   Variance Loss: -87.3492\n",
      "Epoch 120/200,   Variance Loss: -87.3155\n",
      "Epoch 130/200,   Variance Loss: -87.8804\n",
      "Epoch 140/200,   Variance Loss: -88.0530\n",
      "Epoch 150/200,   Variance Loss: -88.1307\n",
      "Epoch 160/200,   Variance Loss: -88.5778\n",
      "Epoch 170/200,   Variance Loss: -88.7083\n",
      "Epoch 180/200,   Variance Loss: -88.7623\n",
      "Epoch 190/200,   Variance Loss: -88.8559\n",
      "Epoch 200/200,   Variance Loss: -89.0421\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -44.0617\n",
      "Epoch 20/200,   Variance Loss: -69.7272\n",
      "Epoch 30/200,   Variance Loss: -74.3314\n",
      "Epoch 40/200,   Variance Loss: -76.7500\n",
      "Epoch 50/200,   Variance Loss: -77.5513\n",
      "Epoch 60/200,   Variance Loss: -78.5216\n",
      "Epoch 70/200,   Variance Loss: -79.8005\n",
      "Epoch 80/200,   Variance Loss: -81.7632\n",
      "Epoch 90/200,   Variance Loss: -85.6455\n",
      "Epoch 100/200,   Variance Loss: -87.0989\n",
      "Epoch 110/200,   Variance Loss: -87.4126\n",
      "Epoch 120/200,   Variance Loss: -87.6051\n",
      "Epoch 130/200,   Variance Loss: -87.7952\n",
      "Epoch 140/200,   Variance Loss: -87.8175\n",
      "Epoch 150/200,   Variance Loss: -87.9079\n",
      "Epoch 160/200,   Variance Loss: -87.9228\n",
      "Epoch 170/200,   Variance Loss: -88.1054\n",
      "Epoch 180/200,   Variance Loss: -88.6134\n",
      "Epoch 190/200,   Variance Loss: -88.7365\n",
      "Epoch 200/200,   Variance Loss: -89.1618\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: -43.9064\n",
      "Epoch 20/200,   Variance Loss: -69.6474\n",
      "Epoch 30/200,   Variance Loss: -75.7816\n",
      "Epoch 40/200,   Variance Loss: -76.8529\n",
      "Epoch 50/200,   Variance Loss: -77.1658\n",
      "Epoch 60/200,   Variance Loss: -77.5374\n",
      "Epoch 70/200,   Variance Loss: -78.4615\n",
      "Epoch 80/200,   Variance Loss: -78.9196\n",
      "Epoch 90/200,   Variance Loss: -79.6207\n",
      "Epoch 100/200,   Variance Loss: -80.2960\n",
      "Epoch 110/200,   Variance Loss: -80.9235\n",
      "Epoch 120/200,   Variance Loss: -81.4309\n",
      "Epoch 130/200,   Variance Loss: -81.5858\n",
      "Epoch 140/200,   Variance Loss: -81.4709\n",
      "Epoch 150/200,   Variance Loss: -81.6604\n",
      "Epoch 160/200,   Variance Loss: -81.4492\n",
      "Epoch 170/200,   Variance Loss: -81.6539\n",
      "Epoch 180/200,   Variance Loss: -81.6165\n",
      "Epoch 190/200,   Variance Loss: -81.6888\n",
      "Epoch 200/200,   Variance Loss: -81.8150\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Document\\Serieux\\Travail\\python_work\\cEBNM_torch\\py\\cash_solver.py:159: RuntimeWarning: divide by zero encountered in log\n",
      "  log_pi=np.log(all_pi_values_np[i, :]),\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 10/200,   Variance Loss: 14.5402\n",
      "Epoch 20/200,   Variance Loss: -64.1910\n",
      "Epoch 30/200,   Variance Loss: -67.9062\n",
      "Epoch 40/200,   Variance Loss: -72.5242\n",
      "Epoch 50/200,   Variance Loss: -74.4165\n",
      "Epoch 60/200,   Variance Loss: -75.2468\n",
      "Epoch 70/200,   Variance Loss: -76.6535\n",
      "Epoch 80/200,   Variance Loss: -79.8324\n",
      "Epoch 90/200,   Variance Loss: -84.0312\n",
      "Epoch 100/200,   Variance Loss: -85.4312\n",
      "Epoch 110/200,   Variance Loss: -86.6352\n",
      "Epoch 120/200,   Variance Loss: -87.8233\n",
      "Epoch 130/200,   Variance Loss: -88.4430\n",
      "Epoch 140/200,   Variance Loss: -88.8216\n",
      "Epoch 150/200,   Variance Loss: -89.0046\n",
      "Epoch 160/200,   Variance Loss: -89.1581\n",
      "Epoch 170/200,   Variance Loss: -89.5022\n",
      "Epoch 180/200,   Variance Loss: -89.6560\n",
      "Epoch 190/200,   Variance Loss: -89.7625\n",
      "Epoch 200/200,   Variance Loss: -89.8794\n",
      "Epoch 10/200,   Variance Loss: 0.3965\n",
      "Epoch 20/200,   Variance Loss: -64.5121\n",
      "Epoch 30/200,   Variance Loss: -71.8214\n",
      "Epoch 40/200,   Variance Loss: -74.2772\n",
      "Epoch 50/200,   Variance Loss: -74.8442\n",
      "Epoch 60/200,   Variance Loss: -75.4844\n",
      "Epoch 70/200,   Variance Loss: -76.4488\n",
      "Epoch 80/200,   Variance Loss: -78.6660\n",
      "Epoch 90/200,   Variance Loss: -82.2898\n",
      "Epoch 100/200,   Variance Loss: -85.1637\n",
      "Epoch 110/200,   Variance Loss: -85.9878\n",
      "Epoch 120/200,   Variance Loss: -86.5004\n",
      "Epoch 130/200,   Variance Loss: -87.0645\n",
      "Epoch 140/200,   Variance Loss: -87.8408\n",
      "Epoch 150/200,   Variance Loss: -88.2632\n",
      "Epoch 160/200,   Variance Loss: -88.8714\n",
      "Epoch 170/200,   Variance Loss: -89.2933\n",
      "Epoch 180/200,   Variance Loss: -89.6370\n",
      "Epoch 190/200,   Variance Loss: -89.6460\n",
      "Epoch 200/200,   Variance Loss: -90.1725\n",
      "Epoch 10/200,   Variance Loss: 17.0460\n",
      "Epoch 20/200,   Variance Loss: -56.5101\n",
      "Epoch 30/200,   Variance Loss: -71.6868\n",
      "Epoch 40/200,   Variance Loss: -74.1898\n",
      "Epoch 50/200,   Variance Loss: -75.2630\n",
      "Epoch 60/200,   Variance Loss: -75.8522\n",
      "Epoch 70/200,   Variance Loss: -76.6001\n",
      "Epoch 80/200,   Variance Loss: -77.7784\n",
      "Epoch 90/200,   Variance Loss: -79.9218\n",
      "Epoch 100/200,   Variance Loss: -83.4317\n",
      "Epoch 110/200,   Variance Loss: -85.0742\n",
      "Epoch 120/200,   Variance Loss: -85.7127\n",
      "Epoch 130/200,   Variance Loss: -86.5199\n",
      "Epoch 140/200,   Variance Loss: -87.4368\n",
      "Epoch 150/200,   Variance Loss: -87.9953\n",
      "Epoch 160/200,   Variance Loss: -88.4743\n",
      "Epoch 170/200,   Variance Loss: -88.7038\n",
      "Epoch 180/200,   Variance Loss: -89.0596\n",
      "Epoch 190/200,   Variance Loss: -89.2638\n",
      "Epoch 200/200,   Variance Loss: -89.6133\n",
      "Epoch 10/200,   Variance Loss: 8.8431\n",
      "Epoch 20/200,   Variance Loss: -68.8240\n",
      "Epoch 30/200,   Variance Loss: -72.2738\n",
      "Epoch 40/200,   Variance Loss: -75.2933\n",
      "Epoch 50/200,   Variance Loss: -76.3664\n",
      "Epoch 60/200,   Variance Loss: -77.9861\n",
      "Epoch 70/200,   Variance Loss: -80.9221\n",
      "Epoch 80/200,   Variance Loss: -84.4680\n",
      "Epoch 90/200,   Variance Loss: -85.3220\n",
      "Epoch 100/200,   Variance Loss: -85.7776\n",
      "Epoch 110/200,   Variance Loss: -86.2446\n",
      "Epoch 120/200,   Variance Loss: -87.4061\n",
      "Epoch 130/200,   Variance Loss: -87.8366\n",
      "Epoch 140/200,   Variance Loss: -88.5113\n",
      "Epoch 150/200,   Variance Loss: -88.7428\n",
      "Epoch 160/200,   Variance Loss: -89.1848\n",
      "Epoch 170/200,   Variance Loss: -89.3084\n",
      "Epoch 180/200,   Variance Loss: -89.5660\n",
      "Epoch 190/200,   Variance Loss: -89.7140\n",
      "Epoch 200/200,   Variance Loss: -89.7766\n",
      "Epoch 10/200,   Variance Loss: 8.0986\n",
      "Epoch 20/200,   Variance Loss: -67.2612\n",
      "Epoch 30/200,   Variance Loss: -71.8780\n",
      "Epoch 40/200,   Variance Loss: -74.9509\n",
      "Epoch 50/200,   Variance Loss: -75.6279\n",
      "Epoch 60/200,   Variance Loss: -77.1503\n",
      "Epoch 70/200,   Variance Loss: -81.2894\n",
      "Epoch 80/200,   Variance Loss: -84.6024\n",
      "Epoch 90/200,   Variance Loss: -85.2279\n",
      "Epoch 100/200,   Variance Loss: -85.4430\n",
      "Epoch 110/200,   Variance Loss: -85.5532\n",
      "Epoch 120/200,   Variance Loss: -85.6454\n",
      "Epoch 130/200,   Variance Loss: -85.7793\n",
      "Epoch 140/200,   Variance Loss: -86.3713\n",
      "Epoch 150/200,   Variance Loss: -87.5808\n",
      "Epoch 160/200,   Variance Loss: -88.3551\n",
      "Epoch 170/200,   Variance Loss: -88.8088\n",
      "Epoch 180/200,   Variance Loss: -89.2448\n",
      "Epoch 190/200,   Variance Loss: -89.4127\n",
      "Epoch 200/200,   Variance Loss: -89.5963\n",
      "Iteration 1 complete\n",
      "Iteration 2 complete\n",
      "Iteration 3 complete\n",
      "Iteration 4 complete\n",
      "Iteration 5 complete\n",
      "Iteration 6 complete\n",
      "Iteration 7 complete\n",
      "Iteration 8 complete\n",
      "Iteration 9 complete\n",
      "Iteration 10 complete\n"
     ]
    }
   ],
   "source": [
    "sideinfo_array = np.arange(1, p + 1).reshape(-1, 1).astype(np.float32)\n",
    "rmses  = []\n",
    "\n",
    "rmses_ash  = []\n",
    "for  k in  range(1, 11):\n",
    "    base_path = Path(\"C:/Document/Serieux/Travail/Data_analysis_and_papers/nash_experiement/data_split\")\n",
    "    result_path = Path(\"C:/Document/Serieux/Travail/Data_analysis_and_papers/nash_experiement/results_realdata\")\n",
    "    dataset_path = Path(\"C:/Document/Serieux/Travail/Data_analysis_and_papers/nash_experiement/data_split/Airpassenger\")\n",
    "    X_train = pd.read_csv(dataset_path / f\"X_train{k}.csv\").values.astype(np.float32)\n",
    "    y_train = pd.read_csv(dataset_path / f\"y_train{k}.csv\").values.astype(np.float32).flatten()\n",
    "    X_test = pd.read_csv(dataset_path / f\"X_test{k}.csv\").values.astype(np.float32)\n",
    "    y_test = pd.read_csv(dataset_path / f\"y_test{k}.csv\").values.astype(np.float32).flatten()\n",
    "    X =  np.eye(144) #X_train.astype(np.float32)\n",
    "    y = y_train.astype(np.float32).flatten()\n",
    "    sideinfo= sideinfo_array\n",
    "    maxit=10\n",
    "    damping=0.99\n",
    "    # Standardize\n",
    "    X, csd = col_scale(X)\n",
    "    y, ysd = col_scale(y.reshape(-1, 1))\n",
    "    y = y.flatten()\n",
    "\n",
    "    n, p = X.shape\n",
    "    sqn = np.sqrt(n).astype(np.float32)\n",
    "\n",
    "    # Initialize via Lasso\n",
    "    lasso = LassoCV(cv=5, max_iter=5000)\n",
    "    lasso.fit(X, y)\n",
    "    beta = lasso.coef_\n",
    "\n",
    "    # Initialize prior as None\n",
    "    log_pi, scale, location = None, None, None\n",
    "    td_beta = []\n",
    "    pi0=0\n",
    "    for o in range(maxit):\n",
    "        betahat_list, sebetahat_list = [], []\n",
    "        for k in range(p):\n",
    "            r = y - X @ beta\n",
    "            beta_new = beta.copy()\n",
    "            xk = X[:, k]\n",
    "            r_k = r + xk * beta_new[k]\n",
    "            betahat_k = np.dot(xk, r_k) / n\n",
    "            sebetahat_k = max(np.std(r_k) / sqn, 1e-4)\n",
    "            if 0<1: \n",
    "\n",
    "                beta_k_new = betahat_k\n",
    "                beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "             \n",
    "            else :\n",
    "                print(o)\n",
    "                pm = posterior_mean_norm(\n",
    "                    betahat=np.array([betahat_k]),\n",
    "                    sebetahat=np.array([sebetahat_k]),\n",
    "                    log_pi=np.log( np.clip( result.pi_np[k, :], 1e-12, 1.0)),\n",
    "                    location=result.location[k, :],\n",
    "                    scale=result.scale[k, :]\n",
    "                    )\n",
    "             \n",
    "                beta_k_new = pm.post_mean[0]\n",
    "\n",
    "            r += xk * (beta_new[k]  - beta_k_new)\n",
    "            beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "            beta_new[k]=beta_k_new\n",
    "            betahat_list.append(betahat_k)\n",
    "            sebetahat_list.append(sebetahat_k) \n",
    "\n",
    "\n",
    "        betahat_arr = np.array(betahat_list)\n",
    "        avg_se = np.mean(sebetahat_list)\n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ betahat_arr ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )   \n",
    " \n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ beta ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )\n",
    "        denom = n + p * (1 - pi0)\n",
    "        sigma_0 = np.sqrt(max((res_sq_final + sigma_0_term) / denom, 1e-8)) / sqn\n",
    "\n",
    "        res_sq = np.sum((y - X @ betahat_arr) ** 2)\n",
    "        drift_term = np.dot(betahat_arr,  betahat_arr) / np.sqrt(n + p)\n",
    "        s = np.sqrt((res_sq + drift_term)) / sqn\n",
    "\n",
    "        # Update drift_comp\n",
    "        drift_comp =    (1 / (n / s**2 + 1 / sigma_0**2)) * (n / s**2)\n",
    "        if o<1: \n",
    "            # Update beta with ash\n",
    "            ash_input = betahat_arr   \n",
    "            result =Cash_posterior_means(X= sideinfo,\n",
    "                                            betahat= betahat_arr ,\n",
    "                                            sebetahat=np.array(sebetahat_list) ,n_epochs=50  ) \n",
    "        else :\n",
    "            ash_input = drift_comp * betahat_arr + (1 - drift_comp) * result.post_mean\n",
    "            result =Cash_posterior_means(X= sideinfo,\n",
    "                                          betahat=  ash_input, #ash_input ,\n",
    "                                          sebetahat= np.full_like(ash_input,sigma_0) /sqn   ,\n",
    "                                          n_epochs=200  )\n",
    "            log_pi= result.pi_np\n",
    "            beta =   result.post_mean\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "    est= np.sqrt(mean_squared_error(ysd* X@result.post_mean ,y_test))# np.sqrt(mean_squared_error(ysd* X@betahat_arr ,y_test))\n",
    "    rmses.append(est)\n",
    "    est_nash = nash_noinfo_dynamic_td(X=np.eye(144),y=y_train)\n",
    "\n",
    "    temp=np.sqrt(mean_squared_error(ysd* X@est_nash ,y_test))\n",
    "    rmses_ash.append(temp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "167117ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19.625836438695224"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(rmses) \n",
    "np.array(rmses).mean() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "499e6e2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "2*np.array(rmses).std()/np.sqrt(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1214802b",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    " \n",
    "X =  np.eye(144) #X_train.astype(np.float32)\n",
    "y = y_train.astype(np.float32).flatten()\n",
    "sideinfo= sideinfo_array\n",
    "maxit=10\n",
    "damping=0.99\n",
    "    # Standardize\n",
    "X, csd = col_scale(X)\n",
    "y, ysd = col_scale(y.reshape(-1, 1))\n",
    "y = y.flatten()\n",
    "\n",
    "n, p = X.shape\n",
    "sqn = np.sqrt(n).astype(np.float32)\n",
    "\n",
    "    # Initialize via Lasso\n",
    "lasso = LassoCV(cv=5, max_iter=5000)\n",
    "lasso.fit(X, y)\n",
    "beta = lasso.coef_\n",
    "\n",
    "    # Initialize prior as None\n",
    "log_pi, scale, location = None, None, None\n",
    "td_beta = []\n",
    "pi0=0\n",
    "for o in range(maxit):\n",
    "        betahat_list, sebetahat_list = [], []\n",
    "        for k in range(p):\n",
    "            r = y - X @ beta\n",
    "            beta_new = beta.copy()\n",
    "            xk = X[:, k]\n",
    "            r_k = r + xk * beta_new[k]\n",
    "            betahat_k = np.dot(xk, r_k) / n\n",
    "            sebetahat_k = max(np.std(r_k) / sqn, 1e-4)\n",
    "            if 0<1: \n",
    "\n",
    "                beta_k_new = betahat_k\n",
    "                beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "             \n",
    "            else :\n",
    "                print(o)\n",
    "                pm = posterior_mean_norm(\n",
    "                    betahat=np.array([betahat_k]),\n",
    "                    sebetahat=np.array([sebetahat_k]),\n",
    "                    log_pi=np.log( np.clip( result.pi_np[k, :], 1e-12, 1.0)),\n",
    "                    location=result.location[k, :],\n",
    "                    scale=result.scale[k, :]\n",
    "                    )\n",
    "             \n",
    "                beta_k_new = pm.post_mean[0]\n",
    "\n",
    "            r += xk * (beta_new[k]  - beta_k_new)\n",
    "            beta_k_new = damping * beta_k_new + (1 - damping) * beta_new[k]\n",
    "            beta_new[k]=beta_k_new\n",
    "            betahat_list.append(betahat_k)\n",
    "            sebetahat_list.append(sebetahat_k) \n",
    "\n",
    "\n",
    "        betahat_arr = np.array(betahat_list)\n",
    "        avg_se = np.mean(sebetahat_list)\n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ betahat_arr ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )   \n",
    " \n",
    "        beta = beta_new.copy()\n",
    "        res_sq_final = np.sum((y - X @ beta ) ** 2)\n",
    "        sigma_0_term = np.dot(beta, beta - betahat_arr )\n",
    "        denom = n + p * (1 - pi0)\n",
    "        sigma_0 = np.sqrt(max((res_sq_final + sigma_0_term) / denom, 1e-8)) / sqn\n",
    "\n",
    "        res_sq = np.sum((y - X @ betahat_arr) ** 2)\n",
    "        drift_term = np.dot(betahat_arr,  betahat_arr) / np.sqrt(n + p)\n",
    "        s = np.sqrt((res_sq + drift_term)) / sqn\n",
    "\n",
    "        # Update drift_comp\n",
    "        drift_comp =    (1 / (n / s**2 + 1 / sigma_0**2)) * (n / s**2)\n",
    "        if o<1: \n",
    "            # Update beta with ash\n",
    "            ash_input = betahat_arr   \n",
    "            result =Cash_posterior_means(X= sideinfo,\n",
    "                                            betahat= betahat_arr ,\n",
    "                                            sebetahat=np.array(sebetahat_list) ,n_epochs=50  ) \n",
    "        else :\n",
    "            ash_input = drift_comp * betahat_arr + (1 - drift_comp) * result.post_mean\n",
    "            result =Cash_posterior_means(X= sideinfo,\n",
    "                                          betahat=  ash_input, #ash_input ,\n",
    "                                          sebetahat= np.full_like(ash_input,sigma_0) /sqn   ,\n",
    "                                          n_epochs=50  )\n",
    "            log_pi= result.pi_np\n",
    "            beta =   result.post_mean\n",
    "\n",
    "  \n",
    "plt.plot(X@ result.post_mean)\n",
    "\n",
    "#plt.plot(X@ betahat_arr)\n",
    "#plt.plot(y)\n",
    "#print(drift_comp)\n",
    "print(np.sqrt(mean_squared_error(ysd* X@result.post_mean ,y_train)))\n",
    "#print(np.sqrt(mean_squared_error(ysd* X@betahat_arr ,y_test)))\n",
    " \n",
    "print(np.sqrt(mean_squared_error(ysd* X@betahat_arr ,y_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48a0b7f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(np.sqrt(mean_squared_error(ysd* X@result.post_mean ,y_test)))\n",
    "#print(np.sqrt(mean_squared_error(ysd* X@betahat_arr ,y_test)))\n",
    " \n",
    "print(np.sqrt(mean_squared_error(ysd* X@betahat_arr ,y_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8827da6",
   "metadata": {},
   "outputs": [],
   "source": [
    "result =emdn_posterior_means(X= sideinfo,\n",
    "                                          betahat=  ash_input, #ash_input ,\n",
    "                                          sebetahat= np.full_like(ash_input,sigma_0) /sqn ,\n",
    "                                          n_epochs=200  )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "c65dd53c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x16eb1e11f00>]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 52404 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(betahat_arr )\n",
    "plt.plot(result.post_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "bcce452e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x16eb1dda050>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 22952 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter ( betahat_arr,result.post_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00be493a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86854008",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot( ysd*betahat_arr/csd )\n",
    "plt.plot(y_test) \n",
    "np.sqrt(mean_squared_error( ysd*betahat_arr/csd ,y_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b67c4f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot( ysd*betahat_arr/csd )\n",
    "plt.plot(y_train)\n",
    "np.sqrt(mean_squared_error(2* ysd*result.post_mean/csd ,y_test))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml_env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
