Spectral Sparse Grids
The sparse grid approximations are polynomial approximations, with a basis of Lagrange interpolation polynomials. The approximation can be written in any suitable polynomial basis, for example we could use the Chebyshev polynomials.
The change of basis is implemented exploiting the ApproxFun.jl package. The underlying interpolation polynomials used in SparseGridsKit.jl are constructed using Funs. To change basis we use an ApproxFun.jl expansion into coefficients and form a tensor product. To promote sparsity this is done using a truncated Kronecker product. The polynomial coefficients are assembled with corresponding polynomial degrees and spaces in a callable SpectralSparseGridApproximation.
Examples
An adaptive sparse grid approximation for a Genz test function is created.
using SparseGridsKit
n = 8
C = 1.0
W = 0.0
T = "exponentialdecay"
N = "gaussianpeak"
f = genz(n::Int, C::Float64, W::Float64, T::String, N::String)
# Approximate
(sg, f_on_Z) = adaptive_sparsegrid(f, n)
f_sg = SparseGridApproximation(sg,f_on_Z)SparseGridApproximation(SparseGrid(8, [[-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0]], [1 1 … 3 4; 1 1 … 2 1; … ; 1 1 … 1 1; 1 1 … 1 1], [-1, 1, 0, 0, 0, -1, 1, 1], Real[0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; -0.38268343236508984 0.0 … 0.0 0.0; -0.9238795325112867 0.0 … 0.0 0.0], [-0.26984126984126977, 0.16666666666666669, 0.16666666666666669, -0.0031746031746031807, 0.05079365079365081, 0.05079365079365081, -0.0031746031746031807, 0.005555555555555559, 0.044444444444444446, 0.06666666666666668 … 0.005555555555555559, 0.005555555555555559, 0.044444444444444446, 0.06666666666666668, 0.044444444444444446, 0.005555555555555559, 0.07310932460800906, 0.1808589293602449, 0.1808589293602449, 0.07310932460800906], Points[CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0]), CCPoints{Float64}([-1.0, 1.0])], Level[Doubling(), Doubling(), Doubling(), Doubling(), Doubling(), Doubling(), Doubling(), Doubling()], SparseGridsKit.sparse_grid_data{8}(SparseGridsKit.SparseTerm{8}[SparseGridsKit.SparseTerm{8}(([1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([1, 1], [1, 1], [2, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([1, 1], [1, 1], [2, 2], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([1, 1], [1, 1], [2, 3], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([3, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([3, 2], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([3, 3], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([3, 4], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([3, 5], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([3, 1], [2, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])) … SparseGridsKit.SparseTerm{8}(([3, 5], [2, 3], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 2], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 3], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 4], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 5], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 6], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 7], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 8], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1])), SparseGridsKit.SparseTerm{8}(([4, 9], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]))], [(1, 1, 1, 1, 1, 1, 1, 1), (1, 1, 2, 1, 1, 1, 1, 1), (1, 1, 3, 1, 1, 1, 1, 1), (2, 1, 1, 1, 1, 1, 1, 1), (4, 1, 1, 1, 1, 1, 1, 1), (5, 1, 1, 1, 1, 1, 1, 1), (3, 1, 1, 1, 1, 1, 1, 1), (2, 2, 1, 1, 1, 1, 1, 1), (4, 2, 1, 1, 1, 1, 1, 1), (1, 2, 1, 1, 1, 1, 1, 1) … (3, 2, 1, 1, 1, 1, 1, 1), (2, 3, 1, 1, 1, 1, 1, 1), (4, 3, 1, 1, 1, 1, 1, 1), (1, 3, 1, 1, 1, 1, 1, 1), (5, 3, 1, 1, 1, 1, 1, 1), (3, 3, 1, 1, 1, 1, 1, 1), (6, 1, 1, 1, 1, 1, 1, 1), (7, 1, 1, 1, 1, 1, 1, 1), (8, 1, 1, 1, 1, 1, 1, 1), (9, 1, 1, 1, 1, 1, 1, 1)], [1, 2, 1, 3, 4, 5, 1, 6, 7, 8 … 17, 4, 18, 5, 19, 1, 20, 6, 21, 7], [-1, 1, 1, 1, -1, -1, -1, -1, -1, 1 … 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…), Dict([4, 2] => 6, [1, 1] => 1, [3, 5] => 3, [4, 5] => 1, [2, 1] => 2, [3, 1] => 2, [4, 8] => 9, [4, 1] => 2, [4, 6] => 8, [2, 3] => 3…)], [[[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]], [[0.0], [1.0, 0.0, -1.0], [1.0, 0.7071067811865475, 0.0, -0.7071067811865475, -1.0], [1.0, 0.9238795325112867, 0.7071067811865475, 0.38268343236508984, 0.0, -0.38268343236508984, -0.7071067811865475, -0.9238795325112867, -1.0]]], [[0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867], [0.0, 1.0, -1.0, 0.7071067811865475, -0.7071067811865475, 0.9238795325112867, 0.38268343236508984, -0.38268343236508984, -0.9238795325112867]], [[[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]], [[1.0], [0.16666666666666669, 0.6666666666666667, 0.16666666666666669], [0.033333333333333354, 0.26666666666666666, 0.4, 0.26666666666666666, 0.033333333333333354], [0.007936507936507936, 0.07310932460800906, 0.13968253968253969, 0.1808589293602449, 0.19682539682539682, 0.1808589293602449, 0.13968253968253969, 0.07310932460800906, 0.007936507936507936]]])), [1.0, 0.9986316107749044, 0.9986316107749044, 0.5420585004051459, 0.7362462226763177, 0.7362462226763177, 0.5420585004051459, 0.5265868123957612, 0.715231937600404, 0.9714575308793776 … 0.5265868123957612, 0.5265868123957612, 0.715231937600404, 0.9714575308793776, 0.715231937600404, 0.5265868123957612, 0.5929174027357444, 0.9142226183682018, 0.9142226183682018, 0.5929174027357444], [[-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0]])The approximation f_sg is a representation formed as a linear combination of Lagrange interpolation polynomials. This is converted to a spectral representation using convert_to_spectral_approximation.
f_spectral = convert_to_spectral_approximation(sg, f_on_Z)SpectralSparseGridApproximation(8, [9, 9, 9, 9, 9, 9, 9, 9], Any[Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0)], sparsevec([1, 118099, 531442, 1062883, 4782970, 5845852, 9565939, 10628821, 14348908, 15411790, 19131877, 20194759, 23914846, 28697815, 33480784, 38263753], [0.7421643379729322, -0.0006841946125477893, 1.3877787807814457e-17, -0.010755340910229252, -2.7755575615628914e-17, -2.0816681711721685e-17, -0.2248162280230623, 0.0032676952778094223, 1.249000902703301e-16, 6.938893903907228e-18, 0.01714331539085502, -0.00024819837227248523, -8.326672684688674e-17, -0.0008868264965551098, 0.0, 3.386294373612653e-5], 43046721), sparsevec([1, 118099, 531442, 1062883, 4782970, 5845852, 9565939, 10628821, 14348908, 15411790, 19131877, 20194759, 23914846, 28697815, 33480784, 38263753], [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 0, 0], [3, 2, 0, 0, 0, 0, 0, 0], [4, 0, 0, 0, 0, 0, 0, 0], [4, 2, 0, 0, 0, 0, 0, 0], [5, 0, 0, 0, 0, 0, 0, 0], [6, 0, 0, 0, 0, 0, 0, 0], [7, 0, 0, 0, 0, 0, 0, 0], [8, 0, 0, 0, 0, 0, 0, 0]], 43046721), Vector{Real}[[-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0]])This still has an n dimensional domain.
f_spectral.dims8The representation of the tensor of polynomials is compactly stored as a SparseVector. To index into this we require the storage dimension for each domain dimension.
f_spectral.expansiondimensions8-element Vector{Int64}:
9
9
9
9
9
9
9
9This demonstrates that more polynomial terms are used in the parameter dimensions closer to one. Intuitively, this matches the anisotropic nature of the test function (see genz). The polynomial coefficients and the corresponding polynomial degrees are stored in sparse vectors.
f_spectral.coefficients, f_spectral.polydegrees(sparsevec([1, 118099, 531442, 1062883, 4782970, 5845852, 9565939, 10628821, 14348908, 15411790, 19131877, 20194759, 23914846, 28697815, 33480784, 38263753], [0.7421643379729322, -0.0006841946125477893, 1.3877787807814457e-17, -0.010755340910229252, -2.7755575615628914e-17, -2.0816681711721685e-17, -0.2248162280230623, 0.0032676952778094223, 1.249000902703301e-16, 6.938893903907228e-18, 0.01714331539085502, -0.00024819837227248523, -8.326672684688674e-17, -0.0008868264965551098, 0.0, 3.386294373612653e-5], 43046721), sparsevec([1, 118099, 531442, 1062883, 4782970, 5845852, 9565939, 10628821, 14348908, 15411790, 19131877, 20194759, 23914846, 28697815, 33480784, 38263753], [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 0, 0], [3, 2, 0, 0, 0, 0, 0, 0], [4, 0, 0, 0, 0, 0, 0, 0], [4, 2, 0, 0, 0, 0, 0, 0], [5, 0, 0, 0, 0, 0, 0, 0], [6, 0, 0, 0, 0, 0, 0, 0], [7, 0, 0, 0, 0, 0, 0, 0], [8, 0, 0, 0, 0, 0, 0, 0]], 43046721))The spectral representation is the same function as the sparse grid representation.
x_test = [rand(n) for i in 1:100]
y_test = f_sg.(x_test)
y_spectral = f_spectral.(x_test)
all(isapprox(y_test, y_spectral; atol=1e-8))trueThe spectral sparse grid approximation also supports addition and subtraction.
f_spectral_2 = f_spectral + f_spectral
y_spectral_2 = f_spectral_2.(x_test)
all(isapprox(y_spectral_2, 2*y_spectral; atol=1e-8))truef_spectral_0 = f_spectral - f_spectral
y_spectral_0 = f_spectral_0.(x_test)
@show y_spectral_0, f_spectral_0
#all(isapprox(y_spectral_0, nothing; atol=1e-8))([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], SpectralSparseGridApproximation(8, [9, 9, 9, 9, 9, 9, 9, 9], Any[Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0), Chebyshev(-1.0 .. 1.0)], sparsevec([1, 118099, 531442, 1062883, 4782970, 5845852, 9565939, 10628821, 14348908, 15411790, 19131877, 20194759, 23914846, 28697815, 33480784, 38263753], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0, 0.0], 43046721), sparsevec([1, 118099, 531442, 1062883, 4782970, 5845852, 9565939, 10628821, 14348908, 15411790, 19131877, 20194759, 23914846, 28697815, 33480784, 38263753], [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 0, 0], [3, 2, 0, 0, 0, 0, 0, 0], [4, 0, 0, 0, 0, 0, 0, 0], [4, 2, 0, 0, 0, 0, 0, 0], [5, 0, 0, 0, 0, 0, 0, 0], [6, 0, 0, 0, 0, 0, 0, 0], [7, 0, 0, 0, 0, 0, 0, 0], [8, 0, 0, 0, 0, 0, 0, 0]], 43046721), Vector{Real}[[-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0], [-1.0, 1.0]]))Function Reference
SparseGridsKit.SpectralSparseGridApproximation — TypeSpectralSparseGridApproximationA spectral sparse grid approximation.
Fields
dims::Int: Dimension of the domain.expansiondimensions::Vector{Int}: Vector of maximum polynomial degree in each dimension.polytypes::Vector{Any}: Vector of polynomial spaces.coefficients::SparseVector{Any}: SparseVector of polynomial coefficientspolydegrees::SparseVector{Vector}: SparseVector of polynomial degrees for each non zero coefficient.
SparseGridsKit.SpectralSparseGridApproximation — MethodSpectralSparseGridApproximation(dims, expansionparams, polytypes, coefficients)Constructs a spectral sparse grid approximation.
Arguments
dims::Int: Dimension of the domain.expansiondimensions::Vector{Int}: Vector of maximum polynomial degree in each dimension.polytypes::Vector{Any}: Vector of polynomial spaces.coefficients::Vector{Any}: Kronecker product vector of polynomial coefficientsdomain::Vector{Vector{Real}}: Vector of domains for inputs
Returns
SpectralSparseGridApproximation: An instance ofSpectralSparseGridApproximation.
SparseGridsKit.SpectralSparseGridApproximation — Method(s::SpectralSparseGridApproximation)(x)Evaluate the spectral sparse grid approximation at the given point x.
Arguments
s::SpectralSparseGridApproximation: Spectral sparse grid approximation object.x::Vector{T}: Vector x in domain to be evaluated
Returns
evaluation: Evaluation of s(x)
Base.:+ — Method+(grid1::SpectralSparseGridApproximation, grid2::SpectralSparseGridApproximation)Add two SpectralSparseGridApproximation objects.
Arguments
grid1::SpectralSparseGridApproximation: Spectral sparse grid approximation.grid2::SpectralSparseGridApproximation: Second spectral sparse grid approximation.
Returns
SpectralSparseGridApproximationrepresenting sum ofgrid1andgrid2.
Base.:- — Method-(grid1::SpectralSparseGridApproximation, grid2::SpectralSparseGridApproximation)Subtracts SpectralSparseGridApproximation objects
Arguments
grid1::SpectralSparseGridApproximation: Spectral sparse grid approximation.grid2::SpectralSparseGridApproximation: Second spectral sparse grid approximation, to be subtracted
Returns
SpectralSparseGridApproximationobject representing the subtraction.
SparseGridsKit.convert_to_sg_approximation — Methodconvert_to_sg_approximation(ssg::SpectralSparseGridApproximation)
Convert a `SpectralSparseGridApproximation` object to a SparseGridApproximation representation.Arguments
ssg::SpectralSparseGridApproximation: Spectral sparse grid approximation.
Returns
SparseGridApproximation: Sparse grid approximation representation ofssg.
SparseGridsKit.convert_to_spectral_approximation — Methodconvert_to_spectral_approximation(sparsegrid::SparseGrid, fongrid)Converts a sparse grid and corresponding evaluations fongrid to a SpectralSparseGridApproximation
Arguments
sparsegrid::SparseGrid: Sparse gridfongrid: Function evaluations ofsparse grid.
Returns
SpectralSparseGridApproximationrepresntation ofsparsegridwith evaluationsfongrid.
SparseGridsKit.convert_to_spectral_approximation — Methodconvert_to_spectral_approximation(sga::SparseGridApproximation)Convert a SparseGridApproximation object to its spectral approximation.
Arguments
sga::SparseGridApproximation: Sparse grid approximation.
Returns
- Spectral Sparse Grid Approximation representing
sga.
SparseGridsKit.getdomain — Methodgetdomain(polytype)
Takes an ApproxFun polynomial space a returns a vector [a,b] of the domain endpoints.Arguments
polytype: ApproxFun Space
Returns
domain: Vector domain [a,b]
SparseGridsKit.inverse_level_map — Methodinverse_level_map(levelfunction, maxlevel)
Inverse level map for a given level2knots type function.Arguments
levelfunction: Level function.maxlevel: Maximum level.
Returns
Vector{Int}: Inverse level map.
SparseGridsKit.kron_index — Methodkron_index(indices::Vector{Int}, dims::Vector{Int})Calculate the linear index in a Kronecker product space given the multi-dimensional indices and the dimensions of each space.
Arguments
indices::Vector{Int}: Index vector.dims::Vector{Int}: Vector of storage dimension for each tensor dimension.
Returns
- Linear index corresponding to the index given in
indices.
SparseGridsKit.poly_Fun — Methodpoly_Fun(knots, ind; lb=-1.0, ub=1.0)Lagrange interpolation polynomial ind for the set of knots
Arguments
knots::Vector{T}: A vector of knotsind::Int: Knot index for polynomial equal to 1.lb::Float64: Domain lower bound. Default is -1.0.ub::Float64: Domain upper bound. Default is 1.0.
Returns
f::Fun: Lagrange interpolation polynomial as ApproxFun Fun object.
SparseGridsKit.reverse_kron_index — Methodreverse_kron_index(index::Int, dims::Vector{Int})Given linear index index and a vector of dimensions dims, computes the multi-dimensional tensor index.
Arguments
index::Int: Linear index.dims::Vector{Int}: Vector containing the storage dimension of the tensor dimensions.
Returns
Vector{Int}: Tensor index
SparseGridsKit.truncated_kron — Methodtruncated_kron(vectors; tol=eps())Compute the Kronecker product of a list of vectors with truncation.
Arguments
vectors::Vector{Vector}: Vector of vectors to compute the Kronecker product.tol::Float64: Tolerance value for coefficienet truncation to promote sparsity. Elements with absolute values less thantolare set to zero. Default is1e-15to remove coefficients at machine precision.
Returns
result: SparseVector representation of truncated Kronecker product of the input vectors.tensor_dims::Vector{Int}: Dimensions of the resulting tensor.