| { |
| "cells": [ |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "# Autoencoder\n", |
| "This notebook demonstrates the invocation of the SystemML autoencoder script, and alternative ways of passing in/out data." |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "### This notebook is supported with SystemML 0.14.0 and above." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "!pip show systemml" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "import pandas as pd\n", |
| "from systemml import MLContext, dml\n", |
| "ml = MLContext(sc)\n", |
| "print(ml.info())\n", |
| "sc.version" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## SystemML Read/Write data from local file system" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "FsPath = \"/tmp/data/\"\n", |
| "inp = FsPath + \"Input/\"\n", |
| "outp = FsPath + \"Output/\"" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "Generate Data and write out to file." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "import numpy as np\n", |
| "X_pd = pd.DataFrame(np.arange(1,2001, dtype=np.float)).values.reshape(100,20)\n", |
| "# X_pd = pd.DataFrame(range(1, 2001,1),dtype=float).values.reshape(100,20)\n", |
| "script =\"\"\"\n", |
| " write(X, $Xfile)\n", |
| "\"\"\"\n", |
| "prog = dml(script).input(X=X_pd).input(**{\"$Xfile\":inp+\"X.csv\"})\n", |
| "ml.execute(prog)" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "!ls -l /tmp/data/Input" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "autoencoderURL = \"https://raw.githubusercontent.com/apache/systemml/master/scripts/staging/autoencoder-2layer.dml\"\n", |
| "rets = (\"iter\", \"num_iters_per_epoch\", \"beg\", \"end\", \"o\")\n", |
| "\n", |
| "prog = dml(autoencoderURL).input(**{\"$X\":inp+\"X.csv\"}) \\\n", |
| " .input(**{\"$H1\":500, \"$H2\":2, \"$BATCH\":36, \"$EPOCH\":5 \\\n", |
| " , \"$W1_out\":outp+\"W1_out\", \"$b1_out\":outp+\"b1_out\" \\\n", |
| " , \"$W2_out\":outp+\"W2_out\", \"$b2_out\":outp+\"b2_out\" \\\n", |
| " , \"$W3_out\":outp+\"W3_out\", \"$b3_out\":outp+\"b3_out\" \\\n", |
| " , \"$W4_out\":outp+\"W4_out\", \"$b4_out\":outp+\"b4_out\" \\\n", |
| " }).output(*rets)\n", |
| "iter, num_iters_per_epoch, beg, end, o = ml.execute(prog).get(*rets)\n", |
| "print (iter, num_iters_per_epoch, beg, end, o)" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true |
| }, |
| "outputs": [], |
| "source": [ |
| "!ls -l /tmp/data/Output" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "metadata": {}, |
| "source": [ |
| "## Alternatively to passing in/out file names, use Python variables." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "metadata": { |
| "collapsed": true, |
| "scrolled": true |
| }, |
| "outputs": [], |
| "source": [ |
| "autoencoderURL = \"https://raw.githubusercontent.com/apache/systemml/master/scripts/staging/autoencoder-2layer.dml\"\n", |
| "rets = (\"iter\", \"num_iters_per_epoch\", \"beg\", \"end\", \"o\")\n", |
| "rets2 = (\"W1\", \"b1\", \"W2\", \"b2\", \"W3\", \"b3\", \"W4\", \"b4\")\n", |
| "\n", |
| "prog = dml(autoencoderURL).input(X=X_pd) \\\n", |
| " .input(**{ \"$H1\":500, \"$H2\":2, \"$BATCH\":36, \"$EPOCH\":5}) \\\n", |
| " .output(*rets) \\\n", |
| " .output(*rets2)\n", |
| "result = ml.execute(prog)\n", |
| "iter, num_iters_per_epoch, beg, end, o = result.get(*rets)\n", |
| "W1, b1, W2, b2, W3, b3, W4, b4 = result.get(*rets2)\n", |
| "\n", |
| "print (iter, num_iters_per_epoch, beg, end, o)" |
| ] |
| } |
| ], |
| "metadata": { |
| "kernelspec": { |
| "display_name": "Python 2", |
| "language": "python", |
| "name": "python2" |
| }, |
| "language_info": { |
| "codemirror_mode": { |
| "name": "ipython", |
| "version": 2 |
| }, |
| "file_extension": ".py", |
| "mimetype": "text/x-python", |
| "name": "python", |
| "nbconvert_exporter": "python", |
| "pygments_lexer": "ipython2", |
| "version": "2.7.13" |
| } |
| }, |
| "nbformat": 4, |
| "nbformat_minor": 1 |
| } |