Skip to content

Commit 42f3db4

Browse files
authored
Merge pull request #99 from SCIInstitute/exp_dist_fix
making the demos all work
2 parents 5a8e061 + cef4562 commit 42f3db4

File tree

5 files changed

+11
-41
lines changed

5 files changed

+11
-41
lines changed

UncertainSCI/distributions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def __init__(self, flag=True, lbd=None, loc=None, mean=None,
281281
self.transform_standard_dist_to_poly = AffineTransform(A=A, b=b)
282282

283283
if self.dim == 1:
284-
A = lbd
284+
A = np.array(lbd)
285285
b = -A * loc
286286
self.transform_to_standard = AffineTransform(A=A, b=b)
287287

UncertainSCI/pce.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,6 @@ def set_samples(self, samples):
143143
'have wrong dimension')
144144

145145
self.samples = samples
146-
self.set_weights()
147-
148-
def set_weights(self):
149-
"""Sets weights based on assigned samples.
150-
"""
151-
if self.samples is None:
152-
raise RuntimeError("PCE weights cannot be set unless samples are set first.""")
153-
154-
if self.sampling.lower() == 'greedy-induced':
155-
self.weights = self.christoffel_weights()
156-
elif self.sampling.lower() == 'gq':
157-
M = self.sampling_options.get('M')
158-
if M is None:
159-
raise ValueError("The sampling option 'M' must be specified for Gauss quadrature sampling.")
160-
161-
_, self.weights = self.distribution.polys.tensor_gauss_quadrature(M)
162-
163-
elif self.sampling.lower() == 'gq-induced':
164-
self.weights = self.christoffel_weights()
165-
166-
else:
167-
raise ValueError("Unsupported sample type '{0}' for input\
168-
sample_type".format(self.sampling))
169146

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

235212
self.samples = self.map_to_model_space(x)
236213

214+
self.weights = self.christoffel_weights()
215+
237216
elif self.sampling.lower() == 'gq':
238217

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

243222
p_standard, w = self.distribution.polys.tensor_gauss_quadrature(M)
244223
self.samples = self.map_to_model_space(p_standard)
245-
# We do the following in the call to self.set_weights() below. A
246-
# little more expensive, but makes for more transparent control structure.
247-
#self.weights = w
224+
self.weights = w
248225

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

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

257234
self.samples = self.map_to_model_space(p_standard)
235+
self.weights = self.christoffel_weights()
258236

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

263-
self.set_weights()
264-
265241
def integration_weights(self):
266242
"""
267243
Generates sample weights associated to integration."

demos/anisotropic_distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
model = sine_modulation(N=N)
3535

3636
# Compute PCE (runs model)
37-
lsq_residuals = pce.build_pce_wafp(model)
37+
lsq_residuals = pce.build(model, oversampling=10)
3838

3939
Q = 6 # Number of quantile bands to plot
4040

demos/quantiles.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from UncertainSCI.indexing import TotalDegreeSet
99
from UncertainSCI.pce import PolynomialChaosExpansion
1010

11+
from UncertainSCI.vis import quantile_plot
12+
1113
# Number of parameters
1214
dimension = 3
1315

@@ -35,7 +37,7 @@
3537
model = sine_modulation(N=N)
3638

3739
# Compute PCE (runs model)
38-
lsq_residuals = pce.build_pce_wafp(model)
40+
lsq_residuals = pce.build(model)
3941

4042
Q = 6 # Number of quantile bands to plot
4143

@@ -57,16 +59,8 @@
5759
for j in range(M):
5860
output[j, :] = model(p_phys[j, :])
5961

62+
quantile_plot(pce, bands=3, xvals=x, xlabel='$x$')
6063
plt.plot(x, output[:M, :].T, 'k', alpha=0.8, linewidth=0.2)
61-
plt.plot(x, median, 'b', label='PCE median')
62-
63-
for ind in range(Q):
64-
alpha = (Q-ind) * 1/Q - (1/(2*Q))
65-
plt.fill_between(x, quantiles_lower[ind, :], quantiles_upper[ind, :],
66-
interpolate=True, facecolor='red', alpha=alpha)
67-
68-
plt.xlabel('x')
6964

70-
plt.legend(loc='lower right')
7165

7266
plt.show()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='UncertainSCI',
8-
version='0.2.0-b0',
8+
version='0.2.1-b0',
99
author='UncertainSCI Developers',
1010
author_email='[email protected]',
1111
packages=find_packages(),

0 commit comments

Comments
 (0)