Skip to content
Snippets Groups Projects
Commit a8559643 authored by Jan Habscheid's avatar Jan Habscheid
Browse files

Fix theoretical POD error by using test data

parent 84d89092
No related branches found
No related tags found
1 merge request!7Examples microstructures
Showing
with 46 additions and 30 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -90,7 +90,8 @@ for R_ in R:
test_velocity_predict, test_pressure_predict = RegressionModel.POD(
R_velocity=R_,
R_pressure=R_,
scaled=False
scaled=False,
testdata=True
)
# Iterate over each testcase
......
This diff is collapsed.
......@@ -79,7 +79,8 @@ class RegressionModels:
self,
R_velocity=None,
R_pressure=None,
scaled=True
scaled=True,
testdata=False
) -> Tuple[np.ndarray, np.ndarray]:
'''
Perform Proper Orthogonal Decomposition (POD) on the velocity and pressure fields.
......@@ -94,6 +95,8 @@ class RegressionModels:
Number of modes for the pressure field, by default None
scaled : bool, optional
Use scaled data, by default True
testdata : bool, optional
Use test data, by default True
Returns
-------
......@@ -105,13 +108,25 @@ class RegressionModels:
if R_pressure is None:
_, R_pressure = self.elbow_point(scaled=True)
# Perform SVD
if scaled:
U_velocity, S_velocity, V_velocity = np.linalg.svd(self.velocity_matrix_scaled_train)
U_pressure, S_pressure, V_pressure = np.linalg.svd(self.pressure_matrix_scaled_train)
if testdata:
if scaled:
velocity_matrix = self.velocity_matrix_scaled_test
pressure_matrix = self.pressure_matrix_scaled_test
else:
velocity_matrix = self.velocity_matrix_test
pressure_matrix = self.pressure_matrix_test
else:
U_velocity, S_velocity, V_velocity = np.linalg.svd(self.velocity_matrix_train)
U_pressure, S_pressure, V_pressure = np.linalg.svd(self.pressure_matrix_train)
if scaled:
velocity_matrix = self.velocity_matrix_scaled_train
pressure_matrix = self.pressure_matrix_scaled_train
else:
velocity_matrix = self.velocity_matrix_train
pressure_matrix = self.pressure_matrix_train
# Get the splitted matrices
U_velocity, S_velocity, V_velocity = np.linalg.svd(velocity_matrix)
U_pressure, S_pressure, V_pressure = np.linalg.svd(pressure_matrix)
# Extract reduced matrices
U_r_velocity = U_velocity[:, :R_velocity]
S_r_velocity = np.diag(S_velocity[:R_velocity])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment