Functions

Note

The core interface of all essential functions are not dependent on specialized types such as AbstractOrthoPoly. Having said that, for exactly those essential functions, there exist overloaded functions that accept specialized types such as AbstractOrthoPoly as arguments.

Too abstract? For example, the function evaluate that evaluates a polynomial of degree n at points x has the core interface

    evaluate(n::Int,x::Array{<:Real},a::Vector{<:Real},b::Vector{<:Real})

where a and b are the vectors of recurrence coefficients. For simplicity, there also exists the interface

    evaluate(n::Int64,x::Vector{<:Real},op::AbstractOrthoPoly)

So fret not upon the encounter of multiple-dispatched versions of the same thing. It's there to simplify your life.

The idea of this approach is to make it simpler for others to copy and paste code snippets and use them in their own work.

List of all functions in PolyChaos.

Recurrence Coefficients for Monic Orthogonal Polynomials

The functions below provide analytic expressions for the recurrence coefficients of common orthogonal polynomials. All of these provide monic orthogonal polynomials relative to the weights.

Note

The number N of recurrence coefficients has to be positive for all functions below.

PolyChaos.r_scale — Function
r_scale(c::Real,β::AbstractVector{<:Real},α::AbstractVector{<:Real})

Given the recursion coefficients (α,β) for a system of orthogonal polynomials that are orthogonal with respect to some positive weight $m(t)$, this function returns the recursion coefficients (α_,β_) for the scaled measure $c m(t)$ for some positive $c$.

Arguments

  • c: positive scaling factor.
  • a, b: recurrence coefficient vectors for the original measure.

Returns

The unchanged a vector and the scaled b vector.

source
PolyChaos.rm_compute — Function
rm_compute(weight::Function,lb::Real,ub::Real,Npoly::Integer=4,Nquad::Integer=10;quadrature::Function=clenshaw_curtis)

Given a positive weight function with domain (lb,ub), i.e. a function $w: [lb, ub ] \rightarrow \mathbb{R}_{\geq 0}$, this function creates Npoly recursion coefficients (α,β).

The keyword quadrature specifies what quadrature rule is being used.

Arguments

  • weight: nonnegative weight function on (lb, ub), or an AbstractMeasure.
  • lb, ub: support bounds when weight is a function.
  • Npoly: number of recurrence coefficients to compute.
  • Nquad: number of quadrature nodes used for discretization.

Keywords

  • quadrature: quadrature rule used to discretize the weight.
  • discretization: recurrence algorithm, typically stieltjes or lanczos.

Returns

A pair (α, β) of monic recurrence coefficient vectors.

source
PolyChaos.rm_logistic — Function
rm_logistic(N::Integer)

Creates N recurrence coefficients for monic polynomials that are orthogonal on $(-\infty,\infty)$ relative to $w(t) = \frac{\mathrm{e}^{-t}}{(1 - \mathrm{e}^{-t})^2}$

Arguments

  • N: number of coefficients; must be nonnegative.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_hermite — Function
rm_hermite(N::Integer,mu::Real)
rm_hermite(N::Integer)

Creates N recurrence coefficients for monic generalized Hermite polynomials that are orthogonal on $(-\infty,\infty)$ relative to $w(t) = |t|^{2 \mu} \mathrm{e}^{-t^2}$

The call rm_hermite(N) is the same as rm_hermite(N,0).

Arguments

  • N: number of coefficients; must be nonnegative.
  • mu: generalized-Hermite parameter; must exceed -0.5.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_hermite_prob — Function
rm_hermite_prob(N::Integer)

Creates N recurrence coefficients for monic probabilists' Hermite polynomials that are orthogonal on $(-\infty,\infty)$ relative to $w(t) = \mathrm{e}^{-0.5t^2}$

Arguments

  • N: number of coefficients; must be nonnegative.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_laguerre — Function
rm_laguerre(N::Integer,a::Real)
rm_laguerre(N::Integer)

Creates N recurrence coefficients for monic generalized Laguerre polynomials that are orthogonal on $(0,\infty)$ relative to $w(t) = t^a \mathrm{e}^{-t}$.

The call rm_laguerre(N) is the same as rm_laguerre(N,0).

