コード例 #1
0
 def testSelectThreshold(self):
     '''Test the effect of the threshold parameter on feature selection'''
     data = np.random.rand(200,3,10)
     fg = FeatureGenerator(data)
     fg.generators = [gens.identity]
     fg.generate()
     fg.select(0.00001)
     n01 = len(fg.selected_fracs)
     fg.select(0.5)
     n5 = len(fg.selected_fracs)
     sum5 = sum(fg.selected_fracs)
     assert n5 <= n01, 'Threshold has no effect on select()'
     assert sum5 < .75, 'Threshold does not bound eigenvalues correctly'
コード例 #2
0
 def testSelect(self):
     '''Test the selection of generated features'''
     data = np.random.rand(200,3,10)
     fg = FeatureGenerator(data)
     fg.generators = [gens.identity]
     fg.generate()
     selret = fg.select()
     assert len(fg.selected_weights) > 0, 'Bad selected weights output'
     assert len(fg.selected_fracs) > 0, 'Bad selected fracs output'
     assert (selret == fg.selected_fracs).all(), 'Select() did not return selected fracs appropriately'
     assert len(fg.selected_fracs) == fg.selected_weights.shape[0], \
                     'Selected fracs and weights do not have equal first dimension'
コード例 #3
0
 def testApplication(self):
     '''Test the application of the generated weights on data'''
     data = np.random.rand(200,3,10)
     fg = FeatureGenerator(data)
     fg.generators = [gens.identity]
     fg.generate()
     fg.select()
     
     applied_base = fg.apply_weights()
     
     assert len(applied_base.shape) == 2, 'apply_weights() returns non-2d shape for [] input'
     assert applied_base.shape[0] == fg.datas.shape[0], \
                     'apply_weights() doesnt keep first dimension constant on [] input'
     assert applied_base.shape[1] == len(fg.selected_fracs), \
                     'apply_weights() does not keep the same number of features as selected'
                 
     new_data = np.random.rand(int(fg.datas.shape[0]/2), fg.datas.shape[1], fg.datas.shape[2])
     applied_rand = fg.apply_weights(new_data)
     
     assert len(applied_rand.shape) == 2, 'apply_weights() returns non-2d shape for new data input'
     assert applied_rand.shape[0] == new_data.shape[0], \
                     'apply_weights() doesnt keep first dimension constant on new data input'
     assert applied_rand.shape != applied_base.shape, 'New input data had no effect on return from apply_weights()'