Skip to content

Commit

Permalink
Changes to resolve failing import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed Nov 20, 2023
1 parent e07eb59 commit 6f19146
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
17 changes: 5 additions & 12 deletions docs/source/surrogates/pce/physics_informed.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Physics-informed Polynomial Chaos Expansion
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Polynomial chaos expansion can be used in physics-informed machine learning as an efficient surrogate model allowing for
analytical uncertainty quantification. The PCE constrained to adhere to the known physics of the model (referenced as
(PC :math:`^2`), combines the conventional experimental design with additional constraints from the physics of the model.
Expand All @@ -25,10 +25,10 @@ The second class in the PC :math:`^2` framework is :class:`.PdePCE` containing P
in PCE context. The class is imported using the following command:


>>> from UQpy.surrogates.polynomial_chaos.physics_informed.PdePCE import PdeCE
>>> from UQpy.surrogates.polynomial_chaos.physics_informed.PdePCE import PdePCE


.. autoclass:: UQpy.surrogates.polynomial_chaos.physics_informed.PdePCE.PdePce
.. autoclass:: UQpy.surrogates.polynomial_chaos.physics_informed.PdePCE.PdePCE
:members:

ConstrainedPCE class
Expand All @@ -40,19 +40,12 @@ imported using the following command:
>>> from UQpy.surrogates.polynomial_chaos.physics_informed.ConstrainedPCE import ConstrainedPCE


.. autoclass:: UQpy.surrogates.polynomial_chaos.physics_informed.ConstrainedPCE.ConstrainedPce
.. autoclass:: UQpy.surrogates.polynomial_chaos.physics_informed.ConstrainedPCE.ConstrainedPCE
:members:











ReducedPCE Class
"""""""""""""""""""""""""""""""""""
Once the PC :math:`^2` is created, it can be easily exploited for UQ as standard PCE. However, since differential
Expand All @@ -64,7 +57,7 @@ The :class:`.ReducedPCE` class is imported using the following command:

>>> from UQpy.surrogates.polynomial_chaos.physics_informed.ReducedPCE import ReducedPCE

.. autoclass:: UQpy.surrogates.polynomial_chaos.physics_informed.ReducedPCE.ReducedPce
.. autoclass:: UQpy.surrogates.polynomial_chaos.physics_informed.ReducedPCE.ReducedPCE
:members:

Examples
Expand Down
1 change: 1 addition & 0 deletions src/UQpy/surrogates/polynomial_chaos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from UQpy.surrogates.polynomial_chaos.polynomials import *
from UQpy.surrogates.polynomial_chaos.regressions import *
from UQpy.surrogates.polynomial_chaos.physics_informed import *

from UQpy.surrogates.polynomial_chaos.PolynomialChaosExpansion import PolynomialChaosExpansion
from UQpy.surrogates.polynomial_chaos.polynomials.baseclass.Polynomials import Polynomials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from sklearn import linear_model as regresion
from UQpy.surrogates import *
import UQpy.surrogates.polynomial_chaos.physics_informed.Utilities as utils
from UQpy.surrogates.polynomial_chaos.physics_informed.Utilities import *
import copy
from UQpy.surrogates.polynomial_chaos.polynomials.baseclass.Polynomials import Polynomials
from UQpy.surrogates.polynomial_chaos.physics_informed.PdePCE import PdePCE
from UQpy.surrogates.polynomial_chaos.physics_informed.PdeData import PdeData
from beartype import beartype
Expand Down Expand Up @@ -79,7 +80,7 @@ def lar(self, n_PI: int = 50, virtual_niters: bool = False, max_niter: int = Non
pce = copy.deepcopy(self.initial_pce)

if self.pde_pce.virt_func is None:
virtual_samples = utils.ortho_grid(n_PI, pce.inputs_number, -1.0, 1.0)
virtual_samples = ortho_grid(n_PI, pce.inputs_number, -1.0, 1.0)
else:
virtual_x = self.pde_pce.virt_func(n_PI)
virtual_samples = polynomial_chaos.Polynomials.standardize_sample(virtual_x, pce.polynomial_basis.distributions)
Expand Down Expand Up @@ -210,7 +211,7 @@ def ols(self, pce: PolynomialChaosExpansion = None, nvirtual: int = -1, calc_coe
else:
virtual_x = self.pde_pce.virt_func(nvirtual)

virtual_s = polynomial_chaos.Polynomials.standardize_sample(virtual_x, pce.polynomial_basis.distributions)
virtual_s = Polynomials.standardize_sample(virtual_x, pce.polynomial_basis.distributions)

self.virtual_s = virtual_s
self.virtual_x = virtual_x
Expand All @@ -235,9 +236,9 @@ def ols(self, pce: PolynomialChaosExpansion = None, nvirtual: int = -1, calc_coe
samples = self.pde_data.get_bcsamples(self.pde_data.der_orders[i])
coord_x = samples[:, :-1]
bc_res = samples[:, -1]
coord_s = polynomial_chaos.Polynomials.standardize_sample(coord_x,
coord_s = Polynomials.standardize_sample(coord_x,
pce.polynomial_basis.distributions)
ac = utils.derivative_basis(coord_s, pce, derivative_order=self.pde_data.der_orders[i],
ac = derivative_basis(coord_s, pce, derivative_order=self.pde_data.der_orders[i],
leading_variable=int(leadvariable))
a_const.append(ac)
b_const.append(bc_res.reshape(-1, 1))
Expand Down Expand Up @@ -270,10 +271,10 @@ def ols(self, pce: PolynomialChaosExpansion = None, nvirtual: int = -1, calc_coe
if not return_coeff:
self.initial_pce.coefficients = a_opt_c
if self.pde_pce.virt_func is None:
standardized_sample = utils.ortho_grid(n_PI, pce.inputs_number, -1.0, 1.0)
standardized_sample = ortho_grid(n_PI, pce.inputs_number, -1.0, 1.0)
else:
virtual_x = self.pde_pce.virt_func(n_PI)
standardized_sample = polynomial_chaos.Polynomials.standardize_sample(virtual_x,
standardized_sample = Polynomials.standardize_sample(virtual_x,
pce.polynomial_basis.distributions)
err = self.estimate_error(self.initial_pce, standardized_sample)
self.ols_err = err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import copy
import UQpy.surrogates.polynomial_chaos.physics_informed.Utilities as utils
from beartype import beartype
from UQpy.surrogates.polynomial_chaos.PolynomialChaosExpansion import PolynomialChaosExpansion
from UQpy.surrogates.polynomial_chaos.polynomials.baseclass.PolynomialBasis import PolynomialBasis
from UQpy.surrogates.polynomial_chaos.polynomials.baseclass.Polynomials import Polynomials

class ReducedPCE:
@beartype
Expand Down Expand Up @@ -35,7 +38,7 @@ def __init__(self, pce: PolynomialChaosExpansion, n_deterministic: int, determin
determ_multi_index[:, determ_selection_mask] = self.original_multindex[:, determ_selection_mask]

self.determ_multi_index = determ_multi_index.astype(int)
self.determ_basis = polynomial_chaos.PolynomialBasis.construct_arbitrary_basis(self.nvar,
self.determ_basis = PolynomialBasis.construct_arbitrary_basis(self.nvar,
self.original_pce.polynomial_basis.distributions,
self.determ_multi_index)

Expand Down Expand Up @@ -73,7 +76,7 @@ def evaluate_coordinate(self, coordinates: np.ndarray, return_coefficients: bool
coord_x = np.zeros((1, self.nvar))
coord_x[0, self.determ_pos] = coordinates

determ_basis_eval = polynomial_chaos.PolynomialBasis(self.nvar, len(self.determ_multi_index),
determ_basis_eval = PolynomialBasis(self.nvar, len(self.determ_multi_index),
self.determ_multi_index, self.determ_basis,
self.original_pce.polynomial_basis.distributions).evaluate_basis(
coord_x)
Expand All @@ -95,7 +98,7 @@ def derive_coordinate(self, coordinates: np.ndarray, derivative_order: int, lead

coord_x = np.zeros((1, self.nvar))
coord_x[0, self.determ_pos] = coordinates
coord_s = polynomial_chaos.Polynomials.standardize_sample(coord_x,
coord_s = Polynomials.standardize_sample(coord_x,
self.original_pce.polynomial_basis.distributions)

determ_multi_index = np.zeros(self.original_multindex.shape)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import numpy as np
import UQpy.distributions.baseclass.Distribution
from UQpy.distributions.collection import Uniform, Normal
from scipy import special as sp
from scipy.special import legendre
from beartype import beartype
from UQpy.surrogates.polynomial_chaos.physics_informed.PdeData import PdeData
from UQpy.surrogates.polynomial_chaos.PolynomialChaosExpansion import PolynomialChaosExpansion
from UQpy.distributions.baseclass.Distribution import Distribution
from UQpy.distributions.collection.Normal import Normal
from UQpy.distributions.collection.Uniform import Uniform
from UQpy.surrogates import *
from UQpy.surrogates.polynomial_chaos.physics_informed.PdeData import PdeData
from scipy import special as sp


@beartype
Expand Down Expand Up @@ -70,7 +72,7 @@ def derivative_basis(standardized_sample: np.ndarray, pce: PolynomialChaosExpans

@beartype
def construct_basis(standardized_sample: np.ndarray, multindex: np.ndarray,
joint_distribution: UQpy.distributions.baseclass.Distribution,
joint_distribution: Distribution,
derivative_order: int = 0, leading_variable: int = 0):
"""
Construct and evaluate derivative basis.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from UQpy.surrogates.polynomial_chaos.physics_informed.ConstrainedPCE import ConstrainedPCE
from UQpy.surrogates.polynomial_chaos.physics_informed.PdeData import PdeData
from UQpy.surrogates.polynomial_chaos.physics_informed.PdePCE import PdePCE
from UQpy.surrogates.polynomial_chaos.physics_informed.ReducedPCE import ReducedPCE

0 comments on commit 6f19146

Please sign in to comment.