Arguments

  • N: number of coefficients; must be nonnegative.
  • a: generalized-Laguerre exponent; must exceed -1.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_legendre — Function
rm_legendre(N::Integer)

Creates N recurrence coefficients for monic Legendre polynomials that are orthogonal on $(-1,1)$ relative to $w(t) = 1$.

Arguments

  • N: number of coefficients; must be nonnegative.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_legendre01 — Function
rm_legendre01(N::Integer)

Creates N recurrence coefficients for monic Legendre polynomials that are orthogonal on $(0,1)$ relative to $w(t) = 1$.

Arguments

  • N: number of coefficients; must be nonnegative.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_jacobi — Function
rm_jacobi(N::Integer,a::Real,b::Real)
rm_jacobi(N::Integer,a::Real)
rm_jacobi(N::Integer)

Creates N recurrence coefficients for monic Jacobi polynomials that are orthogonal on $(-1,1)$ relative to $w(t) = (1-t)^a (1+t)^b$.

The call rm_jacobi(N,a) is the same as rm_jacobi(N,a,a) and rm_jacobi(N) the same as rm_jacobi(N,0,0).

Arguments

  • N: number of coefficients; must be nonnegative.
  • a, b: Jacobi exponents; each must exceed -1.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_jacobi01 — Function
rm_jacobi01(N::Integer,a::Real,b::Real)
rm_jacobi01(N::Integer,a::Real)
rm_jacobi01(N::Integer)

Creates N recurrence coefficients for monic Jacobi polynomials that are orthogonal on $(0,1)$ relative to $w(t) = (1-t)^a t^b$.

The call rm_jacobi01(N,a) is the same as rm_jacobi01(N,a,a) and rm_jacobi01(N) the same as rm_jacobi01(N,0,0).

Arguments

  • N: number of coefficients; must be nonnegative.
  • a, b: exponents in the weight on (0, 1); each must exceed -1.

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.rm_meixner_pollaczek — Function
rm_meixner_pollaczek(N::Integer,lambda::Real,phi::Real)
rm_meixner_pollaczek(N::Integer,lambda::Real)

Creates N recurrence coefficients for monic Meixner-Pollaczek polynomials with parameters λ and ϕ. These are orthogonal on $[-\infty,\infty]$ relative to the weight function $w(t)=(2 \pi)^{-1} \exp{(2 \phi-\pi)t} |\Gamma(\lambda+ i t)|^2$.

The call rm_meixner_pollaczek(n,lambda) is the same as rm_meixner_pollaczek(n,lambda,pi/2).

Arguments

  • N: number of coefficients; must be nonnegative.
  • lambda: positive shape parameter.
  • phi: angle parameter in (0, pi).

Returns

A pair (α, β) of recurrence coefficient vectors.

source
PolyChaos.stieltjes — Function
stieltjes(N::Int,nodes_::AbstractVector{<:Real},weights_::AbstractVector{<:Real};removezeroweights::Bool=true)

Stieltjes procedure—Given the nodes and weights, the function generates the firstN recurrence coefficients of the corresponding discrete orthogonal polynomials.

Set the Boolean removezeroweights to true if zero weights should be removed.

Arguments

  • N: number of recurrence coefficients to compute.
  • nodes, weights: paired nodes and positive discrete weights.

Keywords

  • removezeroweights: whether to discard entries whose weights are numerically zero.

Returns

A pair (α, β) of monic recurrence coefficient vectors.

source
PolyChaos.lanczos — Function
lanczos(N::Int,nodes::AbstractVector{<:Real},weights::AbstractVector{<:Real};removezeroweights::Bool=true)

Lanczos procedure—given the nodes and weights, the function generates the first N recurrence coefficients of the corresponding discrete orthogonal polynomials.

Set the Boolean removezeroweights to true if zero weights should be removed.

The script is adapted from the routine RKPW in W.B. Gragg and W.J. Harrod, The numerically stable reconstruction of Jacobi matrices from spectral data, Numer. Math. 44 (1984), 317-335.

Arguments

  • N: number of recurrence coefficients to compute.
  • nodes, weights: paired nodes and positive discrete weights.

Keywords

  • removezeroweights: whether to discard entries whose weights are numerically zero.

Returns

A pair (α, β) of monic recurrence coefficient vectors.

