Skip to content

Commit

Permalink
Updates standardization code for Uniform and Normal
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed Apr 24, 2023
1 parent e059b2e commit 36269b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
17 changes: 8 additions & 9 deletions docs/source/sampling/theta_criterion.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
Theta Criterion
---------------


ThetaCriterionPCE Class
^^^^^^^^^^^^^^^^^^^^^^^^

The technique enables one-by-one extension of an experimental design while trying to obtain an optimal sample at each stage of the adaptive sequential surrogate model
construction process. The sequential sampling strategy based on :math:`\Theta` criterion selects from a pool of candidate points by trying to cover the design domain
proportionally to their local variance contribution. The proposed criterion for the sample selection balances both exploitation of the surrogate model using variance
density derived analytically from Polynomial Chaos Expansion and exploration of the design domain. The active learning technique based on :math:`\Theta` criterion can be
construction process. The sequential sampling strategy based on :math:`\Theta` criterion selects from a pool of candidate points by trying to cover the design domain
proportionally to their local variance contribution. The proposed criterion for the sample selection balances both exploitation of the surrogate model using variance
density derived analytically from Polynomial Chaos Expansion and exploration of the design domain. The active learning technique based on :math:`\Theta` criterion can be
combined with arbitrary sampling technique employed for construction of a pool of candidate points. More details can be found in:

L. Novák, M. Vořechovský, V. Sadílek, M. D. Shields, *Variance-based adaptive sequential sampling for polynomial chaos expansion*,
L. Novák, M. Vořechovský, V. Sadílek, M. D. Shields, *Variance-based adaptive sequential sampling for polynomial chaos expansion*,
637 Computer Methods in Applied Mechanics and Engineering 386 (2021) 114105. doi:10.1016/j.cma.2021.114105


ThetaCriterionPCE Class
^^^^^^^^^^^^^^^^^^^^^^^^

The :class:`.ThetaCriterionPCE` class is imported using the following command:

>>> from UQpy.sampling.ThetaCriterionPCE import ThetaCriterionPCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ def standardize_sample(x, joint_distribution):
if type(marginals[i]) == Normal:
s[:, i] = Polynomials.standardize_normal(x[:, i], mean=marginals[i].parameters['loc'],
std=marginals[i].parameters['scale'])

if type(marginals[i]) == Uniform:
elif type(marginals[i]) == Uniform:
s[:, i] = Polynomials.standardize_uniform(x[:, i], marginals[i])

else:
raise TypeError("standarize_sample is defined only for Uniform and Gaussian marginal distributions")
return s
Expand All @@ -77,7 +75,7 @@ def standardize_pdf(x, joint_distribution):
for i in range(inputs_number):
if type(marginals[i]) == Normal:
pdf_val *= (stats.norm.pdf(s[:, i]))
if type(marginals[i]) == Uniform:
elif type(marginals[i]) == Uniform:
pdf_val *= (stats.uniform.pdf(s[:, i], loc=-1, scale=2))
else:
raise TypeError("standardize_pdf is defined only for Uniform and Gaussian marginal distributions")
Expand Down
21 changes: 11 additions & 10 deletions tests/unit_tests/surrogates/test_pce.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,35 +405,36 @@ def test_22():
pos = ThetaSampling_complete.run(adapted_x, candidates_x, nsamples=2)
best_candidates = candidates_x[pos, :]
assert best_candidates[0, 0] == 1.1 and best_candidates[1, 0] == 9



def test_23():
"""
Test Standardization of sample and associated PDF
"""
dist1 = Uniform(loc=0, scale=10)
dist1 = Uniform(loc=0, scale=10)
dist2 = Normal(loc=6, scale=2)
marg = [dist1, dist2]
joint = JointIndependent(marginals=marg)

polynomial_basis = TotalDegreeBasis(joint, max_degree)
least_squares = LeastSquareRegression()
pce = PolynomialChaosExpansion(polynomial_basis=polynomial_basis, regression_method=least_squares)
X=np.zeros((3, 2))
X = np.zeros((3, 2))
X[:, 1] = np.array([0, 6, 10])
X[:, 0] = np.array([0, 5, 10])

pce.fit(X, X)
standardized_samples=polynomial_chaos.Polynomials.standardize_sample(X,pce.polynomial_basis.distributions)
standardized_pdf=polynomial_chaos.Polynomials.standardize_pdf(X,pce.polynomial_basis.distributions)

standardized_samples = polynomial_chaos.Polynomials.standardize_sample(X, pce.polynomial_basis.distributions)
standardized_pdf = polynomial_chaos.Polynomials.standardize_pdf(X, pce.polynomial_basis.distributions)

ref_sample1 = np.array([-1, 0, 1])
ref_pdf1 = np.array([0.5, 0.5, 0.5])
ref_sample2 = np.array([-3, 0, 2])
ref_pdf2 = stats.norm.pdf(ref_sample2)

ref_sample = np.zeros((3, 2))
ref_sample[:, 0] = ref_sample1
ref_sample[:, 1] = ref_sample2
ref_pdf = ref_pdf1 * ref_pdf2
assert (standardized_samples==ref_sample).all() and (standardized_pdf==ref_pdf).all()
assert (standardized_samples == ref_sample).all() and (standardized_pdf == ref_pdf).all()

0 comments on commit 36269b1

Please sign in to comment.