diff --git a/stock2vec.ipynb b/stock2vec.ipynb
index fe31d67..d3cb22b 100644
--- a/stock2vec.ipynb
+++ b/stock2vec.ipynb
@@ -2,7 +2,10 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
"source": [
"# stock2vec\n",
"\n",
@@ -11,9 +14,11 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 12,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
@@ -32,7 +37,7 @@
"from functools import partial\n",
"from tqdm import tqdm\n",
"\n",
- "# %config InlineBackend.figure_format = 'retina'\n",
+ "%config InlineBackend.figure_format = 'retina'\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib notebook"
@@ -40,7 +45,10 @@
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
"source": [
"Load the diluted earnings per share by ticker."
]
@@ -49,11 +57,13 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
- "CSV_URL = 'https://s3.amazonaws.com/perl-ml/prices.csv?response-content-disposition=attachment&X-Amz-Security-Token=FQoDYXdzECIaDLG1ZU6Yzztd7CsNGCKsAgNa3zgOVIw%2BQB8y%2FcRAMdAYK0ZPWW59OqVSuRuFGv3NEX3LapeZnns4VZleRraw1352r%2BP1CJm2hqgg2OlGcjf8pa414x90CDCdyIemO8HJwoIr4nKi18945ZmxthTL04BJsHD1MN0Tp%2F30A3kUMqscJP68vuQ75w098gKBJFxlnKztFUnP91Myn3%2FrrNUKQ%2F%2BODJx%2Bmpu7CMOGZlDLlSHtpTKbo8pULbHFGZAe%2BAvPqq0KU71nJ%2FWjUPcbLaEjSxOZl3%2BP98cePjijlMC8O6r9JzjTqGKUUUiqOWA92QZ6UtZfUlkyO%2BcNdLGltRJrCkGEctmyhJ6Qnim0eIfSBlzhDVPAtuAdTDrXzi2d3SGOJNm8P56ak71Vnk7P%2FSyGZsdQ9G0nMXBH1GeG5yjr7ebGBQ%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20170328T010700Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=ASIAJBTQPDQAOL557TLA%2F20170328%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=16a879624653ee25590a42768d975982001f3451249973af25e9d93942fec054'\n",
+ "CSV_URL = 'SEE_PREPROCESSING_NOTEBOOK'\n",
"FILE_NAME = 'input/prices.csv'\n",
"LOG_DIR = 'output'\n",
"MODEL_PATH = os.path.join(LOG_DIR, \"model.ckpt\")\n",
@@ -67,9 +77,19 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Prices: 485MB [00:36, 13.1MB/s] \n"
+ ]
+ }
+ ],
"source": [
"from urllib.request import urlretrieve\n",
"from os.path import isfile, isdir\n",
@@ -94,14 +114,16 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "rows: 10000000it [00:14, 683810.80it/s] \n"
+ "rows: 10000000it [00:13, 784808.61it/s] \n"
]
},
{
@@ -149,9 +171,11 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 13,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [
{
@@ -713,7 +737,7 @@
"};\n",
"mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
"\n",
- "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
+ "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
"\n",
"mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
" // Create a \"websocket\"-like object which calls the given IPython comm\n",
@@ -934,7 +958,7 @@
{
"data": {
"text/html": [
- "
"
+ "
"
],
"text/plain": [
""
@@ -964,7 +988,10 @@
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
"source": [
"## Build context\n",
"\n",
@@ -973,11 +1000,32 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "window for 0 OLED 0\n",
+ "1 YUM\n",
+ "2 SWY\n",
+ "3 PEP\n",
+ "4 SVU\n",
+ "window for 9 SVU 4\n",
+ "0 OLED\n",
+ "1 YUM\n",
+ "2 SWY\n",
+ "3 PEP\n",
+ "window for 18 PEP 3\n",
+ "2 SWY\n"
+ ]
+ }
+ ],
"source": [
"ticker_to_int = {}\n",
"int_to_ticker = {}\n",
@@ -1016,11 +1064,21 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "100%|██████████| 919/919 [01:39<00:00, 9.27it/s]"
+ ]
+ }
+ ],
"source": [
"batch_size = 10000\n",
"window_size = 10\n",
@@ -1057,9 +1115,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
@@ -1070,20 +1130,25 @@
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
"source": [
"## Build the Graph"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
- "n_embedding = 400 # Number of embedding features \n",
+ "n_embedding = 50 # Number of embedding features \n",
"n_stocks = len(df_prices['ticker'].unique())\n",
"\n",
"train_graph = tf.Graph()\n",
@@ -1096,16 +1161,21 @@
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
"source": [
"# Negative sampling"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 16,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
@@ -1127,9 +1197,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 17,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
@@ -1153,7 +1225,10 @@
},
{
"cell_type": "markdown",
- "metadata": {},
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
"source": [
"# Training"
]
@@ -1163,11 +1238,217 @@
"execution_count": null,
"metadata": {
"collapsed": false,
+ "deletable": true,
+ "editable": true,
"scrolled": false
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Epoch 1/20 Iteration: 100 Avg. Training loss: 4.5168 0.1068 sec/batch\n",
+ "Epoch 1/20 Iteration: 200 Avg. Training loss: 4.2953 0.1026 sec/batch\n",
+ "Epoch 1/20 Iteration: 300 Avg. Training loss: 4.1577 0.1006 sec/batch\n",
+ "Epoch 1/20 Iteration: 400 Avg. Training loss: 4.0547 0.1018 sec/batch\n",
+ "Epoch 1/20 Iteration: 500 Avg. Training loss: 4.0295 0.1044 sec/batch\n",
+ "Epoch 1/20 Iteration: 600 Avg. Training loss: 3.8883 0.0993 sec/batch\n",
+ "Epoch 1/20 Iteration: 700 Avg. Training loss: 3.8033 0.0987 sec/batch\n",
+ "Epoch 1/20 Iteration: 800 Avg. Training loss: 3.7277 0.1019 sec/batch\n",
+ "Epoch 1/20 Iteration: 900 Avg. Training loss: 3.7987 0.1011 sec/batch\n",
+ "Epoch 2/20 Iteration: 1000 Avg. Training loss: 4.2752 0.0814 sec/batch\n",
+ "Epoch 2/20 Iteration: 1100 Avg. Training loss: 4.0082 0.1055 sec/batch\n",
+ "Epoch 2/20 Iteration: 1200 Avg. Training loss: 3.8316 0.1014 sec/batch\n",
+ "Epoch 2/20 Iteration: 1300 Avg. Training loss: 3.8532 0.0999 sec/batch\n",
+ "Epoch 2/20 Iteration: 1400 Avg. Training loss: 3.9195 0.1011 sec/batch\n",
+ "Epoch 2/20 Iteration: 1500 Avg. Training loss: 3.7725 0.1037 sec/batch\n",
+ "Epoch 2/20 Iteration: 1600 Avg. Training loss: 3.6816 0.1023 sec/batch\n",
+ "Epoch 2/20 Iteration: 1700 Avg. Training loss: 3.6588 0.1021 sec/batch\n",
+ "Epoch 2/20 Iteration: 1800 Avg. Training loss: 3.7112 0.1025 sec/batch\n",
+ "Epoch 3/20 Iteration: 1900 Avg. Training loss: 4.0917 0.0618 sec/batch\n",
+ "Epoch 3/20 Iteration: 2000 Avg. Training loss: 3.9588 0.1024 sec/batch\n",
+ "Epoch 3/20 Iteration: 2100 Avg. Training loss: 3.7398 0.1009 sec/batch\n",
+ "Epoch 3/20 Iteration: 2200 Avg. Training loss: 3.7453 0.1021 sec/batch\n",
+ "Epoch 3/20 Iteration: 2300 Avg. Training loss: 3.9012 0.1026 sec/batch\n",
+ "Epoch 3/20 Iteration: 2400 Avg. Training loss: 3.7606 0.1016 sec/batch\n",
+ "Epoch 3/20 Iteration: 2500 Avg. Training loss: 3.6935 0.1022 sec/batch\n",
+ "Epoch 3/20 Iteration: 2600 Avg. Training loss: 3.6132 0.1036 sec/batch\n",
+ "Epoch 3/20 Iteration: 2700 Avg. Training loss: 3.6775 0.1016 sec/batch\n",
+ "Epoch 4/20 Iteration: 2800 Avg. Training loss: 3.9706 0.0405 sec/batch\n",
+ "Epoch 4/20 Iteration: 2900 Avg. Training loss: 3.9701 0.1022 sec/batch\n",
+ "Epoch 4/20 Iteration: 3000 Avg. Training loss: 3.7405 0.1019 sec/batch\n",
+ "Epoch 4/20 Iteration: 3100 Avg. Training loss: 3.6953 0.1026 sec/batch\n",
+ "Epoch 4/20 Iteration: 3200 Avg. Training loss: 3.8717 0.0974 sec/batch\n",
+ "Epoch 4/20 Iteration: 3300 Avg. Training loss: 3.7402 0.1026 sec/batch\n",
+ "Epoch 4/20 Iteration: 3400 Avg. Training loss: 3.6701 0.0994 sec/batch\n",
+ "Epoch 4/20 Iteration: 3500 Avg. Training loss: 3.5721 0.1025 sec/batch\n",
+ "Epoch 4/20 Iteration: 3600 Avg. Training loss: 3.6113 0.1010 sec/batch\n",
+ "Epoch 5/20 Iteration: 3700 Avg. Training loss: 3.8495 0.0196 sec/batch\n",
+ "Epoch 5/20 Iteration: 3800 Avg. Training loss: 4.0316 0.0975 sec/batch\n",
+ "Epoch 5/20 Iteration: 3900 Avg. Training loss: 3.7321 0.1000 sec/batch\n",
+ "Epoch 5/20 Iteration: 4000 Avg. Training loss: 3.6589 0.0971 sec/batch\n",
+ "Epoch 5/20 Iteration: 4100 Avg. Training loss: 3.8299 0.0997 sec/batch\n",
+ "Epoch 5/20 Iteration: 4200 Avg. Training loss: 3.7547 0.1006 sec/batch\n",
+ "Epoch 5/20 Iteration: 4300 Avg. Training loss: 3.6827 0.0992 sec/batch\n",
+ "Epoch 5/20 Iteration: 4400 Avg. Training loss: 3.6048 0.1018 sec/batch\n",
+ "Epoch 5/20 Iteration: 4500 Avg. Training loss: 3.6017 0.1011 sec/batch\n",
+ "Epoch 5/20 Iteration: 4600 Avg. Training loss: 3.6698 0.1010 sec/batch\n",
+ "Epoch 6/20 Iteration: 4700 Avg. Training loss: 4.1400 0.0999 sec/batch\n",
+ "Epoch 6/20 Iteration: 4800 Avg. Training loss: 3.7424 0.1010 sec/batch\n",
+ "Epoch 6/20 Iteration: 4900 Avg. Training loss: 3.6545 0.1002 sec/batch\n",
+ "Epoch 6/20 Iteration: 5000 Avg. Training loss: 3.8030 0.1013 sec/batch\n",
+ "Epoch 6/20 Iteration: 5100 Avg. Training loss: 3.7828 0.1006 sec/batch\n",
+ "Epoch 6/20 Iteration: 5200 Avg. Training loss: 3.6678 0.1035 sec/batch\n",
+ "Epoch 6/20 Iteration: 5300 Avg. Training loss: 3.5894 0.1024 sec/batch\n",
+ "Epoch 6/20 Iteration: 5400 Avg. Training loss: 3.5663 0.1021 sec/batch\n",
+ "Epoch 6/20 Iteration: 5500 Avg. Training loss: 3.6286 0.1040 sec/batch\n",
+ "Epoch 7/20 Iteration: 5600 Avg. Training loss: 4.0833 0.0813 sec/batch\n",
+ "Epoch 7/20 Iteration: 5700 Avg. Training loss: 3.7976 0.1000 sec/batch\n",
+ "Epoch 7/20 Iteration: 5800 Avg. Training loss: 3.6538 0.0979 sec/batch\n",
+ "Epoch 7/20 Iteration: 5900 Avg. Training loss: 3.7465 0.1001 sec/batch\n",
+ "Epoch 7/20 Iteration: 6000 Avg. Training loss: 3.8208 0.1033 sec/batch\n",
+ "Epoch 7/20 Iteration: 6100 Avg. Training loss: 3.6532 0.0978 sec/batch\n",
+ "Epoch 7/20 Iteration: 6200 Avg. Training loss: 3.6064 0.1025 sec/batch\n",
+ "Epoch 7/20 Iteration: 6300 Avg. Training loss: 3.5591 0.1008 sec/batch\n",
+ "Epoch 7/20 Iteration: 6400 Avg. Training loss: 3.6270 0.1039 sec/batch\n",
+ "Epoch 8/20 Iteration: 6500 Avg. Training loss: 4.0046 0.0611 sec/batch\n",
+ "Epoch 8/20 Iteration: 6600 Avg. Training loss: 3.8044 0.0999 sec/batch\n",
+ "Epoch 8/20 Iteration: 6700 Avg. Training loss: 3.6440 0.1009 sec/batch\n",
+ "Epoch 8/20 Iteration: 6800 Avg. Training loss: 3.6816 0.1019 sec/batch\n",
+ "Epoch 8/20 Iteration: 6900 Avg. Training loss: 3.8365 0.1019 sec/batch\n",
+ "Epoch 8/20 Iteration: 7000 Avg. Training loss: 3.6728 0.1001 sec/batch\n",
+ "Epoch 8/20 Iteration: 7100 Avg. Training loss: 3.6114 0.1018 sec/batch\n",
+ "Epoch 8/20 Iteration: 7200 Avg. Training loss: 3.5414 0.1005 sec/batch\n",
+ "Epoch 8/20 Iteration: 7300 Avg. Training loss: 3.5768 0.1001 sec/batch\n",
+ "Epoch 9/20 Iteration: 7400 Avg. Training loss: 3.8674 0.0400 sec/batch\n",
+ "Epoch 9/20 Iteration: 7500 Avg. Training loss: 3.8815 0.0987 sec/batch\n",
+ "Epoch 9/20 Iteration: 7600 Avg. Training loss: 3.6408 0.1011 sec/batch\n",
+ "Epoch 9/20 Iteration: 7700 Avg. Training loss: 3.6545 0.0988 sec/batch\n",
+ "Epoch 9/20 Iteration: 7800 Avg. Training loss: 3.8404 0.1021 sec/batch\n",
+ "Epoch 9/20 Iteration: 7900 Avg. Training loss: 3.6918 0.1004 sec/batch\n",
+ "Epoch 9/20 Iteration: 8000 Avg. Training loss: 3.6399 0.0995 sec/batch\n",
+ "Epoch 9/20 Iteration: 8100 Avg. Training loss: 3.5271 0.0996 sec/batch\n",
+ "Epoch 9/20 Iteration: 8200 Avg. Training loss: 3.5425 0.1021 sec/batch\n",
+ "Epoch 10/20 Iteration: 8300 Avg. Training loss: 3.7883 0.0193 sec/batch\n",
+ "Epoch 10/20 Iteration: 8400 Avg. Training loss: 3.9858 0.0997 sec/batch\n",
+ "Epoch 10/20 Iteration: 8500 Avg. Training loss: 3.6711 0.1006 sec/batch\n",
+ "Epoch 10/20 Iteration: 8600 Avg. Training loss: 3.6316 0.0995 sec/batch\n",
+ "Epoch 10/20 Iteration: 8700 Avg. Training loss: 3.8192 0.0990 sec/batch\n",
+ "Epoch 10/20 Iteration: 8800 Avg. Training loss: 3.7340 0.1012 sec/batch\n",
+ "Epoch 10/20 Iteration: 8900 Avg. Training loss: 3.6305 0.1028 sec/batch\n",
+ "Epoch 10/20 Iteration: 9000 Avg. Training loss: 3.5494 0.0998 sec/batch\n",
+ "Epoch 10/20 Iteration: 9100 Avg. Training loss: 3.5416 0.1010 sec/batch\n",
+ "Epoch 10/20 Iteration: 9200 Avg. Training loss: 3.6143 0.0989 sec/batch\n",
+ "Epoch 11/20 Iteration: 9300 Avg. Training loss: 4.0852 0.1002 sec/batch\n",
+ "Epoch 11/20 Iteration: 9400 Avg. Training loss: 3.6892 0.1007 sec/batch\n",
+ "Epoch 11/20 Iteration: 9500 Avg. Training loss: 3.6209 0.1017 sec/batch\n",
+ "Epoch 11/20 Iteration: 9600 Avg. Training loss: 3.7604 0.1020 sec/batch\n",
+ "Epoch 11/20 Iteration: 9700 Avg. Training loss: 3.7568 0.1021 sec/batch\n",
+ "Epoch 11/20 Iteration: 9800 Avg. Training loss: 3.6326 0.0996 sec/batch\n",
+ "Epoch 11/20 Iteration: 9900 Avg. Training loss: 3.5509 0.0999 sec/batch\n",
+ "Epoch 11/20 Iteration: 10000 Avg. Training loss: 3.5358 0.0986 sec/batch\n",
+ "Nearest to UFI: URI, MNTX, SPNS, LCI, CYBX, UIS, CRWN, GORO,\n",
+ "Nearest to GES: RTN, GPS, UFPT, MSFT, WBCO, AET, CACI, CI,\n",
+ "Nearest to ODP: SNBC, RGS, CSE, AAL, RT, AGYS, BBY, CUTR,\n",
+ "Nearest to MCK: HRC, VFC, SEIC, WWW, IEX, ARTNA, CIR, TW,\n",
+ "Nearest to SWY: FRF, CIT, HIL, EMR, BEN, EVC, ROC, SCSC,\n",
+ "Nearest to VVUS: VICL, SRPT, ARQL, GALE, BTX, GMO, NKTR, PCYO,\n",
+ "Nearest to FTR: MATX, HPT, SRE, MPW, OKE, AWI, CBL, RGC,\n",
+ "Nearest to IMGN: EXAS, BTX, ARQL, BCRX, MSO, CAS, ASCMA, SIGA,\n",
+ "Nearest to PLXS: NDAQ, ASNA, LDL, MTZ, DHIL, SMP, CMS, KAMN,\n",
+ "Nearest to MMM: CBRL, CVS, CFR, MGEE, CPK, LO, ICFI, MTSC,\n",
+ "Nearest to FITB: HTLF, NUTR, DST, HCC, GME, ARW, ANCX, LNC,\n",
+ "Nearest to ASTE: COHR, COO, MKL, CBOE, NTAP, CRS, PAYX, DTLK,\n",
+ "Nearest to HLX: SALM, AVID, CBZ, CROX, CCRN, TXT, MSFG, NCR,\n",
+ "Nearest to CCC: MTRN, MMS, MASI, IRBT, VDSI, HCKT, GOOGL, CRUS,\n",
+ "Nearest to WAT: KMX, PX, CTAS, DCI, CHRW, PDCO, LLTC, ALTR,\n",
+ "Nearest to FWRD: KNX, CL, NKE, CWT, ORLY, APH, COO, FELE,\n",
+ "Epoch 11/20 Iteration: 10100 Avg. Training loss: 3.5715 0.1005 sec/batch\n",
+ "Epoch 12/20 Iteration: 10200 Avg. Training loss: 4.0426 0.0787 sec/batch\n",
+ "Epoch 12/20 Iteration: 10300 Avg. Training loss: 3.7252 0.1004 sec/batch\n",
+ "Epoch 12/20 Iteration: 10400 Avg. Training loss: 3.6070 0.1026 sec/batch\n",
+ "Epoch 12/20 Iteration: 10500 Avg. Training loss: 3.7185 0.1027 sec/batch\n",
+ "Epoch 12/20 Iteration: 10600 Avg. Training loss: 3.7873 0.0996 sec/batch\n",
+ "Epoch 12/20 Iteration: 10700 Avg. Training loss: 3.6582 0.1000 sec/batch\n",
+ "Epoch 12/20 Iteration: 10800 Avg. Training loss: 3.5789 0.1004 sec/batch\n",
+ "Epoch 12/20 Iteration: 10900 Avg. Training loss: 3.5230 0.1007 sec/batch\n",
+ "Epoch 12/20 Iteration: 11000 Avg. Training loss: 3.5765 0.0999 sec/batch\n",
+ "Epoch 13/20 Iteration: 11100 Avg. Training loss: 3.9889 0.0619 sec/batch\n",
+ "Epoch 13/20 Iteration: 11200 Avg. Training loss: 3.7892 0.1008 sec/batch\n",
+ "Epoch 13/20 Iteration: 11300 Avg. Training loss: 3.6253 0.0993 sec/batch\n",
+ "Epoch 13/20 Iteration: 11400 Avg. Training loss: 3.6674 0.1019 sec/batch\n",
+ "Epoch 13/20 Iteration: 11500 Avg. Training loss: 3.8050 0.1012 sec/batch\n",
+ "Epoch 13/20 Iteration: 11600 Avg. Training loss: 3.6570 0.1031 sec/batch\n",
+ "Epoch 13/20 Iteration: 11700 Avg. Training loss: 3.5895 0.0995 sec/batch\n",
+ "Epoch 13/20 Iteration: 11800 Avg. Training loss: 3.5086 0.1013 sec/batch\n",
+ "Epoch 13/20 Iteration: 11900 Avg. Training loss: 3.5307 0.0986 sec/batch\n",
+ "Epoch 14/20 Iteration: 12000 Avg. Training loss: 3.8772 0.0402 sec/batch\n",
+ "Epoch 14/20 Iteration: 12100 Avg. Training loss: 3.8458 0.1008 sec/batch\n",
+ "Epoch 14/20 Iteration: 12200 Avg. Training loss: 3.6315 0.1003 sec/batch\n",
+ "Epoch 14/20 Iteration: 12300 Avg. Training loss: 3.6364 0.1021 sec/batch\n",
+ "Epoch 14/20 Iteration: 12400 Avg. Training loss: 3.8390 0.1000 sec/batch\n",
+ "Epoch 14/20 Iteration: 12500 Avg. Training loss: 3.6792 0.1008 sec/batch\n",
+ "Epoch 14/20 Iteration: 12600 Avg. Training loss: 3.6001 0.0999 sec/batch\n",
+ "Epoch 14/20 Iteration: 12700 Avg. Training loss: 3.5277 0.1003 sec/batch\n",
+ "Epoch 14/20 Iteration: 12800 Avg. Training loss: 3.5506 0.0998 sec/batch\n",
+ "Epoch 15/20 Iteration: 12900 Avg. Training loss: 3.7440 0.0208 sec/batch\n",
+ "Epoch 15/20 Iteration: 13000 Avg. Training loss: 3.9341 0.1013 sec/batch\n",
+ "Epoch 15/20 Iteration: 13100 Avg. Training loss: 3.6494 0.1016 sec/batch\n",
+ "Epoch 15/20 Iteration: 13200 Avg. Training loss: 3.6164 0.0990 sec/batch\n",
+ "Epoch 15/20 Iteration: 13300 Avg. Training loss: 3.8015 0.0992 sec/batch\n",
+ "Epoch 15/20 Iteration: 13400 Avg. Training loss: 3.7031 0.1000 sec/batch\n",
+ "Epoch 15/20 Iteration: 13500 Avg. Training loss: 3.6159 0.0996 sec/batch\n",
+ "Epoch 15/20 Iteration: 13600 Avg. Training loss: 3.5164 0.1007 sec/batch\n",
+ "Epoch 15/20 Iteration: 13700 Avg. Training loss: 3.5243 0.0990 sec/batch\n",
+ "Epoch 15/20 Iteration: 13800 Avg. Training loss: 3.5532 0.0989 sec/batch\n",
+ "Epoch 16/20 Iteration: 13900 Avg. Training loss: 4.0605 0.1023 sec/batch\n",
+ "Epoch 16/20 Iteration: 14000 Avg. Training loss: 3.6741 0.0995 sec/batch\n",
+ "Epoch 16/20 Iteration: 14100 Avg. Training loss: 3.6259 0.1031 sec/batch\n",
+ "Epoch 16/20 Iteration: 14200 Avg. Training loss: 3.7474 0.1014 sec/batch\n",
+ "Epoch 16/20 Iteration: 14300 Avg. Training loss: 3.7281 0.1014 sec/batch\n",
+ "Epoch 16/20 Iteration: 14400 Avg. Training loss: 3.6376 0.1012 sec/batch\n",
+ "Epoch 16/20 Iteration: 14500 Avg. Training loss: 3.5464 0.0968 sec/batch\n",
+ "Epoch 16/20 Iteration: 14600 Avg. Training loss: 3.5140 0.0998 sec/batch\n",
+ "Epoch 16/20 Iteration: 14700 Avg. Training loss: 3.5288 0.1014 sec/batch\n",
+ "Epoch 17/20 Iteration: 14800 Avg. Training loss: 4.0308 0.0799 sec/batch\n",
+ "Epoch 17/20 Iteration: 14900 Avg. Training loss: 3.7101 0.1028 sec/batch\n",
+ "Epoch 17/20 Iteration: 15000 Avg. Training loss: 3.5954 0.1007 sec/batch\n",
+ "Epoch 17/20 Iteration: 15100 Avg. Training loss: 3.7106 0.1027 sec/batch\n",
+ "Epoch 17/20 Iteration: 15200 Avg. Training loss: 3.7766 0.0998 sec/batch\n",
+ "Epoch 17/20 Iteration: 15300 Avg. Training loss: 3.6294 0.1027 sec/batch\n",
+ "Epoch 17/20 Iteration: 15400 Avg. Training loss: 3.5576 0.0989 sec/batch\n",
+ "Epoch 17/20 Iteration: 15500 Avg. Training loss: 3.5075 0.1023 sec/batch\n",
+ "Epoch 17/20 Iteration: 15600 Avg. Training loss: 3.5378 0.0982 sec/batch\n",
+ "Epoch 18/20 Iteration: 15700 Avg. Training loss: 3.9460 0.0594 sec/batch\n",
+ "Epoch 18/20 Iteration: 15800 Avg. Training loss: 3.7765 0.0997 sec/batch\n",
+ "Epoch 18/20 Iteration: 15900 Avg. Training loss: 3.6078 0.1020 sec/batch\n",
+ "Epoch 18/20 Iteration: 16000 Avg. Training loss: 3.6418 0.1025 sec/batch\n",
+ "Epoch 18/20 Iteration: 16100 Avg. Training loss: 3.8194 0.1006 sec/batch\n",
+ "Epoch 18/20 Iteration: 16200 Avg. Training loss: 3.6160 0.1006 sec/batch\n",
+ "Epoch 18/20 Iteration: 16300 Avg. Training loss: 3.5744 0.0998 sec/batch\n",
+ "Epoch 18/20 Iteration: 16400 Avg. Training loss: 3.5029 0.1033 sec/batch\n",
+ "Epoch 18/20 Iteration: 16500 Avg. Training loss: 3.5344 0.1015 sec/batch\n",
+ "Epoch 19/20 Iteration: 16600 Avg. Training loss: 3.8664 0.0414 sec/batch\n",
+ "Epoch 19/20 Iteration: 16700 Avg. Training loss: 3.8270 0.0995 sec/batch\n",
+ "Epoch 19/20 Iteration: 16800 Avg. Training loss: 3.6308 0.1016 sec/batch\n",
+ "Epoch 19/20 Iteration: 16900 Avg. Training loss: 3.6175 0.1000 sec/batch\n",
+ "Epoch 19/20 Iteration: 17000 Avg. Training loss: 3.8262 0.1010 sec/batch\n",
+ "Epoch 19/20 Iteration: 17100 Avg. Training loss: 3.6729 0.0996 sec/batch\n",
+ "Epoch 19/20 Iteration: 17200 Avg. Training loss: 3.5943 0.1021 sec/batch\n",
+ "Epoch 19/20 Iteration: 17300 Avg. Training loss: 3.5261 0.0981 sec/batch\n",
+ "Epoch 19/20 Iteration: 17400 Avg. Training loss: 3.4943 0.0973 sec/batch\n",
+ "Epoch 20/20 Iteration: 17500 Avg. Training loss: 3.7168 0.0193 sec/batch\n",
+ "Epoch 20/20 Iteration: 17600 Avg. Training loss: 3.9343 0.1016 sec/batch\n",
+ "Epoch 20/20 Iteration: 17700 Avg. Training loss: 3.6456 0.1030 sec/batch\n",
+ "Epoch 20/20 Iteration: 17800 Avg. Training loss: 3.6141 0.1016 sec/batch\n",
+ "Epoch 20/20 Iteration: 17900 Avg. Training loss: 3.7874 0.0990 sec/batch\n",
+ "Epoch 20/20 Iteration: 18000 Avg. Training loss: 3.7057 0.1022 sec/batch\n",
+ "Epoch 20/20 Iteration: 18100 Avg. Training loss: 3.6083 0.1024 sec/batch\n"
+ ]
+ }
+ ],
"source": [
- "epochs = 10\n",
+ "epochs = 20\n",
"\n",
"with train_graph.as_default():\n",
" saver = tf.train.Saver()\n",
@@ -1221,9 +1502,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
@@ -1248,9 +1531,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 23,
"metadata": {
- "collapsed": true
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": [
@@ -1263,11 +1548,803 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 24,
"metadata": {
- "collapsed": false
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "application/javascript": [
+ "/* Put everything inside the global mpl namespace */\n",
+ "window.mpl = {};\n",
+ "\n",
+ "\n",
+ "mpl.get_websocket_type = function() {\n",
+ " if (typeof(WebSocket) !== 'undefined') {\n",
+ " return WebSocket;\n",
+ " } else if (typeof(MozWebSocket) !== 'undefined') {\n",
+ " return MozWebSocket;\n",
+ " } else {\n",
+ " alert('Your browser does not have WebSocket support.' +\n",
+ " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
+ " 'Firefox 4 and 5 are also supported but you ' +\n",
+ " 'have to enable WebSockets in about:config.');\n",
+ " };\n",
+ "}\n",
+ "\n",
+ "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
+ " this.id = figure_id;\n",
+ "\n",
+ " this.ws = websocket;\n",
+ "\n",
+ " this.supports_binary = (this.ws.binaryType != undefined);\n",
+ "\n",
+ " if (!this.supports_binary) {\n",
+ " var warnings = document.getElementById(\"mpl-warnings\");\n",
+ " if (warnings) {\n",
+ " warnings.style.display = 'block';\n",
+ " warnings.textContent = (\n",
+ " \"This browser does not support binary websocket messages. \" +\n",
+ " \"Performance may be slow.\");\n",
+ " }\n",
+ " }\n",
+ "\n",
+ " this.imageObj = new Image();\n",
+ "\n",
+ " this.context = undefined;\n",
+ " this.message = undefined;\n",
+ " this.canvas = undefined;\n",
+ " this.rubberband_canvas = undefined;\n",
+ " this.rubberband_context = undefined;\n",
+ " this.format_dropdown = undefined;\n",
+ "\n",
+ " this.image_mode = 'full';\n",
+ "\n",
+ " this.root = $('');\n",
+ " this._root_extra_style(this.root)\n",
+ " this.root.attr('style', 'display: inline-block');\n",
+ "\n",
+ " $(parent_element).append(this.root);\n",
+ "\n",
+ " this._init_header(this);\n",
+ " this._init_canvas(this);\n",
+ " this._init_toolbar(this);\n",
+ "\n",
+ " var fig = this;\n",
+ "\n",
+ " this.waiting = false;\n",
+ "\n",
+ " this.ws.onopen = function () {\n",
+ " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
+ " fig.send_message(\"send_image_mode\", {});\n",
+ " if (mpl.ratio != 1) {\n",
+ " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
+ " }\n",
+ " fig.send_message(\"refresh\", {});\n",
+ " }\n",
+ "\n",
+ " this.imageObj.onload = function() {\n",
+ " if (fig.image_mode == 'full') {\n",
+ " // Full images could contain transparency (where diff images\n",
+ " // almost always do), so we need to clear the canvas so that\n",
+ " // there is no ghosting.\n",
+ " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
+ " }\n",
+ " fig.context.drawImage(fig.imageObj, 0, 0);\n",
+ " };\n",
+ "\n",
+ " this.imageObj.onunload = function() {\n",
+ " this.ws.close();\n",
+ " }\n",
+ "\n",
+ " this.ws.onmessage = this._make_on_message_function(this);\n",
+ "\n",
+ " this.ondownload = ondownload;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_header = function() {\n",
+ " var titlebar = $(\n",
+ " '');\n",
+ " var titletext = $(\n",
+ " '');\n",
+ " titlebar.append(titletext)\n",
+ " this.root.append(titlebar);\n",
+ " this.header = titletext[0];\n",
+ "}\n",
+ "\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
+ "\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
+ "\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_canvas = function() {\n",
+ " var fig = this;\n",
+ "\n",
+ " var canvas_div = $('');\n",
+ "\n",
+ " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
+ "\n",
+ " function canvas_keyboard_event(event) {\n",
+ " return fig.key_event(event, event['data']);\n",
+ " }\n",
+ "\n",
+ " canvas_div.keydown('key_press', canvas_keyboard_event);\n",
+ " canvas_div.keyup('key_release', canvas_keyboard_event);\n",
+ " this.canvas_div = canvas_div\n",
+ " this._canvas_extra_style(canvas_div)\n",
+ " this.root.append(canvas_div);\n",
+ "\n",
+ " var canvas = $('');\n",
+ " canvas.addClass('mpl-canvas');\n",
+ " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
+ "\n",
+ " this.canvas = canvas[0];\n",
+ " this.context = canvas[0].getContext(\"2d\");\n",
+ "\n",
+ " var backingStore = this.context.backingStorePixelRatio ||\n",
+ "\tthis.context.webkitBackingStorePixelRatio ||\n",
+ "\tthis.context.mozBackingStorePixelRatio ||\n",
+ "\tthis.context.msBackingStorePixelRatio ||\n",
+ "\tthis.context.oBackingStorePixelRatio ||\n",
+ "\tthis.context.backingStorePixelRatio || 1;\n",
+ "\n",
+ " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
+ "\n",
+ " var rubberband = $('');\n",
+ " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
+ "\n",
+ " var pass_mouse_events = true;\n",
+ "\n",
+ " canvas_div.resizable({\n",
+ " start: function(event, ui) {\n",
+ " pass_mouse_events = false;\n",
+ " },\n",
+ " resize: function(event, ui) {\n",
+ " fig.request_resize(ui.size.width, ui.size.height);\n",
+ " },\n",
+ " stop: function(event, ui) {\n",
+ " pass_mouse_events = true;\n",
+ " fig.request_resize(ui.size.width, ui.size.height);\n",
+ " },\n",
+ " });\n",
+ "\n",
+ " function mouse_event_fn(event) {\n",
+ " if (pass_mouse_events)\n",
+ " return fig.mouse_event(event, event['data']);\n",
+ " }\n",
+ "\n",
+ " rubberband.mousedown('button_press', mouse_event_fn);\n",
+ " rubberband.mouseup('button_release', mouse_event_fn);\n",
+ " // Throttle sequential mouse events to 1 every 20ms.\n",
+ " rubberband.mousemove('motion_notify', mouse_event_fn);\n",
+ "\n",
+ " rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
+ " rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
+ "\n",
+ " canvas_div.on(\"wheel\", function (event) {\n",
+ " event = event.originalEvent;\n",
+ " event['data'] = 'scroll'\n",
+ " if (event.deltaY < 0) {\n",
+ " event.step = 1;\n",
+ " } else {\n",
+ " event.step = -1;\n",
+ " }\n",
+ " mouse_event_fn(event);\n",
+ " });\n",
+ "\n",
+ " canvas_div.append(canvas);\n",
+ " canvas_div.append(rubberband);\n",
+ "\n",
+ " this.rubberband = rubberband;\n",
+ " this.rubberband_canvas = rubberband[0];\n",
+ " this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
+ " this.rubberband_context.strokeStyle = \"#000000\";\n",
+ "\n",
+ " this._resize_canvas = function(width, height) {\n",
+ " // Keep the size of the canvas, canvas container, and rubber band\n",
+ " // canvas in synch.\n",
+ " canvas_div.css('width', width)\n",
+ " canvas_div.css('height', height)\n",
+ "\n",
+ " canvas.attr('width', width * mpl.ratio);\n",
+ " canvas.attr('height', height * mpl.ratio);\n",
+ " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
+ "\n",
+ " rubberband.attr('width', width);\n",
+ " rubberband.attr('height', height);\n",
+ " }\n",
+ "\n",
+ " // Set the figure to an initial 600x600px, this will subsequently be updated\n",
+ " // upon first draw.\n",
+ " this._resize_canvas(600, 600);\n",
+ "\n",
+ " // Disable right mouse context menu.\n",
+ " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
+ " return false;\n",
+ " });\n",
+ "\n",
+ " function set_focus () {\n",
+ " canvas.focus();\n",
+ " canvas_div.focus();\n",
+ " }\n",
+ "\n",
+ " window.setTimeout(set_focus, 100);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_toolbar = function() {\n",
+ " var fig = this;\n",
+ "\n",
+ " var nav_element = $('')\n",
+ " nav_element.attr('style', 'width: 100%');\n",
+ " this.root.append(nav_element);\n",
+ "\n",
+ " // Define a callback function for later on.\n",
+ " function toolbar_event(event) {\n",
+ " return fig.toolbar_button_onclick(event['data']);\n",
+ " }\n",
+ " function toolbar_mouse_event(event) {\n",
+ " return fig.toolbar_button_onmouseover(event['data']);\n",
+ " }\n",
+ "\n",
+ " for(var toolbar_ind in mpl.toolbar_items) {\n",
+ " var name = mpl.toolbar_items[toolbar_ind][0];\n",
+ " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
+ " var image = mpl.toolbar_items[toolbar_ind][2];\n",
+ " var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
+ "\n",
+ " if (!name) {\n",
+ " // put a spacer in here.\n",
+ " continue;\n",
+ " }\n",
+ " var button = $('');\n",
+ " button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
+ " 'ui-button-icon-only');\n",
+ " button.attr('role', 'button');\n",
+ " button.attr('aria-disabled', 'false');\n",
+ " button.click(method_name, toolbar_event);\n",
+ " button.mouseover(tooltip, toolbar_mouse_event);\n",
+ "\n",
+ " var icon_img = $('');\n",
+ " icon_img.addClass('ui-button-icon-primary ui-icon');\n",
+ " icon_img.addClass(image);\n",
+ " icon_img.addClass('ui-corner-all');\n",
+ "\n",
+ " var tooltip_span = $('');\n",
+ " tooltip_span.addClass('ui-button-text');\n",
+ " tooltip_span.html(tooltip);\n",
+ "\n",
+ " button.append(icon_img);\n",
+ " button.append(tooltip_span);\n",
+ "\n",
+ " nav_element.append(button);\n",
+ " }\n",
+ "\n",
+ " var fmt_picker_span = $('');\n",
+ "\n",
+ " var fmt_picker = $('');\n",
+ " fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
+ " fmt_picker_span.append(fmt_picker);\n",
+ " nav_element.append(fmt_picker_span);\n",
+ " this.format_dropdown = fmt_picker[0];\n",
+ "\n",
+ " for (var ind in mpl.extensions) {\n",
+ " var fmt = mpl.extensions[ind];\n",
+ " var option = $(\n",
+ " '', {selected: fmt === mpl.default_extension}).html(fmt);\n",
+ " fmt_picker.append(option)\n",
+ " }\n",
+ "\n",
+ " // Add hover states to the ui-buttons\n",
+ " $( \".ui-button\" ).hover(\n",
+ " function() { $(this).addClass(\"ui-state-hover\");},\n",
+ " function() { $(this).removeClass(\"ui-state-hover\");}\n",
+ " );\n",
+ "\n",
+ " var status_bar = $('');\n",
+ " nav_element.append(status_bar);\n",
+ " this.message = status_bar[0];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
+ " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
+ " // which will in turn request a refresh of the image.\n",
+ " this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.send_message = function(type, properties) {\n",
+ " properties['type'] = type;\n",
+ " properties['figure_id'] = this.id;\n",
+ " this.ws.send(JSON.stringify(properties));\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.send_draw_message = function() {\n",
+ " if (!this.waiting) {\n",
+ " this.waiting = true;\n",
+ " this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
+ " var format_dropdown = fig.format_dropdown;\n",
+ " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
+ " fig.ondownload(fig, format);\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
+ " var size = msg['size'];\n",
+ " if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
+ " fig._resize_canvas(size[0], size[1]);\n",
+ " fig.send_message(\"refresh\", {});\n",
+ " };\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
+ " var x0 = msg['x0'] / mpl.ratio;\n",
+ " var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
+ " var x1 = msg['x1'] / mpl.ratio;\n",
+ " var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
+ " x0 = Math.floor(x0) + 0.5;\n",
+ " y0 = Math.floor(y0) + 0.5;\n",
+ " x1 = Math.floor(x1) + 0.5;\n",
+ " y1 = Math.floor(y1) + 0.5;\n",
+ " var min_x = Math.min(x0, x1);\n",
+ " var min_y = Math.min(y0, y1);\n",
+ " var width = Math.abs(x1 - x0);\n",
+ " var height = Math.abs(y1 - y0);\n",
+ "\n",
+ " fig.rubberband_context.clearRect(\n",
+ " 0, 0, fig.canvas.width, fig.canvas.height);\n",
+ "\n",
+ " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
+ " // Updates the figure title.\n",
+ " fig.header.textContent = msg['label'];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
+ " var cursor = msg['cursor'];\n",
+ " switch(cursor)\n",
+ " {\n",
+ " case 0:\n",
+ " cursor = 'pointer';\n",
+ " break;\n",
+ " case 1:\n",
+ " cursor = 'default';\n",
+ " break;\n",
+ " case 2:\n",
+ " cursor = 'crosshair';\n",
+ " break;\n",
+ " case 3:\n",
+ " cursor = 'move';\n",
+ " break;\n",
+ " }\n",
+ " fig.rubberband_canvas.style.cursor = cursor;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
+ " fig.message.textContent = msg['message'];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
+ " // Request the server to send over a new figure.\n",
+ " fig.send_draw_message();\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
+ " fig.image_mode = msg['mode'];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.updated_canvas_event = function() {\n",
+ " // Called whenever the canvas gets updated.\n",
+ " this.send_message(\"ack\", {});\n",
+ "}\n",
+ "\n",
+ "// A function to construct a web socket function for onmessage handling.\n",
+ "// Called in the figure constructor.\n",
+ "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
+ " return function socket_on_message(evt) {\n",
+ " if (evt.data instanceof Blob) {\n",
+ " /* FIXME: We get \"Resource interpreted as Image but\n",
+ " * transferred with MIME type text/plain:\" errors on\n",
+ " * Chrome. But how to set the MIME type? It doesn't seem\n",
+ " * to be part of the websocket stream */\n",
+ " evt.data.type = \"image/png\";\n",
+ "\n",
+ " /* Free the memory for the previous frames */\n",
+ " if (fig.imageObj.src) {\n",
+ " (window.URL || window.webkitURL).revokeObjectURL(\n",
+ " fig.imageObj.src);\n",
+ " }\n",
+ "\n",
+ " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
+ " evt.data);\n",
+ " fig.updated_canvas_event();\n",
+ " fig.waiting = false;\n",
+ " return;\n",
+ " }\n",
+ " else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
+ " fig.imageObj.src = evt.data;\n",
+ " fig.updated_canvas_event();\n",
+ " fig.waiting = false;\n",
+ " return;\n",
+ " }\n",
+ "\n",
+ " var msg = JSON.parse(evt.data);\n",
+ " var msg_type = msg['type'];\n",
+ "\n",
+ " // Call the \"handle_{type}\" callback, which takes\n",
+ " // the figure and JSON message as its only arguments.\n",
+ " try {\n",
+ " var callback = fig[\"handle_\" + msg_type];\n",
+ " } catch (e) {\n",
+ " console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
+ " return;\n",
+ " }\n",
+ "\n",
+ " if (callback) {\n",
+ " try {\n",
+ " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
+ " callback(fig, msg);\n",
+ " } catch (e) {\n",
+ " console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
+ " }\n",
+ " }\n",
+ " };\n",
+ "}\n",
+ "\n",
+ "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
+ "mpl.findpos = function(e) {\n",
+ " //this section is from http://www.quirksmode.org/js/events_properties.html\n",
+ " var targ;\n",
+ " if (!e)\n",
+ " e = window.event;\n",
+ " if (e.target)\n",
+ " targ = e.target;\n",
+ " else if (e.srcElement)\n",
+ " targ = e.srcElement;\n",
+ " if (targ.nodeType == 3) // defeat Safari bug\n",
+ " targ = targ.parentNode;\n",
+ "\n",
+ " // jQuery normalizes the pageX and pageY\n",
+ " // pageX,Y are the mouse positions relative to the document\n",
+ " // offset() returns the position of the element relative to the document\n",
+ " var x = e.pageX - $(targ).offset().left;\n",
+ " var y = e.pageY - $(targ).offset().top;\n",
+ "\n",
+ " return {\"x\": x, \"y\": y};\n",
+ "};\n",
+ "\n",
+ "/*\n",
+ " * return a copy of an object with only non-object keys\n",
+ " * we need this to avoid circular references\n",
+ " * http://stackoverflow.com/a/24161582/3208463\n",
+ " */\n",
+ "function simpleKeys (original) {\n",
+ " return Object.keys(original).reduce(function (obj, key) {\n",
+ " if (typeof original[key] !== 'object')\n",
+ " obj[key] = original[key]\n",
+ " return obj;\n",
+ " }, {});\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.mouse_event = function(event, name) {\n",
+ " var canvas_pos = mpl.findpos(event)\n",
+ "\n",
+ " if (name === 'button_press')\n",
+ " {\n",
+ " this.canvas.focus();\n",
+ " this.canvas_div.focus();\n",
+ " }\n",
+ "\n",
+ " var x = canvas_pos.x * mpl.ratio;\n",
+ " var y = canvas_pos.y * mpl.ratio;\n",
+ "\n",
+ " this.send_message(name, {x: x, y: y, button: event.button,\n",
+ " step: event.step,\n",
+ " guiEvent: simpleKeys(event)});\n",
+ "\n",
+ " /* This prevents the web browser from automatically changing to\n",
+ " * the text insertion cursor when the button is pressed. We want\n",
+ " * to control all of the cursor setting manually through the\n",
+ " * 'cursor' event from matplotlib */\n",
+ " event.preventDefault();\n",
+ " return false;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
+ " // Handle any extra behaviour associated with a key event\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.key_event = function(event, name) {\n",
+ "\n",
+ " // Prevent repeat events\n",
+ " if (name == 'key_press')\n",
+ " {\n",
+ " if (event.which === this._key)\n",
+ " return;\n",
+ " else\n",
+ " this._key = event.which;\n",
+ " }\n",
+ " if (name == 'key_release')\n",
+ " this._key = null;\n",
+ "\n",
+ " var value = '';\n",
+ " if (event.ctrlKey && event.which != 17)\n",
+ " value += \"ctrl+\";\n",
+ " if (event.altKey && event.which != 18)\n",
+ " value += \"alt+\";\n",
+ " if (event.shiftKey && event.which != 16)\n",
+ " value += \"shift+\";\n",
+ "\n",
+ " value += 'k';\n",
+ " value += event.which.toString();\n",
+ "\n",
+ " this._key_event_extra(event, name);\n",
+ "\n",
+ " this.send_message(name, {key: value,\n",
+ " guiEvent: simpleKeys(event)});\n",
+ " return false;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
+ " if (name == 'download') {\n",
+ " this.handle_save(this, null);\n",
+ " } else {\n",
+ " this.send_message(\"toolbar_button\", {name: name});\n",
+ " }\n",
+ "};\n",
+ "\n",
+ "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
+ " this.message.textContent = tooltip;\n",
+ "};\n",
+ "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
+ "\n",
+ "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
+ "\n",
+ "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
+ " // Create a \"websocket\"-like object which calls the given IPython comm\n",
+ " // object with the appropriate methods. Currently this is a non binary\n",
+ " // socket, so there is still some room for performance tuning.\n",
+ " var ws = {};\n",
+ "\n",
+ " ws.close = function() {\n",
+ " comm.close()\n",
+ " };\n",
+ " ws.send = function(m) {\n",
+ " //console.log('sending', m);\n",
+ " comm.send(m);\n",
+ " };\n",
+ " // Register the callback with on_msg.\n",
+ " comm.on_msg(function(msg) {\n",
+ " //console.log('receiving', msg['content']['data'], msg);\n",
+ " // Pass the mpl event to the overriden (by mpl) onmessage function.\n",
+ " ws.onmessage(msg['content']['data'])\n",
+ " });\n",
+ " return ws;\n",
+ "}\n",
+ "\n",
+ "mpl.mpl_figure_comm = function(comm, msg) {\n",
+ " // This is the function which gets called when the mpl process\n",
+ " // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
+ "\n",
+ " var id = msg.content.data.id;\n",
+ " // Get hold of the div created by the display call when the Comm\n",
+ " // socket was opened in Python.\n",
+ " var element = $(\"#\" + id);\n",
+ " var ws_proxy = comm_websocket_adapter(comm)\n",
+ "\n",
+ " function ondownload(figure, format) {\n",
+ " window.open(figure.imageObj.src);\n",
+ " }\n",
+ "\n",
+ " var fig = new mpl.figure(id, ws_proxy,\n",
+ " ondownload,\n",
+ " element.get(0));\n",
+ "\n",
+ " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
+ " // web socket which is closed, not our websocket->open comm proxy.\n",
+ " ws_proxy.onopen();\n",
+ "\n",
+ " fig.parent_element = element.get(0);\n",
+ " fig.cell_info = mpl.find_output_cell(\"\");\n",
+ " if (!fig.cell_info) {\n",
+ " console.error(\"Failed to find cell for figure\", id, fig);\n",
+ " return;\n",
+ " }\n",
+ "\n",
+ " var output_index = fig.cell_info[2]\n",
+ " var cell = fig.cell_info[0];\n",
+ "\n",
+ "};\n",
+ "\n",
+ "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
+ " var width = fig.canvas.width/mpl.ratio\n",
+ " fig.root.unbind('remove')\n",
+ "\n",
+ " // Update the output cell to use the data from the current canvas.\n",
+ " fig.push_to_output();\n",
+ " var dataURL = fig.canvas.toDataURL();\n",
+ " // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
+ " // the notebook keyboard shortcuts fail.\n",
+ " IPython.keyboard_manager.enable()\n",
+ " $(fig.parent_element).html('
');\n",
+ " fig.close_ws(fig, msg);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.close_ws = function(fig, msg){\n",
+ " fig.send_message('closing', msg);\n",
+ " // fig.ws.close()\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
+ " // Turn the data on the canvas into data in the output cell.\n",
+ " var width = this.canvas.width/mpl.ratio\n",
+ " var dataURL = this.canvas.toDataURL();\n",
+ " this.cell_info[1]['text/html'] = '
';\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.updated_canvas_event = function() {\n",
+ " // Tell IPython that the notebook contents must change.\n",
+ " IPython.notebook.set_dirty(true);\n",
+ " this.send_message(\"ack\", {});\n",
+ " var fig = this;\n",
+ " // Wait a second, then push the new image to the DOM so\n",
+ " // that it is saved nicely (might be nice to debounce this).\n",
+ " setTimeout(function () { fig.push_to_output() }, 1000);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_toolbar = function() {\n",
+ " var fig = this;\n",
+ "\n",
+ " var nav_element = $('')\n",
+ " nav_element.attr('style', 'width: 100%');\n",
+ " this.root.append(nav_element);\n",
+ "\n",
+ " // Define a callback function for later on.\n",
+ " function toolbar_event(event) {\n",
+ " return fig.toolbar_button_onclick(event['data']);\n",
+ " }\n",
+ " function toolbar_mouse_event(event) {\n",
+ " return fig.toolbar_button_onmouseover(event['data']);\n",
+ " }\n",
+ "\n",
+ " for(var toolbar_ind in mpl.toolbar_items){\n",
+ " var name = mpl.toolbar_items[toolbar_ind][0];\n",
+ " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
+ " var image = mpl.toolbar_items[toolbar_ind][2];\n",
+ " var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
+ "\n",
+ " if (!name) { continue; };\n",
+ "\n",
+ " var button = $('');\n",
+ " button.click(method_name, toolbar_event);\n",
+ " button.mouseover(tooltip, toolbar_mouse_event);\n",
+ " nav_element.append(button);\n",
+ " }\n",
+ "\n",
+ " // Add the status bar.\n",
+ " var status_bar = $('');\n",
+ " nav_element.append(status_bar);\n",
+ " this.message = status_bar[0];\n",
+ "\n",
+ " // Add the close button to the window.\n",
+ " var buttongrp = $('');\n",
+ " var button = $('');\n",
+ " button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
+ " button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
+ " buttongrp.append(button);\n",
+ " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
+ " titlebar.prepend(buttongrp);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._root_extra_style = function(el){\n",
+ " var fig = this\n",
+ " el.on(\"remove\", function(){\n",
+ "\tfig.close_ws(fig, {});\n",
+ " });\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._canvas_extra_style = function(el){\n",
+ " // this is important to make the div 'focusable\n",
+ " el.attr('tabindex', 0)\n",
+ " // reach out to IPython and tell the keyboard manager to turn it's self\n",
+ " // off when our div gets focus\n",
+ "\n",
+ " // location in version 3\n",
+ " if (IPython.notebook.keyboard_manager) {\n",
+ " IPython.notebook.keyboard_manager.register_events(el);\n",
+ " }\n",
+ " else {\n",
+ " // location in version 2\n",
+ " IPython.keyboard_manager.register_events(el);\n",
+ " }\n",
+ "\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
+ " var manager = IPython.notebook.keyboard_manager;\n",
+ " if (!manager)\n",
+ " manager = IPython.keyboard_manager;\n",
+ "\n",
+ " // Check for shift+enter\n",
+ " if (event.shiftKey && event.which == 13) {\n",
+ " this.canvas_div.blur();\n",
+ " // select the cell after this one\n",
+ " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n",
+ " IPython.notebook.select(index + 1);\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
+ " fig.ondownload(fig, null);\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.find_output_cell = function(html_output) {\n",
+ " // Return the cell and output element which can be found *uniquely* in the notebook.\n",
+ " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
+ " // IPython event is triggered only after the cells have been serialised, which for\n",
+ " // our purposes (turning an active figure into a static one), is too late.\n",
+ " var cells = IPython.notebook.get_cells();\n",
+ " var ncells = cells.length;\n",
+ " for (var i=0; i= 3 moved mimebundle to data attribute of output\n",
+ " data = data.data;\n",
+ " }\n",
+ " if (data['text/html'] == html_output) {\n",
+ " return [cell, data, j];\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "// Register the function which deals with the matplotlib target/channel.\n",
+ "// The kernel may be null if the page has been refreshed.\n",
+ "if (IPython.notebook.kernel != null) {\n",
+ " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
+ "}\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "
"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"fig, ax = plt.subplots(figsize=(20, 20))\n",
"for idx in range(viz_stocks):\n",
@@ -1279,7 +2356,9 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
- "collapsed": true
+ "collapsed": true,
+ "deletable": true,
+ "editable": true
},
"outputs": [],
"source": []
@@ -1301,7 +2380,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.0"
+ "version": "3.5.3"
}
},
"nbformat": 4,