Sparse Grids

Knot functions, level functions and multi-index sets are combined to define a sparse grid structure.

Simple Sparse Grids

In the simplest case one often wants to create a sparse grid using a sequence of nested sets Clenshaw–Curtis points and a Smolyak type multi-index set. To this end, one uses create_sparsegrid with the desired Smolyak multi-index set.

using SparseGridsKit

n, k = 2, 1
mi_set = create_smolyak_miset(n, k)
sg = create_sparsegrid(mi_set)
propertynames(sg)
(:dims, :domain, :multi_index_set, :combination_coeff, :grid_points, :quadrature_weights, :knots, :rules, :data)

The grid points can be extracted using the get_grid_points function. This returns a vector of vector points.

points = get_grid_points(sg)
5-element Vector{Vector{Real}}:
 [0.0, 0.0]
 [0.0, 1.0]
 [0.0, -1.0]
 [1.0, 0.0]
 [-1.0, 0.0]
using Plots, LaTeXStrings
plot(sg)
plot!(title="Sparse Grid n,k="*string(n)*","*string(k),
        xlabel=L"y_1",
        ylabel=L"y_2")
Example block output

The grid can be altered by adding additional multi-indices.

mi_set_new = MISet([[1,3]])
combined_mi_set = add_mi(mi_set, mi_set_new)
sg_combined = create_sparsegrid(combined_mi_set)

points = get_grid_points(sg_combined)

x = [p[1] for p in points]
y = [p[2] for p in points]

plot(sg_combined)
plot!(  title="Sparse Grid Combined",
        xlabel="y_1",
        ylabel="y_2")
Example block output

More complicated Sparse Grids

More complex grids can be constructed. For example, consider increasing the dimension $n$ and using more multi-indices in the multi-index set.

n, k = 3, 3
mi_set = create_smolyak_miset(n, k)
sg = create_sparsegrid(mi_set)
points = get_grid_points(sg)
69-element Vector{Vector{Real}}:
 [0.0, 0.0, 1.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, -1.0]
 [0.0, 0.0, 0.7071067811865475]
 [0.0, 0.0, -0.7071067811865475]
 [0.0, 0.0, 0.9238795325112867]
 [0.0, 0.0, 0.38268343236508984]
 [0.0, 0.0, -0.38268343236508984]
 [0.0, 0.0, -0.9238795325112867]
 [0.0, 1.0, 0.0]
 ⋮
 [-0.7071067811865475, 0.0, -1.0]
 [0.7071067811865475, 1.0, 0.0]
 [-0.7071067811865475, 1.0, 0.0]
 [0.7071067811865475, -1.0, 0.0]
 [-0.7071067811865475, -1.0, 0.0]
 [0.9238795325112867, 0.0, 0.0]
 [0.38268343236508984, 0.0, 0.0]
 [-0.38268343236508984, 0.0, 0.0]
 [-0.9238795325112867, 0.0, 0.0]

This can still be easily visualised.

nsteps = 100
@gif for i in range(0, stop = 2π, length = nsteps)
        plot(sg)
        plot!(title="Sparse Grid n,k="*string(n)*","*string(k),
                xlabel=L"y_1",
                ylabel=L"y_2",
                zlabel=L"y_3",
                camera = (20 * (1 + cos(i)),10 * (1 + cos(i))))
end
Example block output

Mixed Knots Sparse Grids

It is possible to mix the type of Knots used in to construct a sparse grid. To demonstrate, consider Clenshaw–Curtis points on a domain $\Gamma_1=[-1,1] in the first dimension, Clenshaw--Curtis points on a domain $\Gamma_2=[0,100]$ in the second dimension and uniformly spaced points on the domain $[-1,1]$ in the third dimension.

using SparseGridsKit, Plots, LaTeXStrings
# Test create_sparsegrid
n,k =3,3
knots = [CCPoints(), CCPoints([0,100]), UniformPoints()]
rules = [Doubling(), Doubling(), Linear()]
mi_set = create_smolyak_miset(n,k)
sg = create_sparsegrid(mi_set, knots=knots, rule=rules)
nsteps = 100
@gif for i in range(0, stop = 2π, length = nsteps)
        plot(sg)
        plot!(
                title="Sparse Grid n,k="*string(n)*","*string(k),
                xlabel=L"y_1",
                ylabel=L"y_2",
                zlabel=L"y_3",
                camera = (20 * (1 + cos(i)),10 * (1 + cos(i)))
                )
end
Example block output

Function Reference

SparseGridsKit.compute_quadrature_weights!Method
compute_quadrature_weights!(sg)

