diff --git a/src/bayesvalidrox/post_processing/post_processing.py b/src/bayesvalidrox/post_processing/post_processing.py index e09904f48469474528a56a7096b103f2b84db2f5..62230a3784069329ccf8c2039476e6ba9c5e05d4 100644 --- a/src/bayesvalidrox/post_processing/post_processing.py +++ b/src/bayesvalidrox/post_processing/post_processing.py @@ -17,12 +17,11 @@ from matplotlib.patches import Patch plt.style.use(os.path.join(os.path.split(__file__)[0], '../', 'bayesvalidrox.mplstyle')) - class PostProcessing: """ This class provides many helper functions to post-process the trained meta-model. - + Parameters ---------- engine : obj @@ -30,14 +29,14 @@ class PostProcessing: name : string Name of the PostProcessing object to be used for saving the generated files. The default is 'calib'. - out_dir : string - Output directory in which the images are placed. The default is ''. - + """ def __init__(self, engine, name='calib', out_dir=''): self.engine = engine self.name = name + + self.out_dir = f'./{out_dir}/Outputs_PostProcessing_{self.name}/' @@ -59,7 +58,7 @@ class PostProcessing: self.pce_out_std = None # ------------------------------------------------------------------------- - def plot_moments(self, xlabel: str = 'Time [s]', plot_type: str = None): + def plot_moments(self, xlabel:str='Time [s]', plot_type:str=None): """ Plots the moments in a pdf format in the directory `Outputs_PostProcessing`. @@ -546,7 +545,6 @@ class PostProcessing: ------ AttributeError MetaModel in given Engine needs to be of type 'pce' or 'apce'. - Returns ------- sobol_cell: dict @@ -556,21 +554,12 @@ class PostProcessing: """ # This function currently only supports PCE/aPCE -<<<<<<< HEAD metamod = self.engine.MetaModel if not hasattr(metamod, 'meta_model_type'): raise AttributeError('Sobol indices only support PCE-type models!') if metamod.meta_model_type.lower() not in ['pce', 'apce']: raise AttributeError('Sobol indices only support PCE-type models!') -======= - PCEModel = self.engine.MetaModel - if not hasattr(PCEModel, 'meta_model_type'): - raise AttributeError('Sobol indices only support PCE-type models!') - if PCEModel.meta_model_type.lower() not in ['pce', 'apce']: - raise AttributeError('Sobol indices only support PCE-type models!') - ->>>>>>> 55b69984 ([tests] Add some PCE PostProcessing tests) # Extract the necessary variables basis_dict = metamod._basis_dict coeffs_dict = metamod._coeffs_dict @@ -849,11 +838,8 @@ class PostProcessing: return self.total_sobol # ------------------------------------------------------------------------- -<<<<<<< HEAD - def check_reg_quality(self, n_samples: int = 1000, samples=None, outputs: dict = None) -> None: -======= - def check_reg_quality(self, n_samples=1000, samples=None, outputs=None): ->>>>>>> 4281a0b3 ([fix] Add output-option to check_reg_quality) + def check_reg_quality(self, n_samples:int=1000, samples=None, outputs:dict=None)->None: + """ Checks the quality of the metamodel for single output models based on: https://towardsdatascience.com/how-do-you-check-the-quality-of-your-regression-model-in-python-fa61759ff685 @@ -881,11 +867,7 @@ class PostProcessing: # Evaluate the original and the surrogate model if outputs is None: y_val = self._eval_model(samples, key_str='valid') -<<<<<<< HEAD else: -======= - else: ->>>>>>> 4281a0b3 ([fix] Add output-option to check_reg_quality) y_val = outputs y_pce_val, _ = self.engine.eval_metamodel(samples=samples) @@ -977,7 +959,6 @@ class PostProcessing: plt.close() # ------------------------------------------------------------------------- -<<<<<<< HEAD def plot_metamodel_3d(self, n_samples=10): """ Visualize the results of a PCE MetaModel as a 3D surface over two input @@ -992,18 +973,6 @@ class PostProcessing: ------ AttributeError This function is only applicable if the MetaModel input dimension is 2. -======= - def eval_pce_model_3d(self): - # This function currently only supports PCE/aPCE - PCEModel = self.engine.MetaModel - if not hasattr(PCEModel, 'meta_model_type'): - raise AttributeError('This evaluation only support PCE-type models!') - if PCEModel.meta_model_type.lower() not in ['pce', 'apce']: - raise AttributeError('This evaluation only support PCE-type models!') - - self.n_samples = 1000 - n_samples = self.n_samples ->>>>>>> 55b69984 ([tests] Add some PCE PostProcessing tests) Returns ------- @@ -1098,7 +1067,6 @@ class PostProcessing: """ # This function currently only supports PCE/aPCE -<<<<<<< HEAD metamod = self.engine.MetaModel if not hasattr(metamod, 'meta_model_type'): raise AttributeError( @@ -1106,14 +1074,6 @@ class PostProcessing: if metamod.meta_model_type.lower() not in ['pce', 'apce']: raise AttributeError( 'This evaluation only support PCE-type models!') -======= - PCEModel = self.engine.MetaModel - if not hasattr(PCEModel, 'meta_model_type'): - raise AttributeError('This evaluation only support PCE-type models!') - if PCEModel.meta_model_type.lower() not in ['pce', 'apce']: - raise AttributeError('This evaluation only support PCE-type models!') - ->>>>>>> 55b69984 ([tests] Add some PCE PostProcessing tests) # get the samples y_pce_val = self.pce_out_mean @@ -1188,7 +1148,6 @@ class PostProcessing: """ # This function currently only supports PCE/aPCE -<<<<<<< HEAD metamod = self.engine.MetaModel if not hasattr(metamod, 'meta_model_type'): raise AttributeError( @@ -1196,17 +1155,6 @@ class PostProcessing: if metamod.meta_model_type.lower() not in ['pce', 'apce']: raise AttributeError( 'This evaluation only support PCE-type models!') -======= - PCEModel = self.engine.MetaModel - if not hasattr(PCEModel, 'meta_model_type'): - raise AttributeError('This evaluation only support PCE-type models!') - if PCEModel.meta_model_type.lower() not in ['pce', 'apce']: - raise AttributeError('This evaluation only support PCE-type models!') - - newpath = f'Outputs_PostProcessing_{self.name}/' - if not os.path.exists(newpath): - os.makedirs(newpath) ->>>>>>> 55b69984 ([tests] Add some PCE PostProcessing tests) # List of markers and colors color = cycle((['b', 'g', 'r', 'y', 'k']))