Mercurial > pylearn
comparison test_dataset.py @ 268:3f1cd8897fda
reverting dataset
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Wed, 04 Jun 2008 18:48:50 -0400 |
parents | 6e69fb91f3c0 |
children | fdce496c3b56 |
comparison
equal
deleted
inserted
replaced
267:4dad41215967 | 268:3f1cd8897fda |
---|---|
419 ds = ArrayDataSet(a2,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested | 419 ds = ArrayDataSet(a2,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested |
420 #assert ds==a? should this work? | 420 #assert ds==a? should this work? |
421 | 421 |
422 test_all(a2,ds) | 422 test_all(a2,ds) |
423 | 423 |
424 del a2, ds #removes from list of active objects in debugger | 424 del a2, ds |
425 | 425 |
426 def test_LookupList(): | 426 def test_LookupList(): |
427 #test only the example in the doc??? | 427 #test only the example in the doc??? |
428 print "test_LookupList" | 428 print "test_LookupList" |
429 example = LookupList(['x','y','z'],[1,2,3]) | 429 example = LookupList(['x','y','z'],[1,2,3]) |
542 f_array_full(array) | 542 f_array_full(array) |
543 f_array_index(array) | 543 f_array_index(array) |
544 f_array_iter(array) | 544 f_array_iter(array) |
545 | 545 |
546 f_ds_index(ds) | 546 f_ds_index(ds) |
547 f_ds_index(ds) | |
548 f_ds_iter(ds) | |
549 f_ds_iter(ds) | 547 f_ds_iter(ds) |
550 | 548 |
551 f_ds_mb1(ds,10) | 549 f_ds_mb1(ds,10) |
552 f_ds_mb1(ds,100) | 550 f_ds_mb1(ds,100) |
553 f_ds_mb1(ds,1000) | 551 f_ds_mb1(ds,1000) |
556 f_ds_mb2(ds,100) | 554 f_ds_mb2(ds,100) |
557 f_ds_mb2(ds,1000) | 555 f_ds_mb2(ds,1000) |
558 f_ds_mb2(ds,10000) | 556 f_ds_mb2(ds,10000) |
559 | 557 |
560 | 558 |
561 | |
562 | |
563 | |
564 | |
565 #**************************************************************** | |
566 # dummy tests, less powerful than the previous tests, but can work with any new weird dataset. | |
567 # Basically, emphasis is put on consistency, but it never checks the actual values. | |
568 # To be used as a checklist, or a first test, when creating a new dataset | |
569 | |
570 def dummytest_all(ds) : | |
571 """ Launches all the dummytests with a given dataset. """ | |
572 | |
573 dummytest1_basicstats(ds) | |
574 dummytest2_slicing(ds) | |
575 dummytest3_fields_iterator_consistency(ds) | |
576 | |
577 | |
578 def dummytest1_basicstats(ds) : | |
579 """print basics stats on a dataset, like length""" | |
580 | |
581 print 'len(ds) = ',len(ds) | |
582 print 'num fields = ', len(ds.fieldNames()) | |
583 print 'types of field: ', | |
584 for k in ds.fieldNames() : | |
585 print type(ds[0](k)[0]), | |
586 print '' | |
587 | |
588 def dummytest2_slicing(ds) : | |
589 """test if slicing seems to works properly""" | |
590 print 'testing slicing...', | |
591 sys.stdout.flush() | |
592 | |
593 middle = len(ds) / 2 | |
594 tenpercent = int(len(ds) * .1) | |
595 set1 = ds[:middle+tenpercent] | |
596 set2 = ds[middle-tenpercent:] | |
597 for k in range(tenpercent + tenpercent -1): | |
598 for k2 in ds.fieldNames() : | |
599 if type(set1[middle-tenpercent+k](k2)[0]) == N.ndarray : | |
600 for k3 in range(len(set1[middle-tenpercent+k](k2)[0])) : | |
601 assert set1[middle-tenpercent+k](k2)[0][k3] == set2[k](k2)[0][k3] | |
602 else : | |
603 assert set1[middle-tenpercent+k](k2)[0] == set2[k](k2)[0] | |
604 assert tenpercent > 1 | |
605 set3 = ds[middle-tenpercent:middle+tenpercent:2] | |
606 for k2 in ds.fieldNames() : | |
607 if type(set2[2](k2)[0]) == N.ndarray : | |
608 for k3 in range(len(set2[2](k2)[0])) : | |
609 assert set2[2](k2)[0][k3] == set3[1](k2)[0][k3] | |
610 else : | |
611 assert set2[2](k2)[0] == set3[1](k2)[0] | |
612 | |
613 print 'done' | |
614 | |
615 | |
616 def dummytest3_fields_iterator_consistency(ds) : | |
617 """test if the number of iterator corresponds to the number of fields, also do it for minibatches""" | |
618 print 'testing fields/iterator consistency...', | |
619 sys.stdout.flush() | |
620 | |
621 # basic test | |
622 maxsize = min(len(ds)-1,100) | |
623 for iter in ds[:maxsize] : | |
624 assert len(iter) == len(ds.fieldNames()) | |
625 if len(ds.fieldNames()) == 1 : | |
626 print 'done' | |
627 return | |
628 | |
629 # with minibatches iterator | |
630 ds2 = ds[:maxsize].minibatches([ds.fieldNames()[0],ds.fieldNames()[1]],minibatch_size=2) | |
631 for iter in ds2 : | |
632 assert len(iter) == 2 | |
633 | |
634 print 'done' | |
635 | |
636 | |
637 | |
638 | |
639 | |
640 | |
641 | |
642 | |
643 | |
644 if __name__=='__main__': | 559 if __name__=='__main__': |
645 if 0: | 560 test1() |
646 test1() | |
647 test_LookupList() | 561 test_LookupList() |
648 test_ArrayDataSet() | 562 test_ArrayDataSet() |
649 test_CachedDataSet() | 563 test_CachedDataSet() |
650 test_ApplyFunctionDataSet() | 564 test_ApplyFunctionDataSet() |
651 #test_speed() | 565 #test_speed() |