@@ -99,7 +99,12 @@ def predict(self, mu):
9999 :rtype: Database
100100 """
101101 mu = np .atleast_2d (mu )
102-
102+
103+ for plugin in self .plugins :
104+ if plugin .target == 'parameters' :
105+ mu = plugin .scaler .transform (mu )
106+
107+
103108 self ._reduced_database = Database (
104109 mu , np .atleast_2d (self .approximation .predict (mu )))
105110
@@ -312,3 +317,107 @@ def _simplex_volume(self, vertices):
312317 distance = np .transpose ([vertices [0 ] - vi for vi in vertices [1 :]])
313318 return np .abs (
314319 np .linalg .det (distance ) / math .factorial (vertices .shape [1 ]))
320+
321+ def reconstruction_error (self , db = None , relative = True , eps = 1e-12 ):
322+ """
323+ Calculate the reconstruction error between the original snapshots and
324+ the ones reconstructed by the ROM.
325+
326+ :param database.Database db: the database to use to compute the error.
327+ If None, the error is computed on the training database.
328+ Default is None.
329+ :param bool relative: True if the error computed is relative. Default is
330+ True.
331+ :param float eps: small number to avoid division by zero in relative
332+ error computation. Default is 1e-12.
333+ :return: the vector containing the reconstruction errors.
334+
335+ Esempio:
336+ >>> from ezyrb import ReducedOrderModel as ROM
337+ >>> from ezyrb import POD, RBF, Database
338+ >>> db = Database(param, snapshots) # param and snapshots are assumed
339+ to be declared
340+ >>> db_train = db[:10] # training database
341+ >>> db_test = db[10:] # test database
342+ >>> pod = POD()
343+ >>> rbf = RBF()
344+ >>> rom = ROM(db_train, pod, rbf)
345+ >>> rom.fit()
346+ >>> err_train_reduct = rom.reconstruction_error(relative=True)
347+ >>> err_test_reduct = rom.reconstruction_error(db_test, relative=True)
348+ """
349+
350+ errs = []
351+ if db is None :
352+ db = self .database
353+ snap = db .snapshots_matrix
354+ snap_red = self .reduction .transform (snap .T )
355+ snap_full = self .reduction .inverse_transform (snap_red ).T
356+
357+ E = snap - snap_full
358+
359+ if relative :
360+ num = np .linalg .norm (E , axis = 1 )
361+ den = np .linalg .norm (snap , axis = 1 ) + eps
362+
363+ err = float (np .mean (num / den ))
364+ else :
365+ err = float (np .mean (np .linalg .norm (E , axis = 1 )))
366+ errs .append (err )
367+
368+ return np .array (errs )
369+
370+ def approximation_error (self , db = None , relative = True , eps = 1e-12 ):
371+ """
372+ Calculate the approximation error between the true modal coefficients
373+ and the approximated ones.
374+
375+ :param database.Database db: the database to use to compute the error.
376+ If None, the error is computed on the training database.
377+ Default is None.
378+ :param bool relative: True if the error computed is relative. Default is
379+ True.
380+ :param float eps: small number to avoid division by zero in relative
381+ error computation. Default is 1e-12.
382+
383+ :return: the vector containing the approximation errors.
384+
385+ Esempio:
386+ >>> from ezyrb import ReducedOrderModel as ROM
387+ >>> from ezyrb import POD, RBF, Database
388+ >>> db = Database(param, snapshots) # param and snapshots are assumed
389+ to be declared
390+ >>> db_train = db[:10] # training database
391+ >>> db_test = db[10:] # test database
392+ >>> pod = POD()
393+ >>> rbf = RBF()
394+ >>> rom = ROM(db_train, pod, rbf)
395+ >>> rom.fit()
396+ >>> err_train_approx = rom.approximation_error(relative=True)
397+ >>> err_test_approx = rom.approximation_error(db_test, relative=True)
398+
399+ """
400+ errs = []
401+ if db is None :
402+ db = self .database
403+
404+ snap = db .snapshots_matrix
405+ params_true = self .reduction .transform (snap .T ).T
406+
407+ params = db .parameters_matrix
408+
409+ params_approx = self .approximation .predict (params )
410+
411+ E = params_true - params_approx
412+
413+ if relative :
414+ num = np .linalg .norm (E , axis = 1 )
415+ den = np .linalg .norm (params_true , axis = 1 ) + eps
416+
417+ err = float (np .mean (num / den ))
418+ else :
419+ err = float (np .mean (np .linalg .norm (E , axis = 1 )))
420+ errs .append (err )
421+
422+ return np .array (errs )
423+
0 commit comments