source
PolyChaos.mcdiscretization — Function
mcdiscretization(N::Int,quads::Vector{},discretemeasure::AbstractMatrix{<:Real}=zeros(0,2);discretization::Function=stieltjes,Nmax::Integer=300,ε::Float64=1e-8,gaussquad::Bool=false)

This routine returns $N$ recurrence coefficients of the polynomials that are orthogonal relative to a weight function $w$ that is decomposed as a sum of $m$ weights $w_i$ with domains $[a_i,b_i]$ for $i=1,\dots,m$,

\[w(t) = \sum_{i}^{m} w_i(t) \quad \text{with } \operatorname{dom}(w_i) = [a_i, b_i].\]

For each weight $w_i$ and its domain $[a_i, b_i]$ the function mcdiscretization() expects a quadrature rule of the form nodes::AbstractVector{<:Real}, weights::AbstractVector{<:Real} = myquadi(N::Int) all of which are stacked in the parameter quad quad = [ myquad1, ..., myquadm ] If the weight function has a discrete part (specified by discretemeasure) it is added on to the discretized continuous weight function.

The function mcdiscretization() performs a sequence of discretizations of the given weight $w(t)$, each discretization being followed by an application of the Stieltjes or Lanczos procedure (keyword discretization in [stieltjes, lanczos]) to produce approximations to the desired recurrence coefficients. The function applies to each subinterval $i$ an N-point quadrature rule (the $i$th entry of quad) to discretize the weight function $w_i$ on that subinterval. If the procedure converges to within a prescribed accuracy ε before N reaches its maximum allowed value Nmax. If the function does not converge, the function prompts an error message.

The keyword gaussquad should be set to true if Gauss quadrature rules are available for all$m$ weights $w_i(t)$ with $i = 1, \dots, m$.

For further information, please see W. Gautschi "Orthogonal Polynomials: Approximation and Computation", Section 2.2.4.

Arguments

  • N: number of recurrence coefficients to compute.
  • quads: quadrature data for the continuous components.
  • discretemeasure: optional two-column matrix of discrete nodes and weights.

Keywords

  • discretization: stieltjes or lanczos.
  • Nmax: maximum discretization size.
  • ε: convergence tolerance.
  • gaussquad: whether the supplied quadratures are Gaussian rules.
  • removezeroweights: whether zero quadrature weights are removed.

Returns

A pair (α, β) of monic recurrence coefficient vectors.

source

Show Orthogonal Polynomials

To get a human-readable output of the orthogonal polynomials, there is the function showpoly

PolyChaos.showpoly — Function
showpoly(coeffs::Vector{<:Real};sym::String,digits::Integer)

Show the monic polynomial with coefficients coeffs in a human-readable way.

Arguments

  • coeffs, α, β: polynomial coefficients or recurrence coefficients.
  • d: degree or range of degrees to print.
  • op: orthogonal-polynomial basis supplying recurrence coefficients.

Keywords

  • sym: variable name used in the printed polynomial.
  • digits: number of displayed decimal digits.

The keyword sym sets the name of the variable, and digits controls the number of shown digits.

julia> using PolyChaos

julia> showpoly([1.2, 2.3, 3.4456])
x^3 + 3.45x^2 + 2.3x + 1.2

julia> showpoly([1.2, 2.3, 3.4456], sym = "t", digits = 2)
t^3 + 3.45t^2 + 2.3t + 1.2
showpoly(d::Integer,α::Vector{<:Real},β::Vector{<:Real}; sym::String,digits::Integer)
showpoly(d::Range,α::Vector{<:Real},β::Vector{<:Real};sym::String,digits::Integer) where Range <: OrdinalRange

Show the monic polynomial of degree/range d that has the recurrence coefficients α, β.

julia> using PolyChaos

julia> α, β = rm_hermite(10);

julia> showpoly(3, α, β)
x^3 - 1.5x

julia> showpoly(0:2:10, α, β)
1
x^2 - 0.5
x^4 - 3.0x^2 + 0.75
x^6 - 7.5x^4 + 11.25x^2 - 1.88
x^8 - 14.0x^6 + 52.5x^4 - 52.5x^2 + 6.56
x^10 - 22.5x^8 + 157.5x^6 - 393.75x^4 + 295.31x^2 - 29.53

