Mercurial > pylearn
diff test_dataset.py @ 259:621faba17c60
created 'dummytests', tests that checks consistency of new weird datasets, where we can't compare with actual values in a matrix, for instance. Useful as a first debugging when creating a dataset
author | Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca> |
---|---|
date | Tue, 03 Jun 2008 16:41:55 -0400 |
parents | bf0a1ebc6e52 |
children | 792f81d65f82 |
line wrap: on
line diff
--- a/test_dataset.py Tue Jun 03 16:06:21 2008 -0400 +++ b/test_dataset.py Tue Jun 03 16:41:55 2008 -0400 @@ -558,6 +558,95 @@ f_ds_mb2(ds,10000) + + + + +#**************************************************************** +# dummy tests, less powerful than the previous tests, but can work with any new weird dataset. +# Basically, emphasis is put on consistency, but it never checks the actual values. +# To be used as a checklist, or a first test, when creating a new dataset + +def dummytest_all(ds) : + """ Launches all the dummytests with a given dataset. """ + + +def test1_basicstats(self,ds) : + """print basics stats on a dataset, like length""" + + print 'len(ds) = ',len(ds) + print 'num fields = ', len(ds.fieldNames()) + print 'types of field: ', + for k in ds.fieldNames() : + print type(ds[0](k)[0]), + print '' + +def dummytest1_basicstats(self,ds) : + """print basics stats on a dataset, like length""" + + print 'len(ds) = ',len(ds) + print 'num fields = ', len(ds.fieldNames()) + print 'types of field: ', + for k in ds.fieldNames() : + print type(ds[0](k)[0]), + print '' + +def dummytest2_slicing(self,ds) : + """test if slicing works properly""" + print 'testing slicing...', + sys.stdout.flush() + + middle = len(ds) / 2 + tenpercent = int(len(ds) * .1) + set1 = ds[:middle+tenpercent] + set2 = ds[middle-tenpercent:] + for k in range(tenpercent + tenpercent -1): + for k2 in ds.fieldNames() : + if type(set1[middle-tenpercent+k](k2)[0]) == N.ndarray : + for k3 in range(len(set1[middle-tenpercent+k](k2)[0])) : + assert set1[middle-tenpercent+k](k2)[0][k3] == set2[k](k2)[0][k3] + else : + assert set1[middle-tenpercent+k](k2)[0] == set2[k](k2)[0] + assert tenpercent > 1 + set3 = ds[middle-tenpercent:middle+tenpercent:2] + for k2 in ds.fieldNames() : + if type(set2[2](k2)[0]) == N.ndarray : + for k3 in range(len(set2[2](k2)[0])) : + assert set2[2](k2)[0][k3] == set3[1](k2)[0][k3] + else : + assert set2[2](k2)[0] == set3[1](k2)[0] + + print 'done' + + +def dummytest3_fields_iterator_consistency(self,ds) : + """ check if the number of iterator corresponds to the number of fields""" + print 'testing fields/iterator consistency...', + sys.stdout.flush() + + # basic test + maxsize = min(len(ds)-1,100) + for iter in ds[:maxsize] : + assert len(iter) == len(ds.fieldNames()) + if len(ds.fieldNames()) == 1 : + print 'done' + return + + # with minibatches iterator + ds2 = ds[:maxsize].minibatches([ds.fieldNames()[0],ds.fieldNames()[1]],minibatch_size=2) + for iter in ds2 : + assert len(iter) == 2 + + print 'done' + + + + + + + + + if __name__=='__main__': test1() test_LookupList()