comparison datasets/MNIST.py @ 470:bd937e845bbb

new stuff: algorithms/logistic_regression, datasets/MNIST
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 22 Oct 2008 15:56:53 -0400
parents
children 45b3eb429c15
comparison
equal deleted inserted replaced
469:4335309f4924 470:bd937e845bbb
1 """
2 Various routines to load/access MNIST data.
3 """
4 from __future__ import absolute_import
5
6 import numpy
7
8 from ..amat import AMat
9
10 default_path = '/u/bergstrj/pub/data/mnist.amat'
11 """the location of a file containing mnist data in .amat format"""
12
13
14 def head(n=10, path=None):
15 """Load the first MNIST examples.
16
17 Returns two matrices: x, y. x has N rows of 784 columns. Each row of x represents the
18 28x28 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
19 is the label of the i'th row of x.
20
21 """
22 path = path if path is not None else default_path
23
24 dat = AMat(path=path, head=n)
25
26 return dat.input, numpy.asarray(dat.target, dtype='int64').reshape(dat.target.shape[0])
27
28 def all(path=None):
29 return head(n=None, path=path)
30
31