Constructors and Utilities
PolyChaos.assign2multi — Function
assign2multi(x, i, ind)Embed a univariate coefficient vector into a multivariate total-degree basis.
Arguments
x: univariate coefficients ordered by polynomial degree.i: one-based coordinate index inind.ind: total-degree multi-index matrix.
Returns
A coefficient vector aligned with the rows of ind, with terms that depend on coordinates other than i set to zero.
PolyChaos.calculateMultiIndices — Function
calculateMultiIndices(d, n)Construct the total-degree multi-index matrix for d variables through degree n.
Arguments
d: positive number of variables.n: nonnegative maximum total degree.
Returns
A matrix whose rows are multi-indices in the ordering used by MultiOrthoPoly.
Examples
julia> using PolyChaos
julia> size(calculateMultiIndices(2, 2))
(6, 2)PolyChaos.computeTensorizedSP — Function
computeTensorizedSP(m, basis)
computeTensorizedSP(m, alpha, beta, nodes, weights, ind; issymmetric)Compute sparse tensorized scalar products of order m.
Arguments
m: positive scalar-product order.basis: a univariate basis, coordinate-basis vector, orMultiOrthoPoly.alpha,beta: recurrence coefficient vectors for each coordinate.nodes,weights: quadrature data for each coordinate.ind: multivariate basis multi-index matrix.
Keywords
issymmetric: coordinate symmetry flags used to eliminate zero products.
Returns
A sparse vector indexed by the polynomial-index tuples in the total-degree basis.
PolyChaos.deg — Function
deg(basis)Return the maximum represented polynomial degree.
Arguments
basis: a univariateAbstractOrthoPolyor aMultiOrthoPoly.
PolyChaos.dim — Function
dim(basis)Return the number of polynomials represented by an orthogonal basis.
Arguments
basis: a univariateAbstractOrthoPolyor aMultiOrthoPoly.
For univariate bases this is deg(basis) + 1; for multivariate bases it is the number of rows in the total-degree multi-index matrix.
PolyChaos.findUnivariateIndices — Function
findUnivariateIndices(i::Int,ind::AbstractMatrix{Int64,2})Given the multi-index ind this function returns all entries of the multivariate basis that correspond to the ith univariate basis.
Arguments
i: one-based coordinate index.ind: total-degree multi-index matrix.
Returns
Indices of rows in ind corresponding to the univariate basis in coordinate i.
PolyChaos.genHermiteMeasure — Type
genHermiteMeasure(mu)Generalized Hermite measure with weight abs(t)^(2mu) * exp(-t^2).
Arguments
mu: generalized-Hermite parameter; must exceed-0.5.
Fields
w,dom,symmetric: measure data.muParameter: validated parameter.
PolyChaos.genHermiteOrthoPoly — Type
genHermiteOrthoPoly(deg, mu; Nrec = deg + 1, addQuadrature = true)Construct a generalized Hermite basis.
Arguments
deg: nonnegative maximum degree.mu: generalized-Hermite parameter greater than-0.5.
Keywords
Nrec: recurrence coefficient count.addQuadrature: whether to attach Gaussian quadrature.
Fields
deg: maximum represented degree.α,β: monic recurrence coefficients.measure: generalized-Hermite measure.quad: attached quadrature rule orEmptyQuad.
PolyChaos.genLaguerreMeasure — Type
genLaguerreMeasure(shape)Generalized Laguerre measure with weight t^shape * exp(-t) on (0, Inf).
Arguments
shape: exponent oft; must exceed-1.
Fields
w,dom,symmetric: measure data.shapeParameter: validated generalized-Laguerre shape.
PolyChaos.genLaguerreOrthoPoly — Type
genLaguerreOrthoPoly(deg, shape; Nrec = deg + 1, addQuadrature = true)Construct a generalized Laguerre basis.
Arguments
deg: nonnegative maximum degree.shape: generalized-Laguerre parameter greater than-1.
Keywords
Nrec: recurrence coefficient count.addQuadrature: whether to attach Gaussian quadrature.
Fields
deg: maximum represented degree.α,β: monic recurrence coefficients.measure: generalized-Laguerre measure.quad: attached quadrature rule orEmptyQuad.
PolyChaos.getentry — Function
getentry(a, T, ind, dim)Return a sparse scalar-product tensor entry.
Arguments
a: zero-based polynomial indices; its length must equaldim.T: sparse tensor storage returned bycomputeTensorizedSP.ind: total-degree multi-index matrix used to constructT.dim: scalar-product order.
a is sorted in place in descending order before lookup.
PolyChaos.golubwelsch — Function
golubwelsch(alpha, beta, maxiter = 30)Compute Gaussian quadrature nodes and weights from monic recurrence coefficients using the Golub-Welsch eigenproblem.
Arguments
alpha,beta: equal-length recurrence coefficient vectors.maxiter: maximum eigensolver iteration count.
Returns
Node and weight vectors for the associated Gaussian quadrature rule.
PolyChaos.multi2uni — Function
multi2uni(a, ind)Convert scalar-product basis indices to coordinate-wise univariate indices.
Arguments
a: nonnegative row indices intoind, using PolyChaos's zero-based basis convention.ind: total-degree multi-index matrix.
Returns
A matrix whose column j is the univariate multi-index represented by a[j].
PolyChaos.sampleInverseCDF — Function
sampleInverseCDF(n::Int, pdf::Function, dom::Tuple{<:Real,<:Real})Inverse transform sampling using Chebyshev technology.
Draw n samples from a probability density function pdf with support dom. This method uses Chebyshev polynomial approximation of the PDF, constructs the CDF via integration, and then uses bisection to sample from the inverse CDF.
Based on:
- Olver, Sheehan, and Alex Townsend. "Fast inverse transform sampling in one and two dimensions." arXiv preprint arXiv:1307.1223 (2013).
- https://github.com/dlfivefifty/InverseTransformSampling
This method works for any bounded PDF and does not require log-concavity like adaptive rejection sampling.
Arguments
n::Int: Number of samples to drawpdf::Function: Probability density function (need not be normalized)dom::Tuple{<:Real,<:Real}: Domain (support) of the PDF as (lower, upper)
Returns
Vector{Float64}: Vector ofnsamples from the distribution
Example
# Sample from a truncated normal
pdf = x -> exp(-x^2/2)
samples = sampleInverseCDF(1000, pdf, (-3.0, 3.0))