Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/decrease needed memory (Issue 404) #405

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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