Computes the quadrature weights for a sparse grid (sg).

Arguments

  • sg: The sparse grid for which to compute the quadrature weights.

Returns

  • Updates the quadrature_weights field of the sparse grid with computed weights.
source
SparseGridsKit.create_sparsegridMethod
create_sparsegrid(mi_set; rule=Doubling(), knots=CCPoints())

Creates a sparse grid based on the provided multi-index set (mi_set).

Arguments

  • mi_set: An instance of MISet containing the multi-index set for grid construction.
  • rule: Map from index to number of points. Optional (default Doubling()). Function or vector of functions (for each dimension).
  • knots: Type of knots. Optional (default Clenshaw–Curtis). Function or vector of functions (for each dimension).

Returns

  • A sparse grid object constructed using the specified multi-index set.
source
SparseGridsKit.get_grid_pointsMethod
get_grid_points(sg)

Retrieves the grid points from a sparse grid (sg).

Arguments

  • sg: A sparse grid object.

Returns

  • A vector of vectors, where each inner vector represents a grid point.
source
SparseGridsKit.get_mi_setMethod
get_mi_set(sg)

Gets set of multi-indices from a sparse grid (sg).

Arguments

  • sg: A sparse grid object.

Returns

  • An MISet containing the downwards-closed set of multi-indices.
source
SparseGridsKit.get_n_grid_pointsMethod
get_n_grid_points(sg)

Returns the number of grid points in the sparse grid (sg).

Arguments

  • sg: A sparse grid object.

Returns

  • The number of grid points in the sparse grid.
source
SparseGridsKit.integrate_L2_on_sparsegridMethod
integrate_L2_on_sparsegrid(sg, f_on_grid, precomputed_lagrange_integrals; product=dot, precomputed_pairwise_norms=nothing)

Computes the L2 norm of a function (f_on_grid) over a sparse grid (sg) using precomputed integrals.

Arguments

  • sg: The sparse grid.
  • f_on_grid: A vector of function values on the sparse grid.
  • precomputed_lagrange_integrals: Precomputed Lagrange integrals.
  • product: A function to compute the inner product (default is dot).
  • precomputed_pairwise_norms: Optional precomputed norms for optimization.

Returns

  • The L2 norm of the function over the sparse grid.
source
SparseGridsKit.integrate_on_sparsegridMethod
integrate_on_sparsegrid(sg, f_on_grid, precomputed_lagrange_integrals)

Integrates a function (f_on_grid) over a sparse grid (sg) using precomputed Lagrange integrals.

Arguments

  • sg: The sparse grid for integration.
  • f_on_grid: A vector of function values on the sparse grid.

Returns

  • The integral of the function over the sparse grid.
source
SparseGridsKit.interpolate_on_sparsegridMethod
interpolate_on_sparsegrid(sg, f_on_grid, target_points)

Interpolates a function (f_on_grid) defined on a sparse grid (sg) to a set of target points.

Arguments

  • sg: The source sparse grid.
  • f_on_grid: A vector of function values on the sparse grid.
  • target_points: A vector of target points for interpolation.

Returns

  • A vector of interpolated values at the target points.
source
SparseGridsKit.interpolate_on_sparsegridMethod
interpolate_on_sparsegrid(sga::SparseGridApproximation, target_points)

Interpolates a SparseGridApproximation to a set of target points.

Arguments

  • sga: SparseGridApproximation.
  • target_points: A vector of target points for interpolation.

Returns

  • A vector of interpolated values at the target points.
source
SparseGridsKit.map_from_toMethod
map_from_to(sg_from, sg_to)

Maps data from one sparse grid (sg_from) to another (sg_to).

Arguments

  • sg_from: The source sparse grid.
  • sg_to: The target sparse grid.

Returns

  • A vector that maps data from sg_from to sg_to.
source
SparseGridsKit.precompute_lagrange_integralsFunction
precompute_lagrange_integrals(max_mi)

Precomputes the product integrals for Lagrange basis functions up to a given maximum multi-index (max_mi).

Arguments

  • max_mi: The maximum multi-index for which to precompute integrals.

Returns

  • A vector of precomputed product integrals for the Lagrange basis.
source
SparseGridsKit.precompute_pairwise_normsMethod
precompute_pairwise_norms(f_on_grid, product)

Precomputes pairwise norms for function values (f_on_grid) using a specified product function.

Arguments

  • f_on_grid: A vector of function values on the sparse grid.
  • product: A function to compute the product between pairs of function values.

Returns

  • A matrix of pairwise norms.
source