Skip to content

Commit

Permalink
New functions for PCE basis
Browse files Browse the repository at this point in the history
  • Loading branch information
NovakLBUT authored Apr 18, 2023
1 parent d8f2de0 commit fd26576
Showing 1 changed file with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import scipy.integrate as integrate
from beartype import beartype

from scipy import stats as stats
from UQpy.distributions.baseclass import Distribution
import warnings

Expand All @@ -25,6 +25,64 @@ def __init__(self, distributions: Union[Distribution, list[Distribution]], degre
"""
self.distributions = distributions
self.degree = degree + 1

@staticmethod
def standardize_sample(x,joint_distribution):
"""
Static method: Standardize data based on the joint probability distribution.
:param x: Input data generated from a joint probability distribution.
:param joint_distribution: joint probability distribution from :py:mod:`UQpy` distribution object
:return: Standardized data.
"""


s=np.zeros(x.shape)
inputs_number = len(x[0,:])
if inputs_number == 1:
marginals = [joint_distribution]
else:
marginals = joint_distribution.marginals

for i in range (inputs_number):
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:
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

@staticmethod
def standardize_pdf(x,joint_distribution):
"""
Static method: PDF of standardized distributions associated to Hermite or Legendre polynomials.
:param x: Input data generated from a joint probability distribution
:param joint_distribution: joint probability distribution from :py:mod:`UQpy` distribution object
:return: Value of standardized PDF calculated for x
"""

inputs_number = len(x[0,:])
pdf_val=1
s=Polynomials.standardize_sample(x,joint_distribution)

if inputs_number == 1:
marginals = [joint_distribution]
else:
marginals = joint_distribution.marginals

for i in range (inputs_number):
if type(marginals[i]) == Normal:
pdf_val = pdf_val * (stats.norm.pdf(s[:,i]))
if type(marginals[i]) == Uniform:
pdf_val = 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")
return pdf_val

@staticmethod
def standardize_normal(tensor: np.ndarray, mean: float, std: float):
Expand Down Expand Up @@ -111,4 +169,4 @@ def scale(self):
def evaluate(self, x: np.ndarray):
pass

distribution_to_polynomial = { }
distribution_to_polynomial = { }

0 comments on commit fd26576

Please sign in to comment.