From ebcaf38c85ad3a2bf93faac86f5b8bd9e8a77926 Mon Sep 17 00:00:00 2001
From: vkarve2 <vkarve2@illinois.edu>
Date: Sat, 22 Sep 2018 13:45:54 -0500
Subject: [PATCH] Add cooments to all notebooks.

---
 .gitignore                                    |  2 +-
 .../AlgorithmTesting.ipynb                    |  0
 MultiplicativeAlgorithm/ExtremeEvents.ipynb   | 21 ++++++++-----
 MultiplicativeAlgorithm/Visualizations.ipynb  | 31 ++++++++++---------
 MultiplicativeAlgorithm/Visualizations.py     |  2 ++
 MultiplicativeAlgorithm/cSNMF.py              |  6 ++--
 6 files changed, 36 insertions(+), 26 deletions(-)
 rename {MultiplicativeAlgorithm => Archive}/AlgorithmTesting.ipynb (100%)

diff --git a/.gitignore b/.gitignore
index 2324cd3..6c6109e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
 */.ipynb_checkpoints/
-*/__pycache__/
+**/__pycache__/
 MultiplicativeAlgorithm/D_trips.txt
 MultiplicativeAlgorithm/D_speeds.txt
 MultiplicativeAlgorithm/*.png
diff --git a/MultiplicativeAlgorithm/AlgorithmTesting.ipynb b/Archive/AlgorithmTesting.ipynb
similarity index 100%
rename from MultiplicativeAlgorithm/AlgorithmTesting.ipynb
rename to Archive/AlgorithmTesting.ipynb
diff --git a/MultiplicativeAlgorithm/ExtremeEvents.ipynb b/MultiplicativeAlgorithm/ExtremeEvents.ipynb
index 2320491..23a4cdc 100644
--- a/MultiplicativeAlgorithm/ExtremeEvents.ipynb
+++ b/MultiplicativeAlgorithm/ExtremeEvents.ipynb
@@ -1,5 +1,12 @@
 {
  "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# This notebook identifies days on which Traffic deviates significantly from its median weekly behavior."
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -9,6 +16,7 @@
     "import numpy as np\n",
     "%matplotlib inline\n",
     "import matplotlib.pyplot as plt\n",
+    "import seaborn as sns\n",
     "\n",
     "W = np.loadtxt('W_trips.txt')"
    ]
@@ -19,7 +27,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "assert W.shape == (8760, 50)\n",
+    "# Calculate meedian weekly traffic trends for each signature\n",
     "W_day_week = [[] for dayofweek in range(7)]\n",
     "W_day_hour_week = [[] for dayofweek in range(7)]\n",
     "W_day_hour_median = [[] for dayofweek in range(7)]\n",
@@ -53,8 +61,9 @@
    "metadata": {},
    "outputs": [],
    "source": [
+    "# Calculate deviation from median trend for each day of the year and store in numpy array X.\n",
     "dev = [0 for hourofyear in range(8760)]\n",
-    "X = [0 for dayofyear in range(365)]\n",
+    "X   = [0 for dayofyear in range(365)]\n",
     "\n",
     "for hourofyear in range(8760):\n",
     "    dayofyear = hourofyear//365\n",
@@ -77,11 +86,6 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "import numpy as np\n",
-    "%matplotlib inline\n",
-    "import matplotlib.pyplot as plt\n",
-    "import seaborn as sns\n",
-    "\n",
     "X = np.loadtxt('X_trips.txt')\n",
     "fig, ax = plt.subplots()\n",
     "sns.set()\n",
@@ -95,6 +99,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
+    "# Sort days in decreasing order of (total deviation for all 50 signatures)\n",
     "sorted(enumerate(np.sum(X, axis=1)), key=lambda day: day[1], reverse=True)"
    ]
   },
@@ -104,6 +109,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
+    "# Sort days in decreasing order of (maximum deviation among all 50 signatures)\n",
     "sorted(enumerate(X.max(axis=1)), key=lambda day:day[1], reverse=True)"
    ]
   },
@@ -113,6 +119,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
+    "# Manually track extreme events and make relevant plots and graphs\n",
     "days_of_week = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thurday', 'Friday']\n",
     "for sig in range(50):\n",
     "    date = 238; dname = 'Aug27' # August 27, Hurrnicane Irene day 3\n",
diff --git a/MultiplicativeAlgorithm/Visualizations.ipynb b/MultiplicativeAlgorithm/Visualizations.ipynb
index 3574ee1..5791a8a 100644
--- a/MultiplicativeAlgorithm/Visualizations.ipynb
+++ b/MultiplicativeAlgorithm/Visualizations.ipynb
@@ -1,5 +1,18 @@
 {
  "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# This notebook is used for visualizing the results from cSNMF.ipynb\n",
+    "Map visualizations require links.csv from ../DataFiles/\n",
+    "\n",
+    "We do the following visualizations:\n",
+    "- Plot of each signature, for every day of the week (50 sigs $\\times$ 7 days)\n",
+    "- Map of all links for each signature\n",
+    "- Map of all links that use 7+ signatures"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -8,22 +21,10 @@
    "source": [
     "import numpy as np\n",
     "import pandas as pd\n",
-    "import config\n",
     "%matplotlib notebook\n",
-    "import matplotlib.pyplot as plt"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# This notebook is used for visualizing the results from cSNMF.ipynb\n",
-    "Map visualizations require links.csv from ??????\n",
+    "import matplotlib.pyplot as plt\n",
     "\n",
-    "We do the following visualizations:\n",
-    "- Plot of each signature, for every day of the week (70 sigs $\\times$ 7 days)\n",
-    "- Map of all links for each signature\n",
-    "- Map of all links that use 7+ signatures"
+    "import config"
    ]
   },
   {
@@ -338,7 +339,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.6.3"
+   "version": "3.6.6"
   }
  },
  "nbformat": 4,
diff --git a/MultiplicativeAlgorithm/Visualizations.py b/MultiplicativeAlgorithm/Visualizations.py
index f3896b4..fbbfca6 100644
--- a/MultiplicativeAlgorithm/Visualizations.py
+++ b/MultiplicativeAlgorithm/Visualizations.py
@@ -1,3 +1,5 @@
+'''There function are self-explanatory. However there is redundancy in these functions since some of them use folium while others use geopandas.'''
+
 import numpy as np
 import pandas as pd
 import matplotlib.pyplot as plt
diff --git a/MultiplicativeAlgorithm/cSNMF.py b/MultiplicativeAlgorithm/cSNMF.py
index e02494e..d58bfbb 100644
--- a/MultiplicativeAlgorithm/cSNMF.py
+++ b/MultiplicativeAlgorithm/cSNMF.py
@@ -119,11 +119,11 @@ def factorize(data_array,
     H_shape = (rank, D.shape[1])
     
     if init_W is None:
-        update_W = True
+        change_W = True
         np.random.seed(seed_W)
         W = np.random.uniform(low = 0.01, high = 1., size = W_shape)    
     else:
-        update_W = False
+        change_W = False
         W = init_W
         
     np.random.seed(seed_H)
@@ -143,7 +143,7 @@ def factorize(data_array,
         if iterations > max_iter:
             break
             
-        if update_W:
+        if change_W:
             W_new = update_W(W, H)
         else:
             W_new = W
-- 
GitLab