Tailored to types from PolyChaos.jl

showpoly(d::Union{Integer,Range},op::AbstractOrthoPoly;sym::String,digits::Integer) where Range <: OrdinalRange

Show the monic polynomial of degree/range d of an AbstractOrthoPoly.

julia> using PolyChaos

julia> op = GaussOrthoPoly(5);

julia> showpoly(3, op)
x^3 - 3.0x

julia> showpoly(0:(op.deg), op; sym = "t")
1
t
t^2 - 1.0
t^3 - 3.0t
t^4 - 6.0t^2 + 3.0
t^5 - 10.0t^3 + 15.0t

Thanks @pfitzseb for providing this functionality.

source

In case you want to see the entire basis, just use showbasis

PolyChaos.showbasis — Function
showbasis(α::Vector{<:Real},β::Vector{<:Real};sym::String,digits::Integer)

Show all basis polynomials given the recurrence coefficients α, β.

Arguments

  • α, β: recurrence coefficient vectors.
  • op: orthogonal-polynomial basis.

Keywords

  • sym: variable name used in the printed polynomial.
  • digits: number of displayed decimal digits.

The keyword sym sets the name of the variable, and digits controls the number of shown digits.

julia> using PolyChaos

julia> α, β = rm_hermite(5);

julia> showbasis(α, β)
1
x
x^2 - 0.5
x^3 - 1.5x
x^4 - 3.0x^2 + 0.75
x^5 - 5.0x^3 + 3.75x

Tailored to types from PolyChaos.jl

showbasis(op::AbstractOrthoPoly;sym::String,digits::Integer)

Show all basis polynomials of an AbstractOrthoPoly.

julia> using PolyChaos

julia> op = LegendreOrthoPoly(4);

julia> showbasis(op)
1
x
x^2 - 0.33
x^3 - 0.6x
x^4 - 0.86x^2 + 0.09
source

Both of these functions make excessive use of

PolyChaos.rec2coeff — Function
rec2coeff(deg::Int,a::Vector{<:Real},b::Vector{<:Real})
rec2coeff(a,b) = rec2coeff(length(a),a,b)

Get the coefficients of the orthogonal polynomial of degree up to deg specified by its recurrence coefficients (a,b). The function returns the values $c_i^{(k)}$ from

\[p_k (t) = t^d + \sum_{i=0}^{k-1} c_i t^i,\]

where $k$ runs from 1 to deg.

The call rec2coeff(a,b) outputs all possible recurrence coefficients given (a,b).

Arguments

  • deg: highest polynomial degree to return.
  • a, b: recurrence coefficient vectors.

Returns

A matrix of polynomial coefficients, one row for each degree.

source

Evaluate Orthogonal Polynomials

PolyChaos.evaluate — Function
evaluate(n, x, α, β)
evaluate(n, x, op::AbstractOrthoPoly)
evaluate(x, op::AbstractOrthoPoly)
evaluate(n, x, op::MultiOrthoPoly)
evaluate(x, mop::MultiOrthoPoly)

Evaluate monic orthogonal basis polynomials using their three-term recurrence. Univariate points can be scalars or vectors. For a MultiOrthoPoly, each row of a point matrix is one multivariate point and each row of an index matrix is one multi-index.

Arguments

  • n: polynomial degree for a univariate basis, or a multi-index for one multivariate basis polynomial.
  • ns: degrees of several univariate basis polynomials.
  • ind: matrix whose rows are the multi-indices of several multivariate basis polynomials.
  • x: evaluation point(s). A multivariate point matrix has one point per row and one variable per column.
  • α, β: recurrence coefficient vectors, or one vector per variable.
  • op, mop: univariate or multivariate orthogonal-polynomial basis.

Returns

Values of the requested basis polynomials. Evaluating all polynomials of op returns an array with one row per point and one column per degree.

Examples

julia> using PolyChaos

julia> evaluate(1, 0.5, LegendreOrthoPoly(2))
0.5
source

Scalar Products

PolyChaos.computeSP2 — Function
computeSP2(n::Integer,β::AbstractVector{<:Real})
computeSP2(n::Integer,op::AbstractOrthoPoly) = computeSP2(n,op.β)
computeSP2(op::AbstractOrthoPoly) = computeSP2(op.deg,op.β)

