def test_cvt_attributes_04(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) np.testing.assert_array_almost_equal(cvt_handler.weights, weights)
def test_cvt_attributes_09(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) assert cvt_handler.dim_mu == 2
def test_cvt_compute_leave_one_out_error_02(self): mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test_scalar.npy') cvt_handler = cvt.Cvt(mu_values, snapshots) error = cvt_handler.loo_error() expected_error = np.array([0.718888, 0.28908 , 0.394886, 0.034921]) np.testing.assert_array_almost_equal(error, expected_error)
def test_cvt_attributes_07a(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) expected_rel_error = 780.142129403 np.testing.assert_almost_equal(cvt_handler.rel_error, expected_rel_error)
def test_cvt_compute_max_error(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) cvt_handler.add_new_point() expected_value = 0.14913012395372877 np.testing.assert_almost_equal(cvt_handler.max_error, expected_value)
def test_cvt_compute_new_point(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) cvt_handler.add_new_point() expected_value = np.array([-0.29334384, -0.2312056]) np.testing.assert_array_almost_equal(cvt_handler.mu_values[:,-1], expected_value)
def test_cvt_compute_leave_one_out_error_01(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) error = cvt_handler.loo_error() expected_error = np.array([0.14913012, 0.05875263, 0.04603026, 0.07641862]) np.testing.assert_array_almost_equal(error, expected_error)
def print_info(self): """ This method compute and print the new parameter point for the next simulation and the maximum error in the tesselation. """ self.cvt_handler = cvt.Cvt(self.mu_values, self.snapshots) self.cvt_handler.add_new_point() print ('Maximum error on the tassellation: ' + str(self.cvt_handler.max_error)) print ('New baricentric parameter value added to the triangulation ' + str(self.cvt_handler.mu_values[:,-1]) + '\n')
def test_cvt_compute_volume_1(self): pod_basis = np.load('tests/test_datasets/pod_basis_test.npy') mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test.npy') weights = np.load('tests/test_datasets/weights_test.npy') cvt_handler = cvt.Cvt(mu_values, snapshots, pod_basis, weights) points_x = np.array([0., 1., 0.]) points_y = np.array([0., 0., 1.]) simplex_vertices = np.array([points_x, points_y]) volume = cvt_handler._compute_simplex_volume(simplex_vertices) assert volume == 0.5
def print_info(self): """ This method compute and print the new parameter point for the next simulation and the maximum error in the tesselation. """ weighted_snapshots = np.sqrt(self.weights) * self.snapshots.T eigenvectors, eigenvalues, __ = np.linalg.svd(weighted_snapshots.T, full_matrices=False) self.pod_basis = np.transpose( np.power(self.weights, -0.5) * eigenvectors.T) self.cvt_handler = cvt.Cvt(self.mu_values, self.snapshots, self.pod_basis, self.weights) self.cvt_handler.add_new_point() print('Maximum error on the tassellation: ' + str(self.cvt_handler.max_error)) print('New baricentric parameter value added to the triangulation ' + str(self.cvt_handler.mu_values[:, -1]) + '\n')
def test_cvt_attributes_07b(self): mu_values = np.load('tests/test_datasets/mu_values_test.npy') snapshots = np.load('tests/test_datasets/snapshots_test_scalar.npy') cvt_handler = cvt.Cvt(mu_values, snapshots) expected_rel_error = 36.3507969 np.testing.assert_almost_equal(cvt_handler.rel_error, expected_rel_error)