{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b5ec981e-3b5e-4d46-b763-fe4b2ae22532",
   "metadata": {},
   "source": [
    "# Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7deb56e2-31b3-48be-9069-2b97d6a8920f",
   "metadata": {},
   "source": [
    "- Learning by doing and explaining\n",
    "- Writing a technical blog is a valuable skill.\n",
    "- Blog is like a resume only better"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5128741a-6918-44c0-9dc8-45dc776a7a9f",
   "metadata": {},
   "source": [
    "## Why study Linear Algebra?\n",
    "\n",
    "```{note}\n",
    "KEY QUESTION :-\n",
    "> How can we do matrix multiplication with acceptable speed and acceptable accuracy?\n",
    "\n",
    "QUESTIONS :-\n",
    "> How computers(finite & discrete) store numbers (infinite & continuous)?\n",
    "\n",
    "When designing algorithms for matrix multiplications we often have to tradeoff between :-\n",
    "- Memory Use\n",
    "- Speed (Approximate matrix computation may be 1000 times faster than actual one)\n",
    "- Accuracy\n",
    "- Scalability/ Parallelization\n",
    "```\n",
    "\n",
    "## Types of Matrix Computations\n",
    "- Matrix & Tensor products\n",
    "- Matrix decomposition\n",
    "\n",
    "## Topics to be covered\n",
    "- Topic Modelling\n",
    "- Background Removal\n",
    "- Google PageRank Algorithm\n",
    "- Matrix Factorization Jungle"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28e85b7e-7597-4d0b-9d59-767e950f8141",
   "metadata": {},
   "source": [
    "[Lesson#1 Why are we here?](https://nbviewer.org/github/fastai/numerical-linear-algebra/blob/master/nbs/1.%20Why%20are%20we%20here.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27fecb24-ebb3-4aae-a889-b56a107fe317",
   "metadata": {},
   "source": [
    "## Imports "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b386b01-3e4b-4702-97f1-d0614afa477b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "49c2aa58-1715-45ad-81a9-5ec12dca1e6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "current_healthstate = np.array([[0.85], #asymptotic\n",
    "                                [0.10], #symptotic\n",
    "                                [0.5],  #aids\n",
    "                                [0.0]]) #death\n",
    "# current_healthstate[np.newaxis,]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e89b9d4-c232-43a7-baa3-a4d1d4889cf5",
   "metadata": {},
   "source": [
    "transition matrix for 1 year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a6018ca-417d-412f-a821-6b86c19e9290",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.9 , 0.07, 0.03, 0.01],\n",
       "       [0.  , 0.93, 0.05, 0.02],\n",
       "       [0.  , 0.  , 0.85, 0.15],\n",
       "       [0.  , 0.  , 0.  , 1.  ]])"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#            asymptotic symptotic aids death\n",
    "# asymptotic\n",
    "# symptotic\n",
    "# aids\n",
    "# death\n",
    "\n",
    "transition_matrix = np.array([[0.9, 0.07, 0.03, 0.01],\n",
    "                              [0.0, 0.93, 0.05, 0.02],\n",
    "                              [0.0, 0.00, 0.85, 0.15],\n",
    "                              [0.0, 0.00, 0.00, 1.00]])\n",
    "transition_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf07a08b-bf52-4510-93d2-f0f7a3586222",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.765 , 0.1525, 0.4555, 0.0855]])"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next_state = current_healthstate.T@transition_matrix; next_state\n",
    "# This answer seems incorrect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "163c31bc-cb6d-4de1-aef2-6b36917099be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[50. , 49. ],\n",
       "       [58.5, 61. ],\n",
       "       [43.5, 43.5]])"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transition_matrix = np.array([[6, 5, 3, 1],\n",
    "                              [3, 6, 2, 2],\n",
    "                              [3, 4, 3, 1]])\n",
    "\n",
    "inp_matrix = np.array([[1.5, 1],\n",
    "                      [2, 2.5],\n",
    "                      [5, 4.5],\n",
    "                      [16., 17.]])\n",
    "\n",
    "transition_matrix@inp_matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37757608-c656-4415-855c-f1d558ded304",
   "metadata": {},
   "source": [
    "## Greenbaum & Chartier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd48eaf8-ed06-4784-b52b-de7f6a808214",
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x):\n",
    "    if x <= 1/2:\n",
    "        return 2 * x\n",
    "    if x > 1/2:\n",
    "        return 2*x - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67f3c657-03bf-4ca9-8640-a4b6e2664585",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.1\n",
      "0.2\n",
      "0.4\n",
      "0.8\n",
      "0.6000000000000001\n",
      "0.20000000000000018\n",
      "0.40000000000000036\n",
      "0.8000000000000007\n",
      "0.6000000000000014\n",
      "0.20000000000000284\n",
      "0.4000000000000057\n",
      "0.8000000000000114\n",
      "0.6000000000000227\n",
      "0.20000000000004547\n",
      "0.40000000000009095\n",
      "0.8000000000001819\n",
      "0.6000000000003638\n",
      "0.2000000000007276\n",
      "0.4000000000014552\n",
      "0.8000000000029104\n",
      "0.6000000000058208\n",
      "0.20000000001164153\n",
      "0.40000000002328306\n",
      "0.8000000000465661\n",
      "0.6000000000931323\n",
      "0.20000000018626451\n",
      "0.40000000037252903\n",
      "0.8000000007450581\n",
      "0.6000000014901161\n",
      "0.20000000298023224\n",
      "0.4000000059604645\n",
      "0.800000011920929\n",
      "0.6000000238418579\n",
      "0.20000004768371582\n",
      "0.40000009536743164\n",
      "0.8000001907348633\n",
      "0.6000003814697266\n",
      "0.20000076293945312\n",
      "0.40000152587890625\n",
      "0.8000030517578125\n",
      "0.600006103515625\n",
      "0.20001220703125\n",
      "0.4000244140625\n",
      "0.800048828125\n",
      "0.60009765625\n",
      "0.2001953125\n",
      "0.400390625\n",
      "0.80078125\n",
      "0.6015625\n",
      "0.203125\n",
      "0.40625\n",
      "0.8125\n",
      "0.625\n",
      "0.25\n",
      "0.5\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n",
      "1.0\n"
     ]
    }
   ],
   "source": [
    "x = 1/10\n",
    "for i in range(80):\n",
    "    print(x)\n",
    "    x = f(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8fc4695-36eb-4953-a83e-27c8edc526f5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}