def test_chooseOptQoIs(self): """ Test :meth:`bet.sensitivity.chooseQoIs.chooseOptQoIs`. """ self.qoiIndices = range(0, self.num_qois) self.condnum_indices_mat = cQoIs.chooseOptQoIs( self.G, self.qoiIndices, self.num_qois_return, self.num_optsets_return ) # Test the method returns the correct size array self.assertEqual(self.condnum_indices_mat.shape, (self.num_optsets_return, self.num_qois_return + 1)) # Check that the 'global condidtion number' is greater than or equal to 1 nptest.assert_array_less(1.0, self.condnum_indices_mat[:, 0]) # Test the method returns the known best set of QoIs (chosen to be # last Lambda_dim indices) nptest.assert_array_less(self.num_qois - self.Lambda_dim - 1, self.condnum_indices_mat[0, 1:]) # Test that none of the best chosen QoIs are the same self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat[0, 1:])) # Test the method for a set of QoIs rather than all possible. Choose # this set so that the optimal choice is not removed. self.qoiIndices = np.concatenate([range(1, 3, 2), range(4, self.num_qois)]) self.condnum_indices_mat = cQoIs.chooseOptQoIs( self.G, self.qoiIndices, self.num_qois_return, self.num_optsets_return ) # Test the method returns the correct number of qois self.assertEqual(self.condnum_indices_mat.shape, (self.num_optsets_return, self.num_qois_return + 1)) # Check that the 'global condidtion number' is greater than or equal # to 1 nptest.assert_array_less(1.0, self.condnum_indices_mat[:, 0]) # Test the method returns the known best set of QoIs (chosen to be # last Lambda_dim indices) nptest.assert_array_less(self.num_qois - self.Lambda_dim - 1, self.condnum_indices_mat[0, 1:]) # Test that none of the best chosen QoIs are the same self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat[0, 1:]))
samples = matfile['samples'] data = matfile['data'] Lambda_dim = samples.shape[1] # Calculate the gradient vectors at each of the 16 centers for each of the # QoI maps G = grad.calculate_gradients_rbf(samples, data) #G = grad.calculate_gradients_ffd(samples, data) #G = grad.calculate_gradients_cfd(samples, data) # With a set of QoIs to consider, we check all possible combinations # of the QoIs and choose the best sets. indexstart = 0 indexstop = 20 qoiIndices = range(indexstart, indexstop) condnum_indices_mat = cQoIs.chooseOptQoIs(G, qoiIndices) qoi1 = condnum_indices_mat[0, 1] qoi2 = condnum_indices_mat[0, 2] if comm.rank==0: print 'The 10 smallest condition numbers are in the first column, the \ corresponding sets of QoIs are in the following columns.' print condnum_indices_mat # Choose a specific set of QoIs to check the condition number of index1 = 0 index2 = 4 singvals = np.linalg.svd(G[:, [index1, index2], :], compute_uv=False) spec_condnum = np.sum(singvals[:,0]/singvals[:,-1], axis=0)/16
def test_chooseOptQoIs(self): """ Test :meth:`bet.sensitivity.chooseQoIs.chooseOptQoIs`. """ self.qoiIndices = range(0, self.num_qois) self.condnum_indices_mat = cQoIs.chooseOptQoIs(self.G, self.qoiIndices, self.num_qois_return, self.num_optsets_return) self.condnum_indices_mat_vol = cQoIs.chooseOptQoIs( self.G, self.qoiIndices, self.num_qois_return, self.num_optsets_return, volume=True) # Test the method returns the correct size array self.assertEqual(self.condnum_indices_mat.shape, (self.num_optsets_return, self.num_qois_return + 1)) self.assertEqual(self.condnum_indices_mat_vol.shape, (self.num_optsets_return, self.num_qois_return + 1)) # Check that the 'global condition number' is greater than or equal to 1 nptest.assert_array_less(1.0, self.condnum_indices_mat[:, 0]) # For volume, check that it is greater than or equal to 0 nptest.assert_array_less(0.0, self.condnum_indices_mat_vol[:, 0]) # Test the method returns the known best set of QoIs (chosen to be # last Lambda_dim indices) nptest.assert_array_less(self.num_qois - self.Lambda_dim - 1, self.condnum_indices_mat[0, 1:]) nptest.assert_array_less(self.num_qois - self.Lambda_dim - 1, self.condnum_indices_mat_vol[0, 1:]) # Test that none of the best chosen QoIs are the same self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat[0, 1:])) self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat_vol[0, 1:])) ########## # Test the method for a set of QoIs rather than all possible. Choose # this set so that the optimal choice is not removed. self.qoiIndices = np.concatenate( [range(1, 3, 2), range(4, self.num_qois)]) self.condnum_indices_mat = cQoIs.chooseOptQoIs(self.G, self.qoiIndices, self.num_qois_return, self.num_optsets_return) self.condnum_indices_mat_vol = cQoIs.chooseOptQoIs( self.G, self.qoiIndices, self.num_qois_return, self.num_optsets_return, volume=True) # Test the method returns the correct number of qois self.assertEqual(self.condnum_indices_mat.shape, (self.num_optsets_return, self.num_qois_return + 1)) self.assertEqual(self.condnum_indices_mat_vol.shape, (self.num_optsets_return, self.num_qois_return + 1)) # Check that the 'global condidtion number' is greater than or equal # to 1 nptest.assert_array_less(1.0, self.condnum_indices_mat[:, 0]) nptest.assert_array_less(0.0, self.condnum_indices_mat_vol[:, 0]) # Test the method returns the known best set of QoIs (chosen to be # last Lambda_dim indices) nptest.assert_array_less(self.num_qois - self.Lambda_dim - 1, self.condnum_indices_mat[0, 1:]) nptest.assert_array_less(self.num_qois - self.Lambda_dim - 1, self.condnum_indices_mat_vol[0, 1:]) # Test that none of the best chosen QoIs are the same self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat[0, 1:])) self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat_vol[0, 1:]))
def test_chooseOptQoIs(self): """ Test :meth:`bet.sensitivity.chooseQoIs.chooseOptQoIs`. """ self.qoiIndices = np.arange(0, self.output_dim) self.condnum_indices_mat = cQoIs.chooseOptQoIs(self.input_set_centers, self.qoiIndices, self.output_dim_return, self.num_optsets_return) self.condnum_indices_mat_vol = cQoIs.chooseOptQoIs(self.input_set_centers, self.qoiIndices, self.output_dim_return, self.num_optsets_return, measure=True) # Test the method returns the correct size array self.assertEqual(self.condnum_indices_mat.shape, (self.num_optsets_return, self.output_dim_return + 1)) self.assertEqual(self.condnum_indices_mat_vol.shape, (self.num_optsets_return, self.output_dim_return + 1)) # Check that the 'global condition number' is greater than or equal to 1 nptest.assert_array_less(1.0, self.condnum_indices_mat[:, 0]) # For measure, check that it is greater than or equal to 0 nptest.assert_array_less(0.0, self.condnum_indices_mat_vol[:, 0]) # Test the method returns the known best set of QoIs (chosen to be # last input_dim indices) nptest.assert_array_less(self.output_dim-self.input_dim-1, self.condnum_indices_mat[0, 1:]) nptest.assert_array_less(self.output_dim-self.input_dim-1, self.condnum_indices_mat_vol[0, 1:]) # Test that none of the best chosen QoIs are the same self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat[0, 1:])) self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat_vol[0, 1:])) ########## # Test the method for a set of QoIs rather than all possible. Choose # this set so that the optimal choice is not removed. self.qoiIndices = np.concatenate([np.arange(1, 3, 2), np.arange(4, self.output_dim)]) self.condnum_indices_mat = cQoIs.chooseOptQoIs(self.input_set_centers, self.qoiIndices, self.output_dim_return, self.num_optsets_return) self.condnum_indices_mat_vol = cQoIs.chooseOptQoIs(self.input_set_centers, self.qoiIndices, self.output_dim_return, self.num_optsets_return, measure=True) # Test the method returns the correct number of qois self.assertEqual(self.condnum_indices_mat.shape, (self.num_optsets_return, self.output_dim_return + 1)) self.assertEqual(self.condnum_indices_mat_vol.shape, (self.num_optsets_return, self.output_dim_return + 1)) # Check that the 'global condidtion number' is greater than or equal # to 1 nptest.assert_array_less(1.0, self.condnum_indices_mat[:, 0]) nptest.assert_array_less(0.0, self.condnum_indices_mat_vol[:, 0]) # Test the method returns the known best set of QoIs (chosen to be # last input_dim indices) nptest.assert_array_less(self.output_dim-self.input_dim-1, self.condnum_indices_mat[0, 1:]) nptest.assert_array_less(self.output_dim-self.input_dim-1, self.condnum_indices_mat_vol[0, 1:]) # Test that none of the best chosen QoIs are the same self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat[0, 1:])) self.assertEqual(len(np.unique(self.condnum_indices_mat[0, 1:])), len(self.condnum_indices_mat_vol[0, 1:]))
center_discretization = grad.calculate_gradients_cfd( cluster_discretization) input_samples_centers = center_discretization.get_input_sample_set() # Choose a specific set of QoIs to check the average skewness of index1 = 0 index2 = 4 (specific_skewness, _) = cqoi.calculate_avg_skewness(input_samples_centers, qoi_set=[index1, index2]) if comm.rank == 0: print 'The average skewness of the QoI map defined by indices ' + str(index1) + \ ' and ' + str(index2) + ' is ' + str(specific_skewness) # Compute the skewness for each of the possible QoI maps determined by choosing # any two QoI from the set defined by the indices selected by the # ``indexstart`` and ``indexend`` values skewness_indices_mat = cqoi.chooseOptQoIs(input_samples_centers, qoiIndices, num_optsets_return=10, measure=False) qoi1 = skewness_indices_mat[0, 1] qoi2 = skewness_indices_mat[0, 2] if comm.rank == 0: print 'The 10 smallest condition numbers are in the first column, the \ corresponding sets of QoIs are in the following columns.' print skewness_indices_mat[:10, :]
elif fd_scheme.upper() in ['FFD']: center_discretization = grad.calculate_gradients_ffd(cluster_discretization) else: center_discretization = grad.calculate_gradients_cfd(cluster_discretization) input_samples_centers = center_discretization.get_input_sample_set() # Choose a specific set of QoIs to check the average skewness of index1 = 0 index2 = 4 (specific_skewness, _) = cqoi.calculate_avg_skewness(input_samples_centers, qoi_set=[index1, index2]) if comm.rank == 0: print 'The average skewness of the QoI map defined by indices ' + str(index1) + \ ' and ' + str(index2) + ' is ' + str(specific_skewness) # Compute the skewness for each of the possible QoI maps determined by choosing # any two QoI from the set defined by the indices selected by the # ``indexstart`` and ``indexend`` values skewness_indices_mat = cqoi.chooseOptQoIs(input_samples_centers, qoiIndices, num_optsets_return=10, measure=False) qoi1 = skewness_indices_mat[0, 1] qoi2 = skewness_indices_mat[0, 2] if comm.rank == 0: print 'The 10 smallest condition numbers are in the first column, the \ corresponding sets of QoIs are in the following columns.' print skewness_indices_mat[:10, :]
samples = matfile['samples'] data = matfile['data'] Lambda_dim = samples.shape[1] # Calculate the gradient vectors at each of the 16 centers for each of the # QoI maps G = grad.calculate_gradients_rbf(samples, data) #G = grad.calculate_gradients_ffd(samples, data) #G = grad.calculate_gradients_cfd(samples, data) # With a set of QoIs to consider, we check all possible combinations # of the QoIs and choose the best sets. indexstart = 0 indexstop = 20 qoiIndices = range(indexstart, indexstop) condnum_indices_mat = cQoIs.chooseOptQoIs(G, qoiIndices) qoi1 = condnum_indices_mat[0, 1] qoi2 = condnum_indices_mat[0, 2] if comm.rank == 0: print 'The 10 smallest condition numbers are in the first column, the \ corresponding sets of QoIs are in the following columns.' print condnum_indices_mat # Choose a specific set of QoIs to check the condition number of index1 = 0 index2 = 4 singvals = np.linalg.svd(G[:, [index1, index2], :], compute_uv=False) spec_condnum = np.sum(singvals[:, 0] / singvals[:, -1], axis=0) / 16