1
0
mirror of https://github.com/bspeice/ecbm4040 synced 2024-12-04 13:08:13 -05:00

Add Homework 0 files

This commit is contained in:
Bradlee Speice 2016-09-18 21:04:21 -04:00
commit 825b0c0327
5 changed files with 1234 additions and 0 deletions

View File

@ -0,0 +1,192 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=gpu python DeepLearningTutorials/code/logistic_sgd.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=gpu python DeepLearningTutorials/code/convolutional_mlp.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=cpu python DeepLearningTutorials/code/logistic_sgd.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=cpu timeout 1200 python DeepLearningTutorials/code/convolutional_mlp.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import theano.tensor as T\n",
"from theano.tensor.shared_randomstreams import RandomStreams\n",
"from theano import function, shared\n",
"from theano.compile.sharedvalue import SharedVariable\n",
"import numpy as np\n",
"\n",
"srng = RandomStreams(seed=1234)\n",
"\n",
"x = T.fcol()\n",
"a = srng.uniform((10, 1))\n",
"a_shared = SharedVariable(\n",
" value=np.zeros((10, 1)),\n",
" type=a.type,\n",
" name='a',\n",
" strict=True\n",
")\n",
"\n",
"b = srng.uniform((10, 1))\n",
"b_shared = SharedVariable(\n",
" value=np.zeros((10, 1)),\n",
" type=b.type,\n",
" name='b',\n",
" strict=True\n",
")\n",
"\n",
"z = (x + a).T.dot(b)\n",
"f = function([x], z, updates=[(a_shared, a), (b_shared, b)], allow_input_downcast=True)\n",
"\n",
"f(np.ones((10, 1)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"a_shared.get_value()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"b_shared.get_value()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"(np.ones((10, 1)) + a_shared.get_value()).T.dot(b_shared.get_value())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def fib(n):\n",
" if n <= 1:\n",
" return 0\n",
" elif n == 2:\n",
" return 1\n",
" else:\n",
" a = shared(0)\n",
" b = shared(1)\n",
" f = function([], a + b, updates=[(b, a + b), (a, b)])\n",
" for i in range(1, n):\n",
" f()\n",
" \n",
" return b.get_value()\n",
" \n",
"print('fib(10): {}'.format(fib(10)))\n",
"print('fib(20): {}'.format(fib(20)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

@ -0,0 +1 @@
Subproject commit e64a8fcc096f434f6ab2ba5ab26868a877ad5402

Binary file not shown.

192
Homework 0/Homework 0.ipynb Normal file
View File

@ -0,0 +1,192 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=gpu python DeepLearningTutorials/code/logistic_sgd.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=gpu python DeepLearningTutorials/code/convolutional_mlp.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=cpu python DeepLearningTutorials/code/logistic_sgd.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=cpu timeout 1200 python DeepLearningTutorials/code/convolutional_mlp.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import theano.tensor as T\n",
"from theano.tensor.shared_randomstreams import RandomStreams\n",
"from theano import function, shared\n",
"from theano.compile.sharedvalue import SharedVariable\n",
"import numpy as np\n",
"\n",
"srng = RandomStreams(seed=1234)\n",
"\n",
"x = T.fcol()\n",
"a = srng.uniform((10, 1))\n",
"a_shared = SharedVariable(\n",
" value=np.zeros((10, 1)),\n",
" type=a.type,\n",
" name='a',\n",
" strict=True\n",
")\n",
"\n",
"b = srng.uniform((10, 1))\n",
"b_shared = SharedVariable(\n",
" value=np.zeros((10, 1)),\n",
" type=b.type,\n",
" name='b',\n",
" strict=True\n",
")\n",
"\n",
"z = (x + a).T.dot(b)\n",
"f = function([x], z, updates=[(a_shared, a), (b_shared, b)], allow_input_downcast=True)\n",
"\n",
"f(np.ones((10, 1)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"a_shared.get_value()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"b_shared.get_value()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"(np.ones((10, 1)) + a_shared.get_value()).T.dot(b_shared.get_value())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def fib(n):\n",
" if n <= 1:\n",
" return 0\n",
" elif n == 2:\n",
" return 1\n",
" else:\n",
" a = shared(0)\n",
" b = shared(1)\n",
" f = function([], a + b, updates=[(b, a + b), (a, b)])\n",
" for i in range(1, n):\n",
" f()\n",
" \n",
" return b.get_value()\n",
" \n",
"print('fib(10): {}'.format(fib(10)))\n",
"print('fib(20): {}'.format(fib(20)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

849
Homework 0/best_model.pkl Normal file

File diff suppressed because one or more lines are too long