annotate datasets/shapeset1.py @ 528:cfe3f62a08cb

bugfix, outputs needed to be in a list in the past, not anymore.
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 17 Nov 2008 13:17:00 -0500
parents 6fe692b93b69
children
rev   line source
509
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
1 """
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
2 Routines to load/access Shapeset1
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
3 """
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
4
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
5 from __future__ import absolute_import
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
6
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
7 import os
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
8 import numpy
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
9
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
10 from ..amat import AMat
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
11 from .config import data_root
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
12
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
13 def _head(path, n):
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
14 dat = AMat(path=path, head=n)
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
15
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
16 try:
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
17 assert dat.input.shape[0] == n
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
18 assert dat.target.shape[0] == n
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
19 except Exception , e:
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
20 raise Exception("failed to read %i lines from file %s" % (n, path))
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
21
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
22 return dat.input, numpy.asarray(dat.target, dtype='int64').reshape(dat.target.shape[0])
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
23
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
24
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
25 def head_train(n=10000):
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
26 """Load the first Shapeset1 training examples.
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
27
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
28 Returns two matrices: x, y. x has N rows of 1024 columns. Each row of x represents the
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
29 32x32 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
30 is the label of the i'th row of x.
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
31
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
32 """
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
33 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.10000.train.shape.amat')
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
34 return _head(path, n)
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
35
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
36 def head_valid(n=5000):
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
37 """Load the first Shapeset1 validation examples.
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
38
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
39 Returns two matrices: x, y. x has N rows of 1024 columns. Each row of x represents the
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
40 32x32 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
41 is the label of the i'th row of x.
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
42
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
43 """
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
44 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.5000.valid.shape.amat')
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
45 return _head(path, n)
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
46
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
47 def head_test(n=5000):
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
48 """Load the first Shapeset1 testing examples.
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
49
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
50 Returns two matrices: x, y. x has N rows of 1024 columns. Each row of x represents the
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
51 32x32 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
52 is the label of the i'th row of x.
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
53
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
54 """
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
55 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.5000.test.shape.amat')
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
56 return _head(path, n)
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
57
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
58 def train_valid_test(ntrain=10000, nvalid=5000, ntest=5000):
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
59 return head_train(n=ntrain), head_valid(n=nvalid), head_test(n=ntest)
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
60
6fe692b93b69 added shapeset1
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
61