{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The Trigger Function\n",
    "\n",
    "https://www.desmos.com/calculator/yxklrjs5m3\n",
    "\n",
    "Below we show a sweep of the trigger function threshold, considering the share of funds requested (on the x-axis) with the alpha parameter and effective supply (y-axis):"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Factor out the demonstration of the trigger function from the top of the main simulation notebook\n",
    "+ add a few more plots and explanations about how and why it works"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "\n",
    "from cadCAD.configuration.utils import config_sim\n",
    "from model.parts.utils import *\n",
    "from model.parts.sys_params import * \n",
    "\n",
    "sim_config = config_sim({\n",
    "    'N': 1,\n",
    "    'T': range(100), #day \n",
    "    'M': params,\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for reference: max conviction = 5.035599031662158in log10 units\n"
     ]
    }
   ],
   "source": [
    "supply = initial_values['supply']\n",
    "alpha = sim_config[0]['M']['alpha']\n",
    "\n",
    "mcv = supply/(1-alpha)\n",
    "print('for reference: max conviction = '+str(np.log10(mcv))+'in log10 units')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "supply_sweep = trigger_sweep('effective_supply',trigger_threshold, sim_config[0]['M'], supply)\n",
    "alpha_sweep = trigger_sweep('alpha',trigger_threshold, sim_config[0]['M'], supply)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 117888 characters]\n",
      "text/plain": [
       "<Figure size 1440x1440 with 4 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "trigger_grid(supply_sweep, alpha_sweep)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "These plots demonstrate the increasing conviction required to pass a proposal when either % of funds requested, effective supply, or alpha parameter is high. Blue areas represent lower required conviction, and red areas represent impossibly high conviction. This ensures that the reserve pool of funds are not depleted by a small number of large proposals.\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}