From 30613a0b685df18b2a445b060547e4a208696026 Mon Sep 17 00:00:00 2001 From: Jon Perl Date: Fri, 26 May 2017 16:47:21 -0400 Subject: [PATCH] Push latest run - Run again on floydhub with smaller embedding dimensions --- stock2vec.ipynb | 1169 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 1124 insertions(+), 45 deletions(-) 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 = $('