Mercurial > pylearn
annotate test_dataset.py @ 98:7186e4f502d1
bugfix in DataSet.minibatch to correctly wrap in all corner case.
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Tue, 06 May 2008 13:50:54 -0400 |
parents | 352910e0dbf5 |
children | 574f4db76022 |
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 | 2 from dataset import * |
3 from math import * | |
4 import numpy | |
5 | |
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
|
6 def have_raised(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
|
7 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
|
8 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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 |
45 | 14 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
|
15 print "test1" |
45 | 16 global a,ds |
17 a = numpy.random.rand(10,4) | |
18 print a | |
19 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]}) | |
20 print "len(ds)=",len(ds) | |
54 | 21 assert(len(ds)==10) |
45 | 22 print "example 0 = ",ds[0] |
54 | 23 # assert |
45 | 24 print "x=",ds["x"] |
25 print "x|y" | |
26 for x,y in ds("x","y"): | |
27 print x,y | |
28 minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4) | |
29 minibatch = minibatch_iterator.__iter__().next() | |
30 print "minibatch=",minibatch | |
31 for var in minibatch: | |
32 print "var=",var | |
48
b6730f9a336d
Fixing MinibatchDataSet getitem
bengioy@grenat.iro.umontreal.ca
parents:
45
diff
changeset
|
33 print "take a slice and look at field y",ds[1:6:2]["y"] |
45 | 34 |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
35 def test_ArrayDataSet(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
36 #don't test stream |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
37 #tested only with float value |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
38 #test with y too |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
39 #test missing value |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
40 |
96
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
41 def test_iterate_over_examples(array,ds): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
42 #not in doc!!! |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
43 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
44 for example in range(len(ds)): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
45 assert (ds[example]['x']==a[example][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
46 assert ds[example]['y']==a[example][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
47 assert (ds[example]['z']==a[example][[0,2]]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
48 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
49 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
50 del example,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
51 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
52 # - for example in dataset: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
53 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
54 for example in ds: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
55 assert len(example)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
56 assert (example['x']==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
57 assert example['y']==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
58 assert (example['z']==array[i][0:3:2]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
59 assert (numpy.append(example['x'],example['y'])==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
60 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
61 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
62 del example,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
63 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
64 # - for val1,val2,... in dataset: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
65 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
66 for x,y,z in ds: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
67 assert (x==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
68 assert y==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
69 assert (z==array[i][0:3:2]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
70 assert (numpy.append(x,y)==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
71 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
72 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
73 del x,y,z,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
74 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
75 # - for example in dataset(field1, field2,field3, ...): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
76 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
77 for example in ds('x','y','z'): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
78 assert len(example)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
79 assert (example['x']==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
80 assert example['y']==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
81 assert (example['z']==array[i][0:3:2]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
82 assert (numpy.append(example['x'],example['y'])==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
83 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
84 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
85 del example,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
86 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
87 for example in ds('y','x'): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
88 assert len(example)==2 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
89 assert (example['x']==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
90 assert example['y']==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
91 assert (numpy.append(example['x'],example['y'])==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
92 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
93 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
94 del example,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
95 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
96 # - for val1,val2,val3 in dataset(field1, field2,field3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
97 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
98 for x,y,z in ds('x','y','z'): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
99 assert (x==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
100 assert y==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
101 assert (z==array[i][0:3:2]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
102 assert (numpy.append(x,y)==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
103 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
104 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
105 del x,y,z,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
106 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
107 for y,x in ds('y','x',): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
108 assert (x==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
109 assert y==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
110 assert (numpy.append(x,y)==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
111 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
112 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
113 del x,y,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
114 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
115 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
116 # - for minibatch in dataset.minibatches([field1, field2, ...],minibatch_size=N): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
117 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
118 for minibatch in ds.minibatches(['x','z'], minibatch_size=3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
119 assert len(minibatch)==2 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
120 assert len(minibatch[0])==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
121 assert len(minibatch[1])==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
122 assert (minibatch[0][:,0:3:2]==minibatch[1]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
123 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
124 #assert i==#??? What shoud be the value? |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
125 print i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
126 del minibatch,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
127 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
128 for minibatch in ds.minibatches(['x','y'], minibatch_size=3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
129 assert len(minibatch)==2 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
130 assert len(minibatch[0])==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
131 assert len(minibatch[1])==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
132 for id in range(3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
133 assert (numpy.append(minibatch[0][id],minibatch[1][id])==a[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
134 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
135 #assert i==#??? What shoud be the value? |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
136 print i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
137 del minibatch,i,id |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
138 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
139 # - for mini1,mini2,mini3 in dataset.minibatches([field1, field2, field3], minibatch_size=N): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
140 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
141 for x,z in ds.minibatches(['x','z'], minibatch_size=3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
142 assert len(x)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
143 assert len(z)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
144 assert (x[:,0:3:2]==z).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
145 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
146 #assert i==#??? What shoud be the value? |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
147 print i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
148 del x,z,i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
149 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
150 for x,y in ds.minibatches(['x','y'], minibatch_size=3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
151 assert len(x)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
152 assert len(y)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
153 for id in range(3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
154 assert (numpy.append(x[id],y[id])==a[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
155 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
156 #assert i==#??? What shoud be the value? |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
157 print i |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
158 del x,y,i,id |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
159 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
160 #not in doc |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
161 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
162 for x,y in ds.minibatches(['x','y'],n_batches=1,minibatch_size=3,offset=4): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
163 assert len(x)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
164 assert len(y)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
165 for id in range(3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
166 assert (numpy.append(x[id],y[id])==a[i+4]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
167 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
168 assert i==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
169 del x,y,i,id |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
170 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
171 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
172 for x,y in ds.minibatches(['x','y'],n_batches=2,minibatch_size=3,offset=4): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
173 assert len(x)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
174 assert len(y)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
175 for id in range(3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
176 assert (numpy.append(x[id],y[id])==a[i+4]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
177 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
178 assert i==6 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
179 del x,y,i,id |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
180 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
181 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
182 for x,y in ds.minibatches(['x','y'],n_batches=10,minibatch_size=3,offset=4): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
183 assert len(x)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
184 assert len(y)==3 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
185 for id in range(3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
186 assert (numpy.append(x[id],y[id])==a[i+4]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
187 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
188 assert i==6 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
189 del x,y,i,id |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
190 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
191 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
192 def test_ds_iterator(array,iterator1,iterator2,iterator3): |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
193 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
194 for x,y in iterator1: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
195 assert (x==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
196 assert y==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
197 assert (numpy.append(x,y)==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
198 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
199 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
200 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
201 for y,z in iterator2: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
202 assert y==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
203 assert (z==array[i][0:3:2]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
204 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
205 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
206 i=0 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
207 for x,y,z in iterator3: |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
208 assert (x==array[i][:3]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
209 assert y==array[i][3] |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
210 assert (z==array[i][0:3:2]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
211 assert (numpy.append(x,y)==array[i]).all() |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
212 i+=1 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
213 assert i==len(ds) |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
214 |
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
|
215 print "test_ArrayDataSet" |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
216 a = numpy.random.rand(10,4) |
86
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
217 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested |
91
eee739fefdff
corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
89
diff
changeset
|
218 ds = ArrayDataSet(a,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
219 assert len(ds)==10 |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
220 #assert ds==a? should this work? |
96
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
221 |
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
222 test_iterate_over_examples(a, ds) |
91
eee739fefdff
corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
89
diff
changeset
|
223 |
eee739fefdff
corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
89
diff
changeset
|
224 |
eee739fefdff
corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
89
diff
changeset
|
225 # - for val1,val2,val3 in dataset(field1, field2,field3): |
96
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
226 test_ds_iterator(a,ds('x','y'),ds('y','z'),ds('x','y','z')) |
89
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
227 |
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
|
228 assert have_raised("ds['h']") # h is not defined... |
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
|
229 assert have_raised("ds[['h']]") # h is not defined... |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
230 |
63 | 231 assert len(ds.fields())==3 |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
232 for field in ds.fields(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
233 for field_value in field: # iterate over the values associated to that field for all the ds examples |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
234 pass |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
235 for field in ds('x','z').fields(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
236 pass |
60 | 237 for field in ds.fields('x','y'): |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
238 pass |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
239 for field_examples in ds.fields(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
240 for example_value in field_examples: |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
241 pass |
63 | 242 |
243 assert ds == ds.fields().examples() | |
244 | |
86
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
245 def test_ds(orig,ds,index): |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
246 i=0 |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
247 assert len(ds)==len(index) |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
248 for x,z,y in ds('x','z','y'): |
94
9c8f3c9c247b
corrected the use of .all()
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
91
diff
changeset
|
249 assert (orig[index[i]]['x']==a[index[i]][:3]).all() |
9c8f3c9c247b
corrected the use of .all()
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
91
diff
changeset
|
250 assert (orig[index[i]]['x']==x).all() |
86
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
251 assert orig[index[i]]['y']==a[index[i]][3] |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
252 assert orig[index[i]]['y']==y |
94
9c8f3c9c247b
corrected the use of .all()
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
91
diff
changeset
|
253 assert (orig[index[i]]['z']==a[index[i]][0:3:2]).all() |
9c8f3c9c247b
corrected the use of .all()
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
91
diff
changeset
|
254 assert (orig[index[i]]['z']==z).all() |
86
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
255 i+=1 |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
256 del i |
89
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
257 ds[0] |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
258 if len(ds)>2: |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
259 ds[:1] |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
260 ds[1:1] |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
261 ds[1:1:1] |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
262 if len(ds)>5: |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
263 ds[[1,2,3]] |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
264 for x in ds: |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
265 pass |
63 | 266 |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
267 #ds[:n] returns a dataset with the n first examples. |
86
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
268 ds2=ds[:3] |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
269 test_ds(ds,ds2,index=[0,1,2]) |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
270 |
63 | 271 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. |
86
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
272 ds2=ds[1:7:2] |
fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
84
diff
changeset
|
273 test_ds(ds,ds2,[1,3,5]) |
89
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
274 |
63 | 275 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. |
89
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
276 ds2=ds[[4,7,2,8]] |
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
277 test_ds(ds,ds2,[4,7,2,8]) |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
278 #ds[i1,i2,...]# should we accept???? |
89
05dc4804357b
more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
87
diff
changeset
|
279 |
63 | 280 #ds[fieldname]# an iterable over the values of the field fieldname across |
281 #the ds (the iterable is obtained by default by calling valuesVStack | |
282 #over the values for individual examples). | |
283 | |
284 #ds.<property># returns the value of a property associated with | |
285 #the name <property>. The following properties should be supported: | |
286 # - 'description': a textual description or name for the ds | |
287 # - 'fieldtypes': a list of types (one per field) | |
288 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3]) | |
289 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3]) | |
290 | |
96
352910e0dbf5
added test and some restructuring for futur use
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
94
diff
changeset
|
291 # for (x,y) in (ds('x','y'),a): #???don't work # haven't found a variant that work. |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
292 # assert numpy.append(x,y)==z |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
293 |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
294 def test_LookupList(): |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
295 #test only the example in the doc??? |
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
|
296 print "test_LookupList" |
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
|
297 example = LookupList(['x','y','z'],[1,2,3]) |
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
|
298 example['x'] = [1, 2, 3] # set or change a field |
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
|
299 x, y, z = example |
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
|
300 x = example[0] |
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
|
301 x = example["x"] |
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
|
302 assert example.keys()==['x','y','z'] |
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
|
303 assert example.values()==[[1,2,3],2,3] |
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
|
304 assert example.items()==[('x',[1,2,3]),('y',2),('z',3)] |
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
|
305 example.append_keyval('u',0) # adds item with name 'u' and value 0 |
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
|
306 assert len(example)==4 # number of items = 4 here |
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
|
307 example2 = LookupList(['v','w'], ['a','b']) |
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
|
308 example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b']) |
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
|
309 assert example+example2==example3 |
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
|
310 assert have_raised("example+example") |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
311 |
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
|
312 def test_ApplyFunctionDataSet(): |
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
|
313 print "test_ApplyFunctionDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
314 raise NotImplementedError() |
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
|
315 def test_CacheDataSet(): |
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
|
316 print "test_CacheDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
317 raise NotImplementedError() |
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
|
318 def test_FieldsSubsetDataSet(): |
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
|
319 print "test_FieldsSubsetDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
320 raise NotImplementedError() |
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
|
321 def test_DataSetFields(): |
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
|
322 print "test_DataSetFields" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
323 raise NotImplementedError() |
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
|
324 def test_MinibatchDataSet(): |
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
|
325 print "test_MinibatchDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
326 raise NotImplementedError() |
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
|
327 def test_HStackedDataSet(): |
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
|
328 print "test_HStackedDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
329 raise NotImplementedError() |
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
|
330 def test_VStackedDataSet(): |
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
|
331 print "test_VStackedDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
332 raise NotImplementedError() |
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
|
333 def test_ArrayFieldsDataSet(): |
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
|
334 print "test_ArrayFieldsDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
335 raise NotImplementedError() |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
336 |
74
b4159cbdc06b
Fixed errors raised by test_dataset
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
66
diff
changeset
|
337 test1() |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
338 test_LookupList() |
65
d48eba49a2f4
fixed the infinite loop
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
64
diff
changeset
|
339 test_ArrayDataSet() |
64
863da25a60f1
trying to fix infinite loop
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
63
diff
changeset
|
340 |