Computes the nregular scalar products aka 2-norms of the orthogonal polynomials, namely

\[\|ϕ_i\|^2 = \langle \phi_i,\phi_i\rangle \quad \forall i \in \{ 0,\dots,n \}.\]

Notice that only the values of β of the recurrence coefficients (α,β) are required. The computation is based on equation (1.3.7) from Gautschi, W. "Orthogonal Polynomials: Computation and Approximation". Whenever there exists an analytical expression for β, this function should be used.

The function is multiple-dispatched to facilitate its use with AbstractOrthoPoly.

Arguments

  • n: highest polynomial degree to include.
  • β: monic recurrence norm coefficients, or op supplying them.

Returns

A vector containing the squared norms from degree 0 through n, or the single scalar norm when n == 0.

source
PolyChaos.computeSP — Function
computeSP(a, α, β, nodes, weights; issymmetric = false)
computeSP(a, op::AbstractOrthoPoly)
computeSP(a, mop::MultiOrthoPoly)

Computes the scalar product

\[\langle \phi_{a_1},\phi_{a_2},\cdots,\phi_{a_n} \rangle,\]

where n = length(a). This requires to provide the recurrence coefficients (α,β) and the quadrature rule (nodes,weights), as well as the multi-index ind. If provided via the keyword issymmetric, symmetry of the weight function is exploited. All computations of the multivariate scalar products resort back to efficient computations of the univariate scalar products. Mathematically, this follows from Fubini's theorem.

The function is dispatched to facilitate its use with AbstractOrthoPoly and its quadrature rule Quad.

Arguments

  • a: zero-based polynomial degrees in the scalar product.
  • α, β: monic recurrence coefficients.
  • nodes, weights: quadrature data for the recurrence coefficients.
  • op, mop: univariate or multivariate orthogonal-polynomial basis.
  • ind: multivariate total-degree index matrix.

Keywords

  • issymmetric: symmetry flags used to eliminate odd products.
  • zerotol: absolute tolerance for zero multivariate factors.

Returns

The scalar product represented by the requested basis indices.

Note
  • Zero entries of $a$ are removed automatically to simplify computations, which follows from

\[\langle \phi_i, \phi_j, \phi_0,\cdots,\phi_0 \rangle = \langle \phi_i, \phi_j \rangle,\]

because \phi_0 = 1.

  • It is checked whether enough quadrature points are supplied to solve the integral exactly.
source

Quadrature Rules

PolyChaos.fejer — Function
fejer(N::Integer)

Fejer's first quadrature rule on (-1, 1).

Arguments

  • N: number of quadrature nodes; must be positive.

Returns

A pair (nodes, weights) containing N nodes and weights.

source
PolyChaos.quadgp — Function
quadgp(weight::Function,lb::Real,ub::Real,N::Integer=10;quadrature::Function=clenshaw_curtis,bnd::Float64=Inf)

general purpose quadrature based on Gautschi, "Orthogonal Polynomials: Computation and Approximation", Section 2.2.2, pp. 93-95

Compute the N-point quadrature rule for weight with support (lb, ub). The quadrature rule can be specified by the keyword quadrature. The keyword bnd sets the numerical value for infinity.

Arguments

  • weight: nonnegative weight function to integrate.
  • lb, ub: lower and upper support bounds.
  • N: number of quadrature nodes.

Keywords

  • quadrature: finite-interval rule used after mapping the support; defaults to clenshaw_curtis.
  • bnd: finite cutoff used to represent infinite bounds.

Returns

A pair (nodes, weights) for the requested support.

source
PolyChaos.gauss — Function
gauss(N::Integer,α::AbstractVector{<:Real},β::AbstractVector{<:Real})
gauss(α::AbstractVector{<:Real},β::AbstractVector{<:Real})
gauss(N::Integer,op::Union{OrthoPoly,AbstractCanonicalOrthoPoly})
gauss(op::Union{OrthoPoly,AbstractCanonicalOrthoPoly})

Gauss quadrature rule, also known as Golub-Welsch algorithm

