annotate _test_dataset.py @ 298:5987415496df

better testing of the MultiLengthDataSet, now called exotic1
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Fri, 06 Jun 2008 17:55:14 -0400
parents d08b71d186c8
children eded3cb54930
rev   line source
51
59757365a057 the script can be autorun
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 45
diff changeset
1 #!/bin/env python
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
2 from dataset import *
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
3 from math import *
289
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
4 import numpy, unittest, sys
229
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 202
diff changeset
5 from misc import *
298
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
6 from lookup_list import LookupList
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
7
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
8 def have_raised(to_eval, **var):
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
9 have_thrown = False
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
10 try:
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
11 eval(to_eval)
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
12 except :
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
13 have_thrown = True
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
14 return have_thrown
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
15
173
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
16 def have_raised2(f, *args, **kwargs):
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
17 have_thrown = False
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
18 try:
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
19 f(*args, **kwargs)
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
20 except :
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
21 have_thrown = True
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
22 return have_thrown
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
23
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
24 def test1():
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
25 print "test1"
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
26 global a,ds
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
27 a = numpy.random.rand(10,4)
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
28 print a
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
29 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
30 print "len(ds)=",len(ds)
54
70147d00615a added assert
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 52
diff changeset
31 assert(len(ds)==10)
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
32 print "example 0 = ",ds[0]
54
70147d00615a added assert
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 52
diff changeset
33 # assert
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
34 print "x=",ds["x"]
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
35 print "x|y"
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
36 for x,y in ds("x","y"):
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
37 print x,y
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
38 minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4)
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
39 minibatch = minibatch_iterator.__iter__().next()
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
40 print "minibatch=",minibatch
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
41 for var in minibatch:
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
42 print "var=",var
48
b6730f9a336d Fixing MinibatchDataSet getitem
bengioy@grenat.iro.umontreal.ca
parents: 45
diff changeset
43 print "take a slice and look at field y",ds[1:6:2]["y"]
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
44
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
45 del a,ds,x,y,minibatch_iterator,minibatch,var
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
46
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
47 def test_iterate_over_examples(array,ds):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
48 #not in doc!!!
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
49 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
50 for example in range(len(ds)):
293
4bfdda107a17 still merging
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 292
diff changeset
51 wanted = array[example][:3]
4bfdda107a17 still merging
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 292
diff changeset
52 returned = ds[example]['x']
4bfdda107a17 still merging
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 292
diff changeset
53 if (wanted != returned).all():
4bfdda107a17 still merging
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 292
diff changeset
54 print 'returned:', returned
4bfdda107a17 still merging
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 292
diff changeset
55 print 'wanted:', wanted
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
56 assert (ds[example]['x']==array[example][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
57 assert ds[example]['y']==array[example][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
58 assert (ds[example]['z']==array[example][[0,2]]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
59 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
60 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
61 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
62
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
63 # - for example in dataset:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
64 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
65 for example in ds:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
66 assert len(example)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
67 assert (example['x']==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
68 assert example['y']==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
69 assert (example['z']==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
70 assert (numpy.append(example['x'],example['y'])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
71 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
72 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
73 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
74
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
75 # - for val1,val2,... in dataset:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
76 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
77 for x,y,z in ds:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
78 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
79 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
80 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
81 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
82 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
83 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
84 del x,y,z,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
85
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
86 # - for example in dataset(field1, field2,field3, ...):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
87 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
88 for example in ds('x','y','z'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
89 assert len(example)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
90 assert (example['x']==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
91 assert example['y']==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
92 assert (example['z']==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
93 assert (numpy.append(example['x'],example['y'])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
94 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
95 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
96 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
97 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
98 for example in ds('y','x'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
99 assert len(example)==2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
100 assert (example['x']==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
101 assert example['y']==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
102 assert (numpy.append(example['x'],example['y'])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
103 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
104 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
105 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
106
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
107 # - for val1,val2,val3 in dataset(field1, field2,field3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
108 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
109 for x,y,z in ds('x','y','z'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
110 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
111 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
112 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
113 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
114 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
115 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
116 del x,y,z,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
117 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
118 for y,x in ds('y','x',):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
119 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
120 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
121 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
122 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
123 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
124 del x,y,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
125
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
126 def test_minibatch_size(minibatch,minibatch_size,len_ds,nb_field,nb_iter_finished):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
127 ##full minibatch or the last minibatch
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
128 for idx in range(nb_field):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
129 test_minibatch_field_size(minibatch[idx],minibatch_size,len_ds,nb_iter_finished)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
130 del idx
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
131 def test_minibatch_field_size(minibatch_field,minibatch_size,len_ds,nb_iter_finished):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
132 assert len(minibatch_field)==minibatch_size or ((nb_iter_finished*minibatch_size+len(minibatch_field))==len_ds and len(minibatch_field)<minibatch_size)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
133
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
134 # - for minibatch in dataset.minibatches([field1, field2, ...],minibatch_size=N):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
135 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
136 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
137 m=ds.minibatches(['x','z'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
138 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
139 for minibatch in m:
161
60e00cce3492 bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 158
diff changeset
140 assert isinstance(minibatch,DataSetFields)
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
141 assert len(minibatch)==2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
142 test_minibatch_size(minibatch,m.minibatch_size,len(ds),2,mi)
161
60e00cce3492 bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 158
diff changeset
143 if type(ds)==ArrayDataSet:
60e00cce3492 bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 158
diff changeset
144 assert (minibatch[0][:,::2]==minibatch[1]).all()
60e00cce3492 bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 158
diff changeset
145 else:
162
45427d4d64b3 bugfix in test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 161
diff changeset
146 for j in xrange(len(minibatch[0])):
45427d4d64b3 bugfix in test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 161
diff changeset
147 (minibatch[0][j][::2]==minibatch[1][j]).all()
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
148 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
149 i+=len(minibatch[0])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
150 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
151 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
152 del minibatch,i,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
153
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
154 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
155 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
156 m=ds.minibatches(['x','y'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
157 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
158 for minibatch in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
159 assert len(minibatch)==2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
160 test_minibatch_size(minibatch,m.minibatch_size,len(ds),2,mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
161 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
162 for id in range(len(minibatch[0])):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
163 assert (numpy.append(minibatch[0][id],minibatch[1][id])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
164 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
165 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
166 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
167 del minibatch,i,id,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
168
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
169 # - for mini1,mini2,mini3 in dataset.minibatches([field1, field2, field3], minibatch_size=N):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
170 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
171 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
172 m=ds.minibatches(['x','z'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
173 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
174 for x,z in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
175 test_minibatch_field_size(x,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
176 test_minibatch_field_size(z,m.minibatch_size,len(ds),mi)
164
3518710e16ec don't assume we have an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 162
diff changeset
177 for id in range(len(x)):
3518710e16ec don't assume we have an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 162
diff changeset
178 assert (x[id][::2]==z[id]).all()
3518710e16ec don't assume we have an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 162
diff changeset
179 i+=1
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
180 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
181 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
182 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
183 del x,z,i,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
184 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
185 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
186 m=ds.minibatches(['x','y'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
187 for x,y in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
188 test_minibatch_field_size(x,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
189 test_minibatch_field_size(y,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
190 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
191 for id in range(len(x)):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
192 assert (numpy.append(x[id],y[id])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
193 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
194 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
195 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
196 del x,y,i,id,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
197
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
198 #not in doc
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
199 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
200 m=ds.minibatches(['x','y'],n_batches=1,minibatch_size=3,offset=4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
201 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
202 for x,y in m:
239
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
203 assert len(x)==m.minibatch_size
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
204 assert len(y)==m.minibatch_size
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
205 for id in range(m.minibatch_size):
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
206 assert (numpy.append(x[id],y[id])==array[i+4]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
207 i+=1
239
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
208 assert i==m.n_batches*m.minibatch_size
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
209 del x,y,i,id,m
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
210
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
211 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
212 m=ds.minibatches(['x','y'],n_batches=2,minibatch_size=3,offset=4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
213 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
214 for x,y in m:
239
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
215 assert len(x)==m.minibatch_size
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
216 assert len(y)==m.minibatch_size
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
217 for id in range(m.minibatch_size):
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
218 assert (numpy.append(x[id],y[id])==array[i+4]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
219 i+=1
239
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
220 assert i==m.n_batches*m.minibatch_size
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
221 del x,y,i,id,m
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
222
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
223 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
224 m=ds.minibatches(['x','y'],n_batches=20,minibatch_size=3,offset=4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
225 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
226 for x,y in m:
239
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
227 assert len(x)==m.minibatch_size
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
228 assert len(y)==m.minibatch_size
77b362a23f8e more general test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 236
diff changeset
229 for id in range(m.minibatch_size):
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
230 assert (numpy.append(x[id],y[id])==array[(i+4)%array.shape[0]]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
231 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
232 assert i==m.n_batches*m.minibatch_size
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
233 del x,y,i,id
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
234
293
4bfdda107a17 still merging
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 292
diff changeset
235 assert not have_raised2(ds.minibatches,['x','y'],n_batches=1,minibatch_size=len(array)+1,offset=0)
240
97f35d586727 more test. Are we wanting to limit the size of minibatch to the size of the dataset?
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 239
diff changeset
236 assert not have_raised2(ds.minibatches,['x','y'],n_batches=1,minibatch_size=len(array),offset=0)
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
237
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
238 def test_ds_iterator(array,iterator1,iterator2,iterator3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
239 l=len(iterator1)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
240 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
241 for x,y in iterator1:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
242 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
243 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
244 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
245 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
246 assert i==l
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
247 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
248 for y,z in iterator2:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
249 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
250 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
251 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
252 assert i==l
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
253 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
254 for x,y,z in iterator3:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
255 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
256 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
257 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
258 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
259 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
260 assert i==l
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
261
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
262 def test_getitem(array,ds):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
263 def test_ds(orig,ds,index):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
264 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
265 assert len(ds)==len(index)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
266 for x,z,y in ds('x','z','y'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
267 assert (orig[index[i]]['x']==array[index[i]][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
268 assert (orig[index[i]]['x']==x).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
269 assert orig[index[i]]['y']==array[index[i]][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
270 assert orig[index[i]]['y']==y
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
271 assert (orig[index[i]]['z']==array[index[i]][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
272 assert (orig[index[i]]['z']==z).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
273 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
274 del i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
275 ds[0]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
276 if len(ds)>2:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
277 ds[:1]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
278 ds[1:1]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
279 ds[1:1:1]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
280 if len(ds)>5:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
281 ds[[1,2,3]]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
282 for x in ds:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
283 pass
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
284
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
285 #ds[:n] returns a dataset with the n first examples.
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
286 ds2=ds[:3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
287 assert isinstance(ds2,DataSet)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
288 test_ds(ds,ds2,index=[0,1,2])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
289 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
290
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
291 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s.
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
292 ds2=ds[1:7:2]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
293 assert isinstance(ds2,DataSet)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
294 test_ds(ds,ds2,[1,3,5])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
295 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
296
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
297 #ds[i]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
298 ds2=ds[5]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
299 assert isinstance(ds2,Example)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
300 assert have_raised("var['ds']["+str(len(ds))+"]",ds=ds) # index not defined
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
301 assert not have_raised("var['ds']["+str(len(ds)-1)+"]",ds=ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
302 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
303
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
304 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in.
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
305 ds2=ds[[4,7,2,8]]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
306 assert isinstance(ds2,DataSet)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
307 test_ds(ds,ds2,[4,7,2,8])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
308 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
309
269
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
310 #ds.<property># returns the value of a property associated with
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
311 #the name <property>. The following properties should be supported:
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
312 # - 'description': a textual description or name for the ds
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
313 # - 'fieldtypes': a list of types (one per field)
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
314
269
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
315 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#????
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
316 #assert hstack([ds('x','y'),ds('z')])==ds
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
317 #hstack([ds('z','y'),ds('x')])==ds
173
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
318 assert have_raised2(hstack,[ds('x'),ds('x')])
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
319 assert have_raised2(hstack,[ds('y','x'),ds('x')])
1255cd86df36 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 169
diff changeset
320 assert not have_raised2(hstack,[ds('x'),ds('y')])
269
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
321
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
322 # i=0
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
323 # for example in hstack([ds('x'),ds('y'),ds('z')]):
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
324 # example==ds[i]
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
325 # i+=1
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
326 # del i,example
fdce496c3b56 deprecating __getitem__[fieldname] syntax
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 268
diff changeset
327 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#????
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
328
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
329 def test_fields_fct(ds):
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
330 #@todo, fill correctly
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
331 assert len(ds.fields())==3
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
332 i=0
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
333 v=0
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
334 for field in ds.fields():
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
335 for field_value in field: # iterate over the values associated to that field for all the ds examples
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
336 v+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
337 i+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
338 assert i==3
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
339 assert v==3*10
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
340 del i,v
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
341
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
342 i=0
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
343 v=0
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
344 for field in ds('x','z').fields():
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
345 i+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
346 for val in field:
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
347 v+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
348 assert i==2
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
349 assert v==2*10
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
350 del i,v
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
351
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
352 i=0
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
353 v=0
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
354 for field in ds.fields('x','y'):
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
355 i+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
356 for val in field:
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
357 v+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
358 assert i==2
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
359 assert v==2*10
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
360 del i,v
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
361
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
362 i=0
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
363 v=0
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
364 for field_examples in ds.fields():
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
365 for example_value in field_examples:
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
366 v+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
367 i+=1
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
368 assert i==3
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
369 assert v==3*10
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
370 del i,v
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
371
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
372 assert ds == ds.fields().examples()
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
373 assert len(ds('x','y').fields()) == 2
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
374 assert len(ds('x','z').fields()) == 2
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
375 assert len(ds('y').fields()) == 1
165
2a12e7437c56 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 164
diff changeset
376
168
c704a66706fe more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 165
diff changeset
377 del field
194
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
378 def test_all(array,ds):
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
379 assert len(ds)==10
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
380
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
381 test_iterate_over_examples(array, ds)
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
382 test_getitem(array, ds)
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
383 test_ds_iterator(array,ds('x','y'),ds('y','z'),ds('x','y','z'))
0040ba0f0666 small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 173
diff changeset
384 test_fields_fct(ds)
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
385
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
386 class T_DataSet(unittest.TestCase):
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
387 def test_ArrayDataSet(self):
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
388 #don't test stream
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
389 #tested only with float value
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
390 #don't always test with y
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
391 #don't test missing value
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
392 #don't test with tuple
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
393 #don't test proterties
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
394 a2 = numpy.random.rand(10,4)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
395 ds = ArrayDataSet(a2,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested
292
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 221 284
diff changeset
396 ds = ArrayDataSet(a2,Example(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
397 #assert ds==a? should this work?
100
574f4db76022 restructuring and added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 96
diff changeset
398
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
399 test_all(a2,ds)
169
051e07807554 added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 168
diff changeset
400
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
401 del a2, ds
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
402
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
403 def test_CachedDataSet(self):
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
404 a = numpy.random.rand(10,4)
292
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 221 284
diff changeset
405 ds1 = ArrayDataSet(a,Example(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
406 ds2 = CachedDataSet(ds1)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
407 ds3 = CachedDataSet(ds1,cache_all_upon_construction=True)
148
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
408
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
409 test_all(a,ds2)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
410 test_all(a,ds3)
169
051e07807554 added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 168
diff changeset
411
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
412 del a,ds1,ds2,ds3
148
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
413
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
414
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
415 def test_DataSetFields(self):
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
416 raise NotImplementedError()
161
60e00cce3492 bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 158
diff changeset
417
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
418 def test_ApplyFunctionDataSet(self):
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
419 a = numpy.random.rand(10,4)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
420 a2 = a+1
292
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 221 284
diff changeset
421 ds1 = ArrayDataSet(a,Example(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested
202
b9950ae5e54b Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 195
diff changeset
422
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
423 ds2 = ApplyFunctionDataSet(ds1,lambda x,y,z: (x+1,y+1,z+1), ['x','y','z'],minibatch_mode=False)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
424 ds3 = ApplyFunctionDataSet(ds1,lambda x,y,z: (numpy.array(x)+1,numpy.array(y)+1,numpy.array(z)+1),
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
425 ['x','y','z'],
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
426 minibatch_mode=True)
202
b9950ae5e54b Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 195
diff changeset
427
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
428 test_all(a2,ds2)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
429 test_all(a2,ds3)
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
430
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
431 del a,ds1,ds2,ds3
202
b9950ae5e54b Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 195
diff changeset
432
279
2e22cc120688 passed test_dataset.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 278
diff changeset
433 def test_FieldsSubsetDataSet(self):
289
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
434 a = numpy.random.rand(10,4)
297
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 295
diff changeset
435 ds = ArrayDataSet(a,Example(['x','y','z','w'],[slice(3),3,[0,2],0]))
289
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
436 ds = FieldsSubsetDataSet(ds,['x','y','z'])
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
437
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
438 test_all(a,ds)
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
439
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
440 del a, ds
295
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
441
298
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
442 def test_MinibatchDataSet(self):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
443 raise NotImplementedError()
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
444 def test_HStackedDataSet(self):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
445 raise NotImplementedError()
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
446 def test_VStackedDataSet(self):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
447 raise NotImplementedError()
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
448 def test_ArrayFieldsDataSet(self):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
449 raise NotImplementedError()
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
450
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
451
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
452 class T_Exotic1(unittest.TestCase):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
453 class DataSet(DataSet):
295
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
454 """ Dummy dataset, where one field is a ndarray of variables size. """
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
455 def __len__(self) :
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
456 return 100
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
457 def fieldNames(self) :
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
458 return 'input','target','name'
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
459 def minibatches_nowrap(self,fieldnames,minibatch_size,n_batches,offset):
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
460 class MultiLengthDataSetIterator(object):
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
461 def __init__(self,dataset,fieldnames,minibatch_size,n_batches,offset):
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
462 if fieldnames is None: fieldnames = dataset.fieldNames()
297
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 295
diff changeset
463 self.minibatch = Example(fieldnames,range(len(fieldnames)))
295
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
464 self.dataset, self.minibatch_size, self.current = dataset, minibatch_size, offset
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
465 def __iter__(self):
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
466 return self
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
467 def next(self):
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
468 for k in self.minibatch._names :
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
469 self.minibatch[k] = []
298
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
470 for ex in range(self.minibatch_size) :
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
471 if 'input' in self.minibatch._names:
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
472 self.minibatch['input'].append( numpy.array( range(self.current + 1) ) )
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
473 if 'target' in self.minibatch._names:
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
474 self.minibatch['target'].append( self.current % 2 )
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
475 if 'name' in self.minibatch._names:
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
476 self.minibatch['name'].append( str(self.current) )
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
477 self.current += 1
295
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
478 return self.minibatch
7380376816e5 started a test for datasets where one field has a variable length. Not obvious, all tests requires a matrix as a reference
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 294
diff changeset
479 return MultiLengthDataSetIterator(self,fieldnames,minibatch_size,n_batches,offset)
298
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
480
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
481 def test_ApplyFunctionDataSet(self):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
482 ds = T_Exotic1.DataSet()
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
483 dsa = ApplyFunctionDataSet(ds,lambda x,y,z: ([x[-1]],[y*10],[int(z)]),['input','target','name'],minibatch_mode=False) #broken!!!!!!
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
484 for k in range(len(dsa)):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
485 res = dsa[k]
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
486 self.failUnless(ds[k]('input')[0][-1] == res('input')[0] , 'problem in first applied function')
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
487 res = dsa[33:96:3]
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
488
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
489 def test_CachedDataSet(self):
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
490 ds = T_Exotic1.DataSet()
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
491 dsc = CachedDataSet(ds)
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
492 for k in range(len(dsc)) :
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
493 self.failUnless(numpy.all( dsc[k]('input')[0] == ds[k]('input')[0] ) , (dsc[k],ds[k]) )
5987415496df better testing of the MultiLengthDataSet, now called exotic1
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents: 297
diff changeset
494 res = dsc[:]
229
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 202
diff changeset
495
157
e8c8022582f4 only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 149
diff changeset
496 if __name__=='__main__':
289
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
497 if len(sys.argv)==2:
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
498 if sys.argv[1]=="--debug":
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
499 module = __import__("_test_dataset")
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
500 tests = unittest.TestLoader().loadTestsFromModule(module)
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
501 tests.debug()
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
502 print "bad argument: only --debug is accepted"
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
503 elif len(sys.argv)==1:
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
504 unittest.main()
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
505 else:
3af204aa71e5 implemented test for FieldsSubsetDataSet. if executed, can take a --debug option to be used in a debugger
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 284
diff changeset
506 print "bad argument: only --debug is accepted"
229
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 202
diff changeset
507