Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ docs/_build/

# PyBuilder
target/

#ipython notebook
.ipynb_checkpoints/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ Theano-Tutorials
================

Bare bones introduction to machine learning from linear regression to convolutional neural networks using Theano.

See [ipython notebooks](http://nbviewer.ipython.org/github/udibr/Theano-Tutorials/blob/master/notebooks/index.ipynb)

10 changes: 5 additions & 5 deletions load.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def one_hot(x,n):

def mnist(ntrain=60000,ntest=10000,onehot=True):
data_dir = os.path.join(datasets_dir,'mnist/')
fd = open(os.path.join(data_dir,'train-images.idx3-ubyte'))
fd = open(os.path.join(data_dir,'train-images-idx3-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
trX = loaded[16:].reshape((60000,28*28)).astype(float)

fd = open(os.path.join(data_dir,'train-labels.idx1-ubyte'))
fd = open(os.path.join(data_dir,'train-labels-idx1-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
trY = loaded[8:].reshape((60000))

fd = open(os.path.join(data_dir,'t10k-images.idx3-ubyte'))
fd = open(os.path.join(data_dir,'t10k-images-idx3-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
teX = loaded[16:].reshape((10000,28*28)).astype(float)

fd = open(os.path.join(data_dir,'t10k-labels.idx1-ubyte'))
fd = open(os.path.join(data_dir,'t10k-labels-idx1-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
teY = loaded[8:].reshape((10000))

Expand All @@ -45,4 +45,4 @@ def mnist(ntrain=60000,ntest=10000,onehot=True):
trY = np.asarray(trY)
teY = np.asarray(teY)

return trX,teX,trY,teY
return trX,teX,trY,teY
146 changes: 146 additions & 0 deletions notebooks/0_multiply.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"metadata": {
"name": "",
"signature": "sha256:f13eb3b414e3e34aa7531d120d38fcd6602672de65630585a7952395a63c3f7e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Theano Basics\n",
"-------------"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`theano.tensor` is the module that deals most directly with the manipulation of data."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import theano\n",
"from theano import tensor as T"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Instation of Theano symbolic variables is simple."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a = T.scalar()\n",
"b = T.scalar()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Relationships between variables are defined in a functional manner."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"y = a * b"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can then compile to an input/output mapping to a python function (executed on the CPU or GPU depending on configuration). "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"multiply = theano.function(inputs=[a, b], outputs=y)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, you can call the function as normal."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"multiply(1, 2)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'multiply' is not defined",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-2c7a8e9cf618>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmultiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'multiply' is not defined"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"multiply(3, 3)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
"array(9.0)"
]
}
],
"prompt_number": 6
}
],
"metadata": {}
}
]
}
Loading