Skip to content

Commit

Permalink
Revert "making the demos all work" (#102)
Browse files Browse the repository at this point in the history
* Revert "making the demos all work"

* commits that were reverted, readded, without reverting previous changes

* bump patch number
  • Loading branch information
jessdtate committed Mar 4, 2022
1 parent 42f3db4 commit e16b0ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions UncertainSCI/pce.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ def set_samples(self, samples):
'have wrong dimension')

self.samples = samples
self.set_weights()

def set_weights(self):
"""Sets weights based on assigned samples.
"""
if self.samples is None:
raise RuntimeError("PCE weights cannot be set unless samples are set first.""")

if self.sampling.lower() == 'greedy-induced':
self.weights = self.christoffel_weights()
elif self.sampling.lower() == 'gq':
M = self.sampling_options.get('M')
if M is None:
raise ValueError("The sampling option 'M' must be specified for Gauss quadrature sampling.")

_, self.weights = self.distribution.polys.tensor_gauss_quadrature(M)

elif self.sampling.lower() == 'gq-induced':
self.weights = self.christoffel_weights()

else:
raise ValueError("Unsupported sample type '{0}' for input\
sample_type".format(self.sampling))

def map_to_standard_space(self, q):
"""Maps parameter values from model space to standard space.
Expand Down Expand Up @@ -211,8 +234,6 @@ def generate_samples(self, **kwargs):

self.samples = self.map_to_model_space(x)

self.weights = self.christoffel_weights()

elif self.sampling.lower() == 'gq':

M = self.sampling_options.get('M')
Expand All @@ -221,7 +242,9 @@ def generate_samples(self, **kwargs):

p_standard, w = self.distribution.polys.tensor_gauss_quadrature(M)
self.samples = self.map_to_model_space(p_standard)
self.weights = w
# We do the following in the call to self.set_weights() below. A
# little more expensive, but makes for more transparent control structure.
#self.weights = w

elif self.sampling.lower() == 'gq-induced':

Expand All @@ -232,12 +255,13 @@ def generate_samples(self, **kwargs):
p_standard = self.distribution.opolys.idist_gq_sampling(K, self.indices, M=self.sampling_options.get('M'))

self.samples = self.map_to_model_space(p_standard)
self.weights = self.christoffel_weights()

else:
raise ValueError("Unsupported sample type '{0}' for input\
sample_type".format(self.sampling))

self.set_weights()

def integration_weights(self):
"""
Generates sample weights associated to integration."
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='UncertainSCI',
version='0.2.1-b0',
version='0.2.2-b0',
author='UncertainSCI Developers',
author_email='uncertainsci@sci.utah.edu',
packages=find_packages(),
Expand Down

0 comments on commit e16b0ad

Please sign in to comment.