|
4 | 4 | import copy |
5 | 5 | import pickle |
6 | 6 | import numpy as np |
7 | | -from scipy.spatial.qhull import Delaunay |
| 7 | +from scipy.spatial import Delaunay |
8 | 8 | from sklearn.model_selection import KFold |
9 | 9 | from pycompss.api.api import compss_wait_on |
10 | 10 |
|
@@ -60,30 +60,32 @@ def fit(self, *args, **kwargs): |
60 | 60 | :param \*args: additional parameters to pass to the `fit` method. |
61 | 61 | :param \**kwargs: additional parameters to pass to the `fit` method. |
62 | 62 | """ |
63 | | - self.reduction.fit(self.database.snapshots.T) |
64 | | - reduced_output = self.reduction.transform( |
65 | | - self.database.snapshots.T, self.scaler_red |
66 | | - ) |
| 63 | + self.reduction.fit(self.database.snapshots_matrix.T) |
| 64 | + reduced_output = self.reduction.transform(self.database.snapshots_matrix.T).T |
67 | 65 |
|
68 | 66 | self.approximation.fit( |
69 | | - self.database.parameters, reduced_output, *args, **kwargs |
| 67 | + self.database.parameters_matrix, reduced_output, *args, **kwargs |
70 | 68 | ) |
71 | 69 |
|
72 | 70 | return self |
73 | 71 |
|
74 | 72 | def predict(self, mu): |
75 | | - """ |
76 | | - Calculate predicted solution for given mu |
| 73 | + r""" |
| 74 | + Predict the solution for given parameters mu. |
| 75 | + |
| 76 | + This method distributes the evaluation tasks across the |
| 77 | + available computational nodes using the PyCOMPSs framework. |
| 78 | +
|
| 79 | + :param numpy.ndarray mu: The parameters $\mu \in \mathbb{R}^d$ to evaluate. |
| 80 | + :return: The predicted snapshot $u(\mu)$. |
77 | 81 | """ |
78 | 82 | mu = np.atleast_2d(mu) |
79 | | - if hasattr(self, "database") and self.database.scaler_parameters: |
80 | | - mu = self.database.scaler_parameters.transform(mu) |
81 | | - |
82 | | - predicted_red_sol = self.approximation.predict(mu, self.scaler_red) |
| 83 | + |
| 84 | + predicted_red_sol = self.approximation.predict(mu) |
83 | 85 |
|
84 | 86 | predicted_sol = self.reduction.inverse_transform( |
85 | | - predicted_red_sol, self.database |
86 | | - ) |
| 87 | + predicted_red_sol.T |
| 88 | + ).T |
87 | 89 |
|
88 | 90 | return predicted_sol |
89 | 91 |
|
@@ -166,8 +168,8 @@ def kfold_cv_error(self, n_splits, *args, norm=np.linalg.norm, **kwargs): |
166 | 168 | ).fit(*args, **kwargs) |
167 | 169 |
|
168 | 170 | test = self.database[test_index] |
169 | | - predicted_test.append(rom.predict(test.parameters)) |
170 | | - original_test.append(test.snapshots) |
| 171 | + predicted_test.append(rom.predict(test.parameters_matrix)) |
| 172 | + original_test.append(test.snapshots_matrix) |
171 | 173 |
|
172 | 174 | predicted_test = compss_wait_on(predicted_test) |
173 | 175 | for j in range(len(predicted_test)): |
@@ -216,8 +218,8 @@ def loo_error(self, *args, norm=np.linalg.norm, **kwargs): |
216 | 218 | copy.deepcopy(self.approximation), |
217 | 219 | ).fit(*args, **kwargs) |
218 | 220 |
|
219 | | - predicted_test.append(rom.predict(test_db.parameters)) |
220 | | - original_test.append(test_db.snapshots) |
| 221 | + predicted_test.append(rom.predict(test_db.parameters_matrix)) |
| 222 | + original_test.append(test_db.snapshots_matrix) |
221 | 223 |
|
222 | 224 | predicted_test = compss_wait_on(predicted_test) |
223 | 225 | for j in range(len(predicted_test)): |
@@ -246,7 +248,7 @@ def optimal_mu(self, error=None, k=1): |
246 | 248 | if error is None: |
247 | 249 | error = self.loo_error() |
248 | 250 |
|
249 | | - mu = self.database.parameters |
| 251 | + mu = self.database.parameters_matrix |
250 | 252 | tria = Delaunay(mu) |
251 | 253 |
|
252 | 254 | error_on_simplex = np.array( |
|
0 commit comments