gauss() generates the N Gauss quadrature nodes and weights for a given weight function. The weight function is represented by the N recurrence coefficients for the monic polynomials orthogonal with respect to the weight function.

Note

The function gauss accepts at most N = length(α) - 1 quadrature points, hence providing at most an (length(α) - 1)-point quadrature rule.

Note

If no N is provided, then N = length(α) - 1.

Arguments

  • N: requested number of nodes.
  • α, β: monic recurrence coefficients.
  • op: orthogonal-polynomial basis supplying α and β.

Returns

A pair (nodes, weights) for the Gaussian quadrature rule.

source
PolyChaos.radau — Function
radau(N::Integer,α::AbstractVector{<:Real},β::AbstractVector{<:Real},end0::Real)
radau(α::AbstractVector{<:Real},β::AbstractVector{<:Real},end0::Real)
radau(N::Integer,op::Union{OrthoPoly,AbstractCanonicalOrthoPoly},end0::Real)
radau(op::Union{OrthoPoly,AbstractCanonicalOrthoPoly},end0::Real)

Gauss-Radau quadrature rule. Given a weight function encoded by the recurrence coefficients (α,β)for the associated orthogonal polynomials, the function generates the nodes and weights (N+1)-point Gauss-Radau quadrature rule for the weight function having a prescribed node end0 (typically at one of the end points of the support interval of w, or outside thereof).

Note

The function radau accepts at most N = length(α) - 2 as an input, hence providing at most an (length(α) - 1)-point quadrature rule.

Note

Reference: OPQ: A MATLAB SUITE OF PROGRAMS FOR GENERATING ORTHOGONAL POLYNOMIALS AND RELATED QUADRATURE RULES by Walter Gautschi

Arguments

  • N: number of free nodes; the returned rule has N + 1 nodes.
  • α, β, op: recurrence coefficients or a basis supplying them.
  • end0: prescribed node, usually an endpoint of the support.

Returns

A pair (nodes, weights) for the Gauss-Radau rule.

source
PolyChaos.lobatto — Function
lobatto(N::Integer,α::AbstractVector{<:Real},β::AbstractVector{<:Real},endl::Real,endr::Real)
lobatto(α::AbstractVector{<:Real},β::AbstractVector{<:Real},endl::Real,endr::Real)
lobatto(N::Integer,op::Union{OrthoPoly,AbstractCanonicalOrthoPoly},endl::Real,endr::Real)
lobatto(op::Union{OrthoPoly,AbstractCanonicalOrthoPoly},endl::Real,endr::Real)

Gauss-Lobatto quadrature rule. Given a weight function encoded by the recurrence coefficients for the associated orthogonal polynomials, the function generates the nodes and weights of the (N+2)-point Gauss-Lobatto quadrature rule for the weight function, having two prescribed nodes endl, endr (typically the left and right end points of the support interval, or points to the left resp. to the right thereof).

Note

The function radau accepts at most N = length(α) - 3 as an input, hence providing at most an (length(α) - 1)-point quadrature rule.

Note

Reference: OPQ: A MATLAB SUITE OF PROGRAMS FOR GENERATING ORTHOGONAL POLYNOMIALS AND RELATED QUADRATURE RULES by Walter Gautschi

Arguments

  • N: number of free nodes; the returned rule has N + 2 nodes.
  • α, β, op: recurrence coefficients or a basis supplying them.
  • endl, endr: prescribed left and right nodes.

Returns

A pair (nodes, weights) for the Gauss-Lobatto rule.

source

Polynomial Chaos

PolyChaos.mean — Function

Univariate

mean(x::AbstractVector,op::AbstractOrthoPoly)

Multivariate

mean(x::AbstractVector,mop::MultiOrthoPoly)

compute mean of random variable with PCE x

For one-argument calls, mean(x) delegates to Statistics.mean.

Arguments

  • x: PCE coefficients.
  • op, mop: basis associated with the PCE.

Returns

The mean coefficient of the PCE, accounting for the basis normalization.

source
PolyChaos.var — Function

Univariate

var(x::AbstractVector,op::AbstractOrthoPoly)
var(x::AbstractVector,t2::Tensor)

Multivariate

var(x::AbstractVector,mop::MultiOrthoPoly)
var(x::AbstractVector,t2::Tensor)

