Skip to content

Commit

Permalink
Merge pull request #405 from UCL-CCS/feature/decrease_needed_memory
Browse files Browse the repository at this point in the history
Feature/decrease needed memory (Issue 404)
  • Loading branch information
DavidPCoster committed Oct 3, 2023
2 parents 253386d + e64a3db commit 0d27a63
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
35 changes: 35 additions & 0 deletions .readthedocs.yaml
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
28 changes: 22 additions & 6 deletions easyvvuq/analysis/pce_analysis.py
Expand Up @@ -182,7 +182,7 @@ def get_distribution(self, qoi):

class PCEAnalysis(BaseAnalysisElement):

def __init__(self, sampler=None, qoi_cols=None, sampling=False):
def __init__(self, sampler=None, qoi_cols=None, sampling=False, CorrelationMatrices=True, OutputDistributions=True):
"""Analysis element for polynomial chaos expansion (PCE).
Parameters
Expand All @@ -193,7 +193,13 @@ def __init__(self, sampler=None, qoi_cols=None, sampling=False):
Column names for quantities of interest (for which analysis is
performed).
sampling : True if chaospy sampling method to be used for calculating
statitical quantities; otherwise [default] the pce coefficients are used
statistical quantities; otherwise [default] the pce coefficients are used
CorrelationMatrices : boolean
if False then disable the calculation of the Correlation Matrices, otherwise
[default] calculate them
OutputDistributions : boolean
if False then disable the calculation of the Output Distributions, otherwise
[default] calculate them
"""

if sampler is None:
Expand All @@ -211,6 +217,8 @@ def __init__(self, sampler=None, qoi_cols=None, sampling=False):
self.sampling = sampling
self.output_type = OutputType.SUMMARY
self.sampler = sampler
self.CorrelationMatrices = CorrelationMatrices
self.OutputDistributions = OutputDistributions

def element_name(self):
"""Name for this element for logging purposes.
Expand Down Expand Up @@ -506,23 +514,31 @@ def build_surrogate_der(Y_hat, verbose=False):

# Correlation matrix
try:
warnings.warn(f"Skipping computation of cp.Corr", RuntimeWarning)
if self.sampler._is_dependent:
warnings.warn(f"Skipping computation of cp.Corr", RuntimeWarning)
results['correlation_matrices'][k] = None
else:
results['correlation_matrices'][k] = cp.Corr(fit, self.sampler.distribution)
if self.CorrelationMatrices:
results['correlation_matrices'][k] = cp.Corr(fit, self.sampler.distribution)
else:
warnings.warn(f"Skipping computation of cp.Corr", RuntimeWarning)
results['correlation_matrices'][k] = None
except Exception as e:
print ('Error %s for %s when computing cp.Corr()'% (e.__class__.__name__, k))
results['correlation_matrices'][k] = None


# Output distributions
try:
warnings.warn(f"Skipping computation of cp.QoI_Dist", RuntimeWarning)
if self.sampler._is_dependent:
warnings.warn(f"Skipping computation of cp.QoI_Dist", RuntimeWarning)
results['output_distributions'][k] = None
else:
results['output_distributions'][k] = cp.QoI_Dist( fit, self.sampler.distribution)
if self.OutputDistributions:
results['output_distributions'][k] = cp.QoI_Dist( fit, self.sampler.distribution)
else:
warnings.warn(f"Skipping computation of cp.QoI_Dist", RuntimeWarning)
results['output_distributions'][k] = None
except Exception as e:
print ('Error %s for %s when computing cp.QoI_Dist()'% (e.__class__.__name__, k))
# from traceback import print_exc
Expand Down

0 comments on commit 0d27a63

Please sign in to comment.