def testMerge(self): #setDebugLevel(GAlgorithms) ds = testdata.loadTestDB() ds1 = transform(ds, 'select', { 'descriptorNames': '*.mean' }) ds2 = transform(ds, 'select', { 'descriptorNames': '*.var' }) ds12 = transform(ds, 'select', { 'descriptorNames': [ '*.mean', '*.var'] }) ds_merged = mergeDataSets(ds1, ds2) # we need to do this because to add a Point we need it with the # original layout, not the FixedLength one testdata.resetSettings() ds_orig = testdata.loadTestDB() sp = ds_orig.samplePoint() # test if we can add points normally ds_merged.removePoint(sp.name()) ds_merged.addPoint(sp) # compare datasets contents self.compareDataSets(ds12, ds_merged) # test the mapDataSet function of the Merge applier ds_remapped = ds_merged.history().mapDataSet(ds_orig) self.compareDataSets(ds12, ds_remapped) self.compareDataSets(ds_merged, ds_remapped)
def testMerge(self): # setDebugLevel(GAlgorithms) ds = testdata.loadTestDB() ds1 = transform(ds, "select", {"descriptorNames": "*.mean"}) ds2 = transform(ds, "select", {"descriptorNames": "*.var"}) ds12 = transform(ds, "select", {"descriptorNames": ["*.mean", "*.var"]}) ds_merged = mergeDataSets(ds1, ds2) # we need to do this because to add a Point we need it with the # original layout, not the FixedLength one testdata.resetSettings() ds_orig = testdata.loadTestDB() sp = ds_orig.samplePoint() # test if we can add points normally ds_merged.removePoint(sp.name()) ds_merged.addPoint(sp) # compare datasets contents self.compareDataSets(ds12, ds_merged) # test the mapDataSet function of the Merge applier ds_remapped = ds_merged.history().mapDataSet(ds_orig) self.compareDataSets(ds12, ds_remapped) self.compareDataSets(ds_merged, ds_remapped)
def testHistory(self): ds = testdata.loadTestDB() ignored_descs = testdata.TEST_DATABASE_VARLENGTH_REAL testdata.resetSettings() ds_orig = testdata.loadTestDB() # cleaning, mandatory step ds = transform(ds, 'fixlength', {'except': ignored_descs}) cleaned_db = transform(ds, 'cleaner', {'except': ignored_descs}) # removing annoying descriptors, like mfcc.cov & mfcc.icov, who don't # like to be normalized like the other ones (constant value: dimension) no_mfcc_db = transform(cleaned_db, 'remove', {'descriptorNames': '*mfcc*'}) # normalize, to have everyone change values normalized_db = transform(no_mfcc_db, 'normalize', {'except': ignored_descs}) testPoints = [ '01 Oye Como Va - Santana.mp3', '02 Carmen Burana- O Fortuna.mp3', '07 Romeo and Juliet- the Knights\' Dance.mp3', '11 Lambada.mp3' ] for pointName in testPoints: p1 = normalized_db.point(pointName) p2 = normalized_db.history().mapPoint(ds_orig.point(pointName)) for name in p1.layout().descriptorNames(): self.assertEqual(p1[name], p2[name]) (tmpFile, tmpName) = tempfile.mkstemp() os.close(tmpFile) normalized_db.save(tmpName) reloaded_db = DataSet() reloaded_db.load(tmpName) for pointName in testPoints: p1 = normalized_db.point(pointName) p2 = normalized_db.history().mapPoint(ds_orig.point(pointName)) p3 = reloaded_db.point(pointName) p4 = reloaded_db.history().mapPoint(ds_orig.point(pointName)) self.assert_(p1.layout() == p2.layout()) self.assert_(p2.layout() == p3.layout()) self.assert_(p3.layout() == p4.layout()) for name in p1.layout().descriptorNames(): self.assertEqual(p1[name], p2[name]) self.assertEqual(p2[name], p3[name]) self.assertEqual(p3[name], p4[name]) # remove temp file os.remove(tmpName)
def testHistory(self): ds = testdata.loadTestDB() ignored_descs = testdata.TEST_DATABASE_VARLENGTH_REAL testdata.resetSettings() ds_orig = testdata.loadTestDB() # cleaning, mandatory step ds = transform(ds, 'fixlength', { 'except': ignored_descs }) cleaned_db = transform(ds, 'cleaner', { 'except': ignored_descs }) # removing annoying descriptors, like mfcc.cov & mfcc.icov, who don't # like to be normalized like the other ones (constant value: dimension) no_mfcc_db = transform(cleaned_db, 'remove', { 'descriptorNames': '*mfcc*' }) # normalize, to have everyone change values normalized_db = transform(no_mfcc_db, 'normalize', { 'except': ignored_descs }) testPoints = [ '01 Oye Como Va - Santana.mp3', '02 Carmen Burana- O Fortuna.mp3', '07 Romeo and Juliet- the Knights\' Dance.mp3', '11 Lambada.mp3' ] for pointName in testPoints: p1 = normalized_db.point(pointName) p2 = normalized_db.history().mapPoint(ds_orig.point(pointName)) for name in p1.layout().descriptorNames(): self.assertEqual(p1[name], p2[name]) (tmpFile, tmpName) = tempfile.mkstemp() os.close(tmpFile) normalized_db.save(tmpName) reloaded_db = DataSet() reloaded_db.load(tmpName) for pointName in testPoints: p1 = normalized_db.point(pointName) p2 = normalized_db.history().mapPoint(ds_orig.point(pointName)) p3 = reloaded_db.point(pointName) p4 = reloaded_db.history().mapPoint(ds_orig.point(pointName)) self.assert_(p1.layout() == p2.layout()) self.assert_(p2.layout() == p3.layout()) self.assert_(p3.layout() == p4.layout()) for name in p1.layout().descriptorNames(): self.assertEqual(p1[name], p2[name]) self.assertEqual(p2[name], p3[name]) self.assertEqual(p3[name], p4[name]) # remove temp file os.remove(tmpName)
def testLinkedViews(self): ds = testdata.createSimpleDataSet() ds.point('p')['a.1'] = 23.0 for i in range(5): p = Point() p.setName('p%d' % i) p.setLayout(ds.originalLayout()) p['a.1'] = float(i) ds.addPoint(p) ds = transform(ds, 'fixlength') dist = MetricFactory.create('euclidean', ds.layout()) v = View(ds) query = Point(ds.point('p')) query['a.1'] = 23.0 self.assertEqual((('p', 0.), ('p4', 19.), ('p3', 20.), ('p2', 21.)), v.nnSearch(query, dist).get(4)) ds.removePoint('p') self.assertEqual((('p4', 19.), ('p3', 20.), ('p2', 21.), ('p1', 22.)), v.nnSearch(query, dist).get(4)) ds.removePoint('p3') self.assertEqual((('p4', 19.), ('p2', 21.), ('p1', 22.), ('p0', 23.)), v.nnSearch(query, dist).get(4)) # get original query point to add in dataset testdata.resetSettings() dsq = testdata.createSimpleDataSet() orig_query = Point(dsq.point('p')) orig_query['a.1'] = 23.0 ds.addPoint(orig_query) self.assertEqual((('p', 0.), ('p4', 19.), ('p2', 21.), ('p1', 22.)), v.nnSearch(query, dist).get(4))
def tearDown(self): testdata.resetSettings()