Skip to content

Commit

Permalink
Merge pull request #427 from UCL-CCS/feature_more_stats_in_qmc
Browse files Browse the repository at this point in the history
more stats for (q)mc
  • Loading branch information
DavidPCoster authored Dec 4, 2024
2 parents 1159d3b + 2023f72 commit 6cbc27e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
18 changes: 14 additions & 4 deletions easyvvuq/analysis/qmc_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ def supported_stats(self):
-------
list of str
"""
return ['mean', 'var', 'std', 'percentiles', '10%', '50%', '90%']
return ['mean', 'var', 'std', 'min', 'max', 'median', 'percentiles', '1%', '10%', '50%', '90%', '99%']

def _describe(self, qoi, statistic):
if statistic not in self.supported_stats():
raise NotImplementedError
if statistic == '1%':
return self.raw_data['percentiles'][qoi]['p1']
if statistic == '10%':
return self.raw_data['percentiles'][qoi]['p10']
elif statistic == '50%':
return self.raw_data['percentiles'][qoi]['p50']
elif statistic == '90%':
return self.raw_data['percentiles'][qoi]['p90']
elif statistic == '99%':
return self.raw_data['percentiles'][qoi]['p99']
else:
return self.raw_data['statistical_moments'][qoi][statistic][0]

Expand Down Expand Up @@ -206,10 +210,16 @@ def analyse(self, data_frame):

results['statistical_moments'][k] = {'mean': np.mean(masked_samples, axis=0),
'var': np.var(masked_samples, axis=0),
'std': np.std(masked_samples, axis=0)}
results['percentiles'][k] = {'p10': np.percentile(masked_samples, 10, 0)[0],
'std': np.std(masked_samples, axis=0),
'min': np.min(masked_samples, axis=0),
'max': np.max(masked_samples, axis=0),
'median': np.median(masked_samples, axis=0),
}
results['percentiles'][k] = {'p1': np.percentile(masked_samples, 1, 0)[0],
'p10': np.percentile(masked_samples, 10, 0)[0],
'p50': np.percentile(masked_samples, 50, 0)[0],
'p90': np.percentile(masked_samples, 90, 0)[0]}
'p90': np.percentile(masked_samples, 90, 0)[0],
'p99': np.percentile(masked_samples, 99, 0)[0]}

# Replace Nan values by the mean before proceeding with the SA
indices = np.where(mask == 0)[0] # samples[~mask] = results[k].mean
Expand Down
20 changes: 15 additions & 5 deletions tests/test_mc_analysis_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,28 @@ def test_describe(results_vectors):
results_vectors.describe()[
('g',
1)].to_dict() == {
'1%': 0.007945053328978277,
'10%': 0.08156520178597204,
'90%': 0.8729378821725343,
'90%': 0.8729378821725343,
'99%': 0.9950881374303691,
'max': 0.9983981908285983,
'mean': 0.4691844466934421,
'var': 0.08534945020531205,
'std': 0.29214628220347433})
'median': 0.4495551186167759,
'min': 0.0038532031638378594,
'std': 0.29214628220347433,
'var': 0.08534945020531205})
assert (
results_vectors.describe('h')[
('h',
1)].to_dict() == {
'1%': 0.039851582820686876,
'10%': 0.21724677702965456,
'90%': 0.9764815719704141,
'99%': 0.9969701901368494,
'max': 0.9993165378092128,
'mean': 0.6873389710989142,
'var': 0.07501266456861228,
'std': 0.27388440000958847})
'median': 0.7696583654805108,
'min': 0.01590577381510083,
'std': 0.27388440000958847,
'var': 0.07501266456861228})
assert (isinstance(results_vectors.describe('h', 'std'), np.ndarray))

0 comments on commit 6cbc27e

Please sign in to comment.