comparison test_dataset.py @ 58:17729d7104fa

added function test_ArrayDataSet
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Thu, 01 May 2008 16:17:10 -0400
parents 70147d00615a
children 9165d86855ab
comparison
equal deleted inserted replaced
54:70147d00615a 58:17729d7104fa
21 print "minibatch=",minibatch 21 print "minibatch=",minibatch
22 for var in minibatch: 22 for var in minibatch:
23 print "var=",var 23 print "var=",var
24 print "take a slice and look at field y",ds[1:6:2]["y"] 24 print "take a slice and look at field y",ds[1:6:2]["y"]
25 25
26 test1() 26 def test_ArrayDataSet():
27 #don't test stream
28 #tested only with float value
29 a = numpy.random.rand(10,4)
30 print a
31 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})
32 assert len(ds)==10
33 #assert ds==a? should this work?
34 for i in range(len(ds)):
35 assert ds[i]['x'].all()==a[i][:2].all()
36 assert ds[i]['y']==a[i][3]
37 assert ds[i]['z'].all()==a[i][0:3:2].all()
38 print "x=",ds["x"]
39 print "x|y"
40 i=0
41 for x in ds('x','y'):
42 assert numpy.append(x['x'],x['y']).all()==a[i].all()
43 i+=1
44 # i=0
45 # for x in ds['x','y']: # don't work
46 # assert numpy.append(x['x'],x['y']).all()==a[i].all()
47 # i+=1
48 # for (x,y) in (ds('x','y'),a): #don't work # haven't found a variant that work.
49 # assert numpy.append(x,y)==z
50 i=0
51 for x,y in ds('x','y'):
52 assert numpy.append(x,y).all()==a[i].all()
53 i+=1
54 for minibatch in ds.minibatches(['x','z'], minibatch_size=3):
55 assert minibatch[0][:,0:3:2].all()==minibatch[1].all()
56 for x,z in ds.minibatches(['x','z'], minibatch_size=3):
57 assert x[:,0:3:2].all()==z.all()
58
59 # for minibatch in ds.minibatches(['z','y'], minibatch_size=3):
60 # print minibatch
61 # minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4)
62 # minibatch = minibatch_iterator.__iter__().next()
63 # print "minibatch=",minibatch
64 # for var in minibatch:
65 # print "var=",var
66 # print "take a slice and look at field y",ds[1:6:2]["y"]
67 have_thrown = False
68 try:
69 ds['h']
70 except :
71 have_thrown = True
72 assert have_thrown == True
73 assert ds == ds.fields().examples()
74 for field in ds.fields():
75 for field_value in field: # iterate over the values associated to that field for all the ds examples
76 pass
77 for field in ds('x','z').fields():
78 pass
79 for field in ds.fields(field1,field2):
80 pass
81 for field_examples in ds.fields():
82 for example_value in field_examples:
83 pass
84 test_ArrayDataSet()
85