Mercurial > pylearn
comparison test_dataset.py @ 86:fdf72ea4f2bc
added function test_ds in test_ArrayDataSet who test a sub dataset
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Mon, 05 May 2008 14:37:34 -0400 |
parents | aa9e786ee849 |
children | 3fd6879e0f76 |
comparison
equal
deleted
inserted
replaced
85:7b1f3ad3d60b | 86:fdf72ea4f2bc |
---|---|
38 #test with y too | 38 #test with y too |
39 #test missing value | 39 #test missing value |
40 | 40 |
41 print "test_ArrayDataSet" | 41 print "test_ArrayDataSet" |
42 a = numpy.random.rand(10,4) | 42 a = numpy.random.rand(10,4) |
43 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]}) | 43 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested |
44 | |
44 assert len(ds)==10 | 45 assert len(ds)==10 |
45 #assert ds==a? should this work? | 46 #assert ds==a? should this work? |
46 for i in range(len(ds)): | 47 for i in range(len(ds)): |
47 assert ds[i]['x'].all()==a[i][:2].all() | 48 assert ds[i]['x'].all()==a[i][:2].all() |
48 assert ds[i]['y']==a[i][3] | 49 assert ds[i]['y']==a[i][3] |
84 for example_value in field_examples: | 85 for example_value in field_examples: |
85 pass | 86 pass |
86 | 87 |
87 assert ds == ds.fields().examples() | 88 assert ds == ds.fields().examples() |
88 | 89 |
90 def test_ds(orig,ds,index): | |
91 i=0 | |
92 assert len(ds)==len(index) | |
93 for x,z,y in ds('x','z','y'): | |
94 print x,y,z | |
95 assert orig[index[i]]['x'].all()==a[index[i]][:3].all() | |
96 assert orig[index[i]]['x'].all()==x.all() | |
97 assert orig[index[i]]['y']==a[index[i]][3] | |
98 assert orig[index[i]]['y']==y | |
99 assert orig[index[i]]['z'].all()==a[index[i]][0:3:2].all() | |
100 assert orig[index[i]]['z'].all()==z.all() | |
101 i+=1 | |
102 del i | |
89 | 103 |
90 #ds[:n] returns a dataset with the n first examples. | 104 #ds[:n] returns a dataset with the n first examples. |
91 assert len(ds[:3])==3 | 105 ds2=ds[:3] |
92 i=0 | 106 test_ds(ds,ds2,index=[0,1,2]) |
93 for x,z,y in ds[:3]('x','z','y'): | |
94 assert ds[i]['x'].all()==a[i][:3].all() | |
95 assert ds[i]['x'].all()==x.all() | |
96 assert ds[i]['y']==a[i][3] | |
97 assert ds[i]['y']==y | |
98 assert ds[i]['z'].all()==a[i][0:3:2].all() | |
99 assert ds[i]['z'].all()==z.all() | |
100 i+=1 | |
101 i=0 | |
102 for x,z in ds[:3]('x','z'): | |
103 assert ds[i]['z'].all()==a[i][0:3:2].all() | |
104 i+=1 | |
105 | 107 |
106 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. | 108 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. |
107 ds[1:7:2][1] | 109 ds2=ds[1:7:2] |
108 assert len(ds[1:7:2])==3 # should be number example 1,3 and 5 | 110 ds2[1] |
109 i=0 | 111 test_ds(ds,ds2,[1,3,5]) |
110 index=[1,3,5] | |
111 for z,y,x in ds[1:7:2]('z','y','x'): | |
112 assert ds[index[i]]['x'].all()==a[index[i]][:3].all() | |
113 assert ds[index[i]]['x'].all()==x.all() | |
114 assert ds[index[i]]['y']==a[index[i]][3] | |
115 assert ds[index[i]]['y']==y | |
116 assert ds[index[i]]['z'].all()==a[index[i]][0:3:2].all() | |
117 assert ds[index[i]]['z'].all()==z.all() | |
118 i+=1 | |
119 | |
120 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. | 112 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. |
121 i=0 | 113 # ds2=ds[[4,7,2,8]]# fail |
122 for x in ds[[1,2]]: | 114 # assert len(ds2)==4 |
123 assert numpy.append(x['x'],x['y']).all()==a[i].all() | 115 # i=0 |
124 i+=1 | 116 # index=[4,7,2,8] |
117 # for x in ds2: | |
118 # assert ds[index[i]]['x'].all()==a[index[i]][:3].all() | |
119 # assert ds[index[i]]['x'].all()==x.all() | |
120 # assert ds[index[i]]['y']==a[index[i]][3] | |
121 # assert ds[index[i]]['y']==y | |
122 # assert ds[index[i]]['z'].all()==a[index[i]][0:3:2].all() | |
123 # assert ds[index[i]]['z'].all()==z.all() | |
124 # i+=1 | |
125 #ds[i1,i2,...]# should we accept???? | 125 #ds[i1,i2,...]# should we accept???? |
126 #ds[fieldname]# an iterable over the values of the field fieldname across | 126 #ds[fieldname]# an iterable over the values of the field fieldname across |
127 #the ds (the iterable is obtained by default by calling valuesVStack | 127 #the ds (the iterable is obtained by default by calling valuesVStack |
128 #over the values for individual examples). | 128 #over the values for individual examples). |
129 | 129 |