compute variance of random variable with PCE x

For one-argument calls, var(x) delegates to Statistics.var.

Arguments

  • x: PCE coefficients.
  • op, mop, t2: basis or scalar-product tensor associated with the PCE.

Returns

The variance of the PCE.

source
PolyChaos.std — Function

Univariate

std(x::AbstractVector,op::AbstractOrthoPoly)

Multivariate

std(x::AbstractVector,mop::MultiOrthoPoly)

compute standard deviation of random variable with PCE x

For one-argument calls, std(x) delegates to Statistics.std.

Arguments

  • x: PCE coefficients.
  • op, mop: basis associated with the PCE.

Returns

The standard deviation of the PCE.

source
PolyChaos.sampleMeasure — Function

Univariate

sampleMeasure(n::Int,name::String,w::Function,dom::Tuple{<:Real,<:Real},symm::Bool,d::Dict;method::String="adaptiverejection")
sampleMeasure(n::Int,m::Measure;method::String="adaptiverejection")
sampleMeasure(n::Int,op::AbstractOrthoPoly;method::String="adaptiverejection")

Draw n samples from the measure m described by its

  • name
  • weight function w,
  • domain dom,
  • symmetry property symm,
  • and, if applicable, parameters stored in the dictionary d. By default, an adaptive rejection sampling method is used (from AdaptiveRejectionSampling.jl), unless it is a common random variable for which Distributions.jl is used.

The function is dispatched to accept AbstractOrthoPoly.

Multivariate

sampleMeasure(n::Int,m::ProductMeasure;method::Vector{String}=["adaptiverejection" for i=1:length(m.name)])
sampleMeasure(n::Int,mop::MultiOrthoPoly;method::Vector{String}=["adaptiverejection" for i=1:length(mop.meas.name)])

Multivariate extension, which provides an array of samples with n rows and as many columns as the multimeasure has univariate measures.

Arguments

  • n: number of samples to draw.
  • w, dom: weight function and its support.
  • meas, op, mop: measure, basis, or multivariate basis to sample.

Keywords

  • method: sampling method, such as "adaptiverejection" or "inversecdf"; multivariate calls accept one method per component.

Returns

A vector of n univariate samples, or an n-by-d matrix for a product measure with d components.

source
PolyChaos.evaluatePCE — Function
evaluatePCE(x::AbstractVector{<:Real},ξ::AbstractVector{<:Real},α::AbstractVector{<:Real},β::AbstractVector{<:Real})

Evaluation of polynomial chaos expansion

\[\mathsf{x} = \sum_{i=0}^{L} x_i \phi_i{\xi_j},\]

where L+1 = length(x) and $x_j$ is the $j$th sample where $j=1,\dots,m$ with m = length(ξ).

Arguments

  • x: PCE coefficients, ordered by polynomial degree.
  • ξ: sample points at which to evaluate the random variable.
  • α, β: recurrence coefficients of the basis.

Returns

The PCE value at each sample point in ξ.

source
PolyChaos.samplePCE — Function

Univariate

samplePCE(n::Int,x::AbstractVector{<:Real},op::AbstractOrthoPoly;method::String="adaptiverejection")

Combines sampleMeasure and evaluatePCE, i.e. it first draws n samples from the measure, then evaluates the PCE for those samples.

Multivariate

samplePCE(n::Int,x::AbstractVector{<:Real},mop::MultiOrthoPoly;method::Vector{String}=["adaptiverejection" for i=1:length(mop.meas.name)])

Arguments

  • n: number of samples.
  • x: PCE coefficient vector.
  • op, mop: univariate or multivariate basis used for sampling.

Keywords

Returns

The sampled PCE values as a vector.

source
PolyChaos.calculateAffinePCE — Function
calculateAffinePCE(α::AbstractVector{<:Real})

Arguments

  • α: recurrence coefficients of the basis; α[1] is the constant shift.
  • op: basis from which to read α.
  • i, mop: coordinate and multivariate basis for a component PCE.

Returns

The two coefficients [x₀, x₁] of the affine expansion.

Examples

julia> using PolyChaos
julia> calculateAffinePCE(LegendreOrthoPoly(1))
[0.0, 1.0]

Computes the affine PCE coefficients $x_0$ and $x_1$ from recurrence coefficients $�lpha$.

source
PolyChaos.convert2affinePCE — Function
convert2affinePCE(mu::Real, sigma::Real, op::AbstractCanonicalOrthoPoly; kind::String)

Computes the affine PCE coefficients $x_0$ and $x_1$ from

\[X = a_1 + a_2 \Xi = x_0 + x_1 \phi_1(\Xi),\]

where $\phi_1(t) = t-\alpha_0$ is the first-order monic basis polynomial.

Works for subtypes of AbstractCanonicalOrthoPoly. The keyword kind in ["lbub", "μσ"] specifies whether p1 and p2 have the meaning of lower/upper bounds or mean/standard deviation.

Arguments

  • par1, par2: lower and upper bounds, or mean and standard deviation, depending on kind.
  • α0: constant recurrence coefficient for the first-order basis.
  • op: canonical orthogonal-polynomial basis.

Keywords

  • kind: "lbub" for bounds or "μσ" for mean and standard deviation.

Returns

The affine PCE coefficient vector [x₀, x₁].

source

Auxiliary Functions

PolyChaos.nw — Function
nw(q::AbstractQuad)
nw(op::AbstractOrthoPoly)
nw(ops::AbstractVector)
nw(mop::MultiOrthoPoly)

Return quadrature nodes and weights in matrix form. nw(EmptyQuad()) returns an empty 0 x 2 matrix.

Arguments

  • q, op, ops, mop: a quadrature rule, basis, collection of bases, or multivariate basis.

Returns

A node/weight matrix for a univariate input, or one node and weight array per component for a collection or multivariate basis.

Examples

julia> using PolyChaos

julia> size(nw(LegendreOrthoPoly(2)), 2)
2
source
PolyChaos.coeffs — Function
coeffs(op::AbstractOrthoPoly)
coeffs(ops::AbstractVector)
coeffs(mop::MultiOrthoPoly)

Return the monic recurrence coefficients associated with an orthogonal basis.

Arguments

  • op, ops, mop: a basis, collection of univariate bases, or multivariate basis.

Returns

A two-column α/β matrix for a univariate basis, or the corresponding coefficient arrays for collections and multivariate bases.

source
PolyChaos.integrate — Function
integrate(f::Function, nodes::AbstractVector{<:Real}, weights::AbstractVector{<:Real})
integrate(f::Function, q::AbstractQuad)
integrate(f::Function, op::AbstractOrthoPoly)

Integrate f using the supplied quadrature rule.

Arguments

  • f: scalar-valued integrand.
  • nodes, weights: paired quadrature data.
  • q, op: a quadrature rule or basis with an attached rule.

Returns

The weighted sum of f evaluated at the quadrature nodes.

For example $\int_0^1 6x^5 = 1$ can be solved as follows:

julia> opq = Uniform01OrthoPoly(3) # a quadrature rule is added by default

julia> integrate(x -> 6x^5, opq)
0.9999999999999993
Note
  • function $f$ is assumed to return a scalar.
  • interval of integration is "hidden" in nodes.
source
integrate(f::Function, mop::MultiOrthoPoly)

Integrate a multivariate function f using tensor product quadrature from a MultiOrthoPoly. The function f should accept the same number of arguments as there are univariate orthogonal polynomials in mop.

For product measures, this computes the integral by evaluating f at all combinations of quadrature nodes and weighting by the product of the corresponding univariate weights.

Arguments

  • f: function accepting one scalar argument per coordinate.
  • mop: multivariate basis with attached quadrature rules.

Returns

The tensor-product quadrature estimate of the integral.

Examples

op1 = GaussOrthoPoly(3)
op2 = Uniform01OrthoPoly(5)
mop = MultiOrthoPoly([op1, op2], 3)

# Integrate f(x,y) = x*y over the product measure
integrate((x, y) -> x * y, mop)
source
PolyChaos.issymmetric — Function
issymmetric(m::AbstractMeasure)
issymmetric(op::AbstractOrthoPoly)

Return whether the measure underlying m or op is symmetric about zero.

Arguments

  • m: measure implementing the AbstractMeasure contract.
  • op: basis with an underlying measure.

Returns

true when the measure is symmetric and false otherwise.

source