Merge pull request #14 from pswietojanski/master
fixed typos, added some more comments, bugfixes
This commit is contained in:
commit
bab884b8ee
File diff suppressed because one or more lines are too long
@ -22,7 +22,7 @@
|
||||
"\n",
|
||||
"## On Synchronising repositories\n",
|
||||
"\n",
|
||||
"Enter the git mlp repository you set up last week (i.e. `~/mlpractical/repo-mlp`) and once you sync the repository (in one of the two below ways), start the notebook session by typing:\n",
|
||||
"Enter the git mlp repository you set up last week (i.e. `~/mlpractical/repo-mlp`) and once you sync the repository (in one of the two below ways, or look at our short Git FAQ <a href=\"https://github.com/CSTR-Edinburgh/mlpractical/blob/master/gitFAQ.md\">here</a>), start the notebook session by typing:\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"ipython notebook\n",
|
||||
@ -35,7 +35,9 @@
|
||||
"1. `git stash save \"Lab1 work\"`\n",
|
||||
"2. `git pull`\n",
|
||||
"\n",
|
||||
"Then, if you need to, you can always (temporaily) restore a desired state of the repository.\n",
|
||||
"Then, if you need to, you can always (temporaily) restore a desired state of the repository (look <a href=\"https://github.com/CSTR-Edinburgh/mlpractical/blob/master/gitFAQ.md\">here</a>).\n",
|
||||
"\n",
|
||||
"**Otherwise** you may also create a branch for each lab separately (again, look at <a href=\"https://github.com/CSTR-Edinburgh/mlpractical/blob/master/gitFAQ.md\">here</a> and git tutorials we linked there), this will allow you to keep `master` branch clean, and pull changes into it every week from the central repository. At the same time branching gives you much more flexibility with changes you introduce to the code as potential conflicts will not occur until you try to make an explicit merge (which you probably .\n",
|
||||
"\n",
|
||||
"### For advanced github users\n",
|
||||
"\n",
|
||||
@ -93,7 +95,7 @@
|
||||
"w_{21} & w_{22} & w_{23} \\\\\n",
|
||||
"w_{31} & w_{32} & w_{33} \\\\\n",
|
||||
"w_{41} & w_{42} & w_{43} \\\\\n",
|
||||
"w_{51} & x_{52} & 2_{53} \\\\ \\end{array} \\right]$, bias vector $\\mathbf{b} = (b_1, b_2, b_3)$ and outputs $\\mathbf{y} = (y_1, y_2, y_3)$, one can write the transformation as follows:\n",
|
||||
"w_{51} & w_{52} & w_{53} \\\\ \\end{array} \\right]$, bias vector $\\mathbf{b} = (b_1, b_2, b_3)$ and outputs $\\mathbf{y} = (y_1, y_2, y_3)$, one can write the transformation as follows:\n",
|
||||
"\n",
|
||||
"(for the $i$-th output)\n",
|
||||
"\n",
|
||||
@ -103,7 +105,7 @@
|
||||
"\\end{equation}\n",
|
||||
"$\n",
|
||||
"\n",
|
||||
"or the equivalent vector form (where $\\mathbf w_i$ is the $i$-th column of $\\mathbf W$):\n",
|
||||
"or the equivalent vector form (where $\\mathbf w_i$ is the $i$-th column of $\\mathbf W$, but note, when we **slice** the $i$th column we will get a **vector** $\\mathbf w_i = (w_{1i}, w_{2i}, w_{3i}, w_{4i}, w_{5i})$, hence the transpose for $\\mathbf w_i$ in the below equation):\n",
|
||||
"\n",
|
||||
"(2) $\n",
|
||||
"\\begin{equation}\n",
|
||||
@ -237,7 +239,7 @@
|
||||
"source": [
|
||||
"## Exercise 2\n",
|
||||
"\n",
|
||||
"Modify the examples from Exercise 1 to perform **backward** propagation, that is, given $\\mathbf{y}$ (obtained in the previous step) and weight matrix $\\mathbf{W}$, project $\\mathbf{y}$ onto the input space $\\mathbf{x}$ (ignore or set to zero the biases towards $\\mathbf{x}$ in backward pass). Mathematically, we are interested in the following transformation: $\\mathbf{z}=\\mathbf{y}\\mathbf{W}^T$"
|
||||
"Modify the examples from Exercise 1 to perform **backward** propagation, that is, given $\\mathbf{y}$ (obtained in the previous step) and weight matrix $\\mathbf{W}$, project $\\mathbf{y}$ onto the input space $\\mathbf{x}$ (ignore or set to zero the biases towards $\\mathbf{x}$ in backward pass, and note, we are **not** trying to reconstruct the original $\\mathbf{x}$). Mathematically, we are interested in the following transformation: $\\mathbf{z}=\\mathbf{y}\\mathbf{W}^T$"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -6,6 +6,10 @@ import cPickle
|
||||
import gzip
|
||||
import numpy
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DataProvider(object):
|
||||
@ -65,6 +69,7 @@ class MNISTDataProvider(DataProvider):
|
||||
def __init__(self, dset,
|
||||
batch_size=10,
|
||||
max_num_batches=-1,
|
||||
max_num_examples=-1,
|
||||
randomize=True):
|
||||
|
||||
super(MNISTDataProvider, self).\
|
||||
@ -78,6 +83,11 @@ class MNISTDataProvider(DataProvider):
|
||||
assert max_num_batches != 0, (
|
||||
"max_num_batches should be != 0"
|
||||
)
|
||||
|
||||
if max_num_batches > 0 and max_num_examples > 0:
|
||||
logger.warning("You have specified both 'max_num_batches' and " \
|
||||
"a deprecead 'max_num_examples' arguments. We will " \
|
||||
"use the former over the latter.")
|
||||
|
||||
dset_path = './data/mnist_%s.pkl.gz' % dset
|
||||
assert os.path.isfile(dset_path), (
|
||||
@ -88,6 +98,11 @@ class MNISTDataProvider(DataProvider):
|
||||
x, t = cPickle.load(f)
|
||||
|
||||
self._max_num_batches = max_num_batches
|
||||
#max_num_examples arg was provided for backward compatibility
|
||||
#but it maps us to the max_num_batches anyway
|
||||
if max_num_examples > 0 and max_num_batches < 0:
|
||||
self._max_num_batches = max_num_examples / self.batch_size
|
||||
|
||||
self.x = x
|
||||
self.t = t
|
||||
self.num_classes = 10
|
||||
@ -106,9 +121,9 @@ class MNISTDataProvider(DataProvider):
|
||||
return numpy.random.permutation(numpy.arange(0, self.x.shape[0]))
|
||||
|
||||
def next(self):
|
||||
|
||||
|
||||
has_enough = (self._curr_idx + self.batch_size) <= self.x.shape[0]
|
||||
presented_max = (0 < self._max_num_batches < (self._curr_idx / self.batch_size))
|
||||
presented_max = (0 < self._max_num_batches <= (self._curr_idx / self.batch_size))
|
||||
|
||||
if not has_enough or presented_max:
|
||||
raise StopIteration()
|
||||
@ -142,6 +157,7 @@ class MetOfficeDataProvider(DataProvider):
|
||||
def __init__(self, window_size,
|
||||
batch_size=10,
|
||||
max_num_batches=-1,
|
||||
max_num_examples=-1,
|
||||
randomize=True):
|
||||
|
||||
super(MetOfficeDataProvider, self).\
|
||||
@ -152,10 +168,20 @@ class MetOfficeDataProvider(DataProvider):
|
||||
"File %s was expected to exist!." % dset_path
|
||||
)
|
||||
|
||||
if max_num_batches > 0 and max_num_examples > 0:
|
||||
logger.warning("You have specified both 'max_num_batches' and " \
|
||||
"a deprecead 'max_num_examples' arguments. We will " \
|
||||
"use the former over the latter.")
|
||||
|
||||
raw = numpy.loadtxt(dset_path, skiprows=3, usecols=range(2, 32))
|
||||
|
||||
self.window_size = window_size
|
||||
self._max_num_batches = max_num_batches
|
||||
#max_num_examples arg was provided for backward compatibility
|
||||
#but it maps us to the max_num_batches anyway
|
||||
if max_num_examples > 0 and max_num_batches < 0:
|
||||
self._max_num_batches = max_num_examples / self.batch_size
|
||||
|
||||
#filter out all missing datapoints and
|
||||
#flatten a matrix to a vector, so we will get
|
||||
#a time preserving representation of measurments
|
||||
@ -190,9 +216,9 @@ class MetOfficeDataProvider(DataProvider):
|
||||
return numpy.random.permutation(numpy.arange(self.window_size, self.x.shape[0]))
|
||||
|
||||
def next(self):
|
||||
|
||||
has_enough = (self._curr_idx + self.batch_size) <= self.x.shape[0]
|
||||
presented_max = (0 < self._max_num_batches < (self._curr_idx / self.batch_size))
|
||||
|
||||
has_enough = (self.window_size + self._curr_idx + self.batch_size) <= self.x.shape[0]
|
||||
presented_max = (0 < self._max_num_batches <= (self._curr_idx / self.batch_size))
|
||||
|
||||
if not has_enough or presented_max:
|
||||
raise StopIteration()
|
||||
@ -202,7 +228,8 @@ class MetOfficeDataProvider(DataProvider):
|
||||
self._rand_idx[self._curr_idx:self._curr_idx + self.batch_size]
|
||||
else:
|
||||
range_idx = \
|
||||
numpy.arange(self._curr_idx, self._curr_idx + self.batch_size)
|
||||
numpy.arange(self.window_size + self._curr_idx,
|
||||
self.window_size + self._curr_idx + self.batch_size)
|
||||
|
||||
#build slicing matrix of size minibatch, which will contain batch_size
|
||||
#rows, each keeping indexes that selects windows_size+1 [for (x,t)] elements
|
||||
@ -215,7 +242,7 @@ class MetOfficeDataProvider(DataProvider):
|
||||
range_idx[i] - self.window_size - 1,
|
||||
-1,
|
||||
dtype=numpy.int32)[::-1]
|
||||
|
||||
|
||||
#here we use advanced indexing to select slices from observation vector
|
||||
#last column of rval_x makes our targets t (as we splice window_size + 1
|
||||
tmp_x = self.x[range_slices]
|
||||
|
Loading…
Reference in New Issue
Block a user