From 61c5ffd806ed72a8242db072374c654e1b402ec7 Mon Sep 17 00:00:00 2001
From: faridm69 <faridmohammadi69@gmail.com>
Date: Sun, 17 May 2020 18:10:03 +0200
Subject: [PATCH] [bayesinference] replaced post predictive storage via feather
 with h5 files.

---
 BayesValidRox/BayesInference/BayesInference.py | 17 ++++++++---------
 BayesValidRox/PostProcessing/PostProcessing.py |  5 +++--
 README.md                                      |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/BayesValidRox/BayesInference/BayesInference.py b/BayesValidRox/BayesInference/BayesInference.py
index 19a06d293..074f6bea7 100644
--- a/BayesValidRox/BayesInference/BayesInference.py
+++ b/BayesValidRox/BayesInference/BayesInference.py
@@ -468,25 +468,26 @@ class BayesInference:
         
         
         # Prior Predictive
+        priorh5File = "priorPredictive.h5"
         for Out_idx, OutputName in enumerate(Model.Output.Names):
             PriorPred_dict = {} 
             PriorPred_dict[x_key] = X_values
             PriorPred_dict[OutputName] = PriorPred[OutputName].flatten('F')
             PriorPred_df = pd.DataFrame(PriorPred_dict)
-            PriorPred_df.to_feather(OutputDir+'/PriorPredictive_'+OutputName+'.ftr')
-        
+            PriorPred_df.to_hdf(OutputDir+'/'+priorh5File, "/data/"+OutputName)
         
         # Convert the array to a categorical data frame (PosteriorPredictive)
         # X_values
         X_values = np.repeat(MeasuredData[x_key] , PosteriorPred[Model.Output.Names[0]].shape[0])
         
         # Posterior Predictive
+        posth5File = "postPredictive.h5"
         for Out_idx, OutputName in enumerate(Model.Output.Names):
             PCEPosteriorPred_dict = {}
             PCEPosteriorPred_dict[x_key] = X_values
             PCEPosteriorPred_dict[OutputName] = PosteriorPred[OutputName].flatten('F')
             PosteriorPred_df = pd.DataFrame(PCEPosteriorPred_dict)
-            PosteriorPred_df.to_feather(OutputDir+'/PostPredictive_'+OutputName+'.ftr')
+            PosteriorPred_df.to_hdf(OutputDir+'/'+posth5File, "/data/"+OutputName)
             
         return
 
@@ -742,14 +743,12 @@ class BayesInference:
                     
                     # --- Read prior and posterior predictive ---
                     # Prior
-                    priorPred_df = pd.read_feather(OutputDir+'/PriorPredictive_'+OutputName+'.ftr',
-                                                   columns=None, use_threads=True)
+                    priorPred_df = pd.read_hdf(OutputDir+'/'+"priorPredictive.h5" ,'/data/'+OutputName)
                     tags_post = ['prior'] * len(priorPred_df)
                     priorPred_df.insert(len(priorPred_df.columns), "Tags", tags_post, True)
                     
                     # Posterir
-                    postPred_df = pd.read_feather(OutputDir+'/PostPredictive_'+OutputName+'.ftr',
-                                                  columns=None, use_threads=True)
+                    postPred_df = pd.read_hdf(OutputDir+'/'+"postPredictive.h5" ,'/data/'+OutputName)
                     tags_post = ['posterior'] * len(postPred_df)
                     postPred_df.insert(len(postPred_df.columns), "Tags", tags_post, True)
                     
@@ -769,7 +768,7 @@ class BayesInference:
                                   linestyles='', capsize=16, ax=ax) #
                     
                     ax.errorbar(x_coords, MAP_PCEModel[OutputName][0], 
-                                  yerr=2*MAP_PCEModelstd[OutputName][0],
+                                  yerr=1.96*MAP_PCEModelstd[OutputName][0],
                                   ecolor='lime', fmt=' ', zorder=-1)
                     
                     # --- Plot MAP (origModel) ---
@@ -784,7 +783,7 @@ class BayesInference:
                                   linestyles='', capsize=16, data=ObservationData, ax=ax)
 
                     ax.errorbar(x_coords, ObservationData[OutputName].to_numpy(), 
-                                  yerr=2*self.MeasurementError[OutputName].to_numpy(),
+                                  yerr=1.96*self.MeasurementError[OutputName].to_numpy(),
                                   ecolor='g', fmt=' ', zorder=-1)
                     
                     # Add labels to the legend
diff --git a/BayesValidRox/PostProcessing/PostProcessing.py b/BayesValidRox/PostProcessing/PostProcessing.py
index e7730e462..02dd0b5d0 100644
--- a/BayesValidRox/PostProcessing/PostProcessing.py
+++ b/BayesValidRox/PostProcessing/PostProcessing.py
@@ -567,7 +567,8 @@ class PostProcessing:
                 
                 plt.plot(x_values, Y_PC_Val_[idx,:], color=Color, marker=Marker, linestyle='--', label='$Y_{%s}^{PCE}$'%(idx+1))
                 #plt.errorbar(x_values, Y_PC_Val_[idx,:], 2*Y_PC_Val_std_[idx,:], color=Color, marker=Marker, linestyle='--')
-                plt.fill_between(x_values, Y_PC_Val_[idx,:]-2*Y_PC_Val_std_[idx,:], Y_PC_Val_[idx,:]+2*Y_PC_Val_std_[idx,:], color=Color,alpha=0.15)
+                plt.fill_between(x_values, Y_PC_Val_[idx,:]-1.96*Y_PC_Val_std_[idx,:], 
+                                 Y_PC_Val_[idx,:]+1.96*Y_PC_Val_std_[idx,:], color=Color,alpha=0.15)
                 
             plt.ylabel(key)
             plt.xlabel(x_axis)
@@ -578,7 +579,7 @@ class PostProcessing:
             
             if SaveFig is True:
                 # ---------------- Saving the figure and text files -----------------------
-                newpath = (r'Outputs_PostPorecessing') 
+                newpath = (r'Outputs_PostProcessing') 
                 if not os.path.exists(newpath): os.makedirs(newpath)
                 plt.savefig('./'+newpath+'/Model_vs_PCEModel_'+key+'.svg',
                             bbox_inches='tight')   # save the figure to file
diff --git a/README.md b/README.md
index 2f10f31c8..8f782586c 100644
--- a/README.md
+++ b/README.md
@@ -8,4 +8,4 @@ Validation Benchmark
 * seaborn
 * emcee
 * chaospy
-* pyarrow
+* pytables
-- 
GitLab