This file contains a class that builds a Smolyak Grid. The hope is that it will eventually contain the interpolation routines necessary so that the given some data, this class can build a grid and use the Chebychev polynomials to interpolate and approximate the data.
Method based on Judd, Maliar, Maliar, Valero 2013 (W.P)
Bases: object
This class currently takes a dimension and a degree of polynomial and builds the Smolyak Sparse grid. We base this on the work by Judd, Maliar, Maliar, and Valero (2013).
Parameters : | d : int
mu : int or array(int, ndim=1, length=d)
|
---|
Examples
>>> s = SmolyakGrid(3, 2)
>>> s
Smolyak Grid:
d: 3
mu: 2
npoints: 25
B: 0.65% non-zero
>>> ag = SmolyakGrid(3, [1, 2, 3])
>>> ag
Anisotropic Smolyak Grid:
d: 3
mu: 1 x 2 x 3
npoints: 51
B: 0.68% non-zero
Attributes
d | int | This is the dimension of grid that you are building |
mu | int | mu is a parameter that defines the fineness of grid that we want to build |
grid | array (float, ndim=2) | This is the sparse grid that we need to build |
inds | list (list (int)) | This is a lists of lists that contains all of the indices |
B | array (float, ndim=2) | This is the B matrix that is used to do lagrange interpolation |
B_L | array (float, ndim=2) | Lower triangle matrix of the decomposition of B |
B_U | array (float, ndim=2) | Upper triangle matrix of the decomposition of B |
Methods
plot_grid() | Beautifully plots the grid for the 2d and 3d cases |
Finds all of the unidimensional disjoint sets of Chebychev extrema that are used to construct the grid. It improves on past algorithms by noting that \(A_{n} = S_{n}\) [evens] except for \(A_1 = \{0\}\) and \(A_2 = \{-1, 1\}\) . Additionally, \(A_{n} = A_{n+1}\) [odds] This prevents the calculation of these nodes repeatedly. Thus we only need to calculate biggest of the S_n’s to build the sequence of \(A_n\) ‘s
Parameters : | n : int
|
---|---|
Returns : | A_chain : dict (int -> list)
|
Compute the matrix B from equation 22 in JMMV 2013 Translation of dolo.numeric.interpolation.smolyak.SmolyakBasic
Parameters : | d : int
mu : int or array (int, ndim=1, legnth=d)
grid : array (float, dims=2)
inds : list (list (int)), optional (default=None)
|
---|---|
Returns : | B : array (float, 2)
|
Use disjoint Smolyak sets to construct Smolyak grid of degree d and density parameter \(mu\)
The return value is an \(n \times d\) Array, where \(n\) is the number of points in the grid
Parameters : | d : int
mu : int
inds : list (list (int)), optional (default=None)
|
---|---|
Returns : | grid : array (float, ndim=2)
|
Computes the first \(n+1\) Chebychev polynomials of the first kind evaluated at each point in \(x\) .
Parameters : | x : float or array(float)
n : int
kind : float, optional(default=1.0)
|
---|---|
Returns : | results : array (float, ndim=x.ndim+1)
|
Compute one plus the “total degree of the interpolating polynoimals” (Kruger & Kubler, 2004). This shows up many times in Smolyak’s algorithm. It is defined as:
Parameters : | i : int
|
---|---|
Returns : | num : int
|
Checks the number of grid points for a given d, mu combination.
Parameters : | d, mu : int
|
---|---|
Returns : | num : int
|
Notes
This function is only defined for mu = 1, 2, or 3
For each number in 1 to n, compute the Smolyak indices for the corresponding basis functions. This is the \(n\) in \(\phi_n\)
Parameters : | n : int
|
---|---|
Returns : | aphi_chain : dict (int -> list)
|
Build indices specifying all the Cartesian products of Chebychev polynomials needed to build Smolyak polynomial
Parameters : | d : int
mu : int
inds : list (list (int)), optional (default=None)
|
---|---|
Returns : | phi_inds : array
|
Notes
This function uses smol_inds and phi_chain. The output of this function is used by build_B to construct the B matrix
Finds the set \(S_n\) , which is the \(n\) th Smolyak set of Chebychev extrema
Parameters : | n : int
|
---|---|
Returns : | s_n : array (float, ndim=1)
|
Finds all of the indices that satisfy the requirement that \(d \leq \sum_{i=1}^d \leq d + \mu\).
Parameters : | d : int
mu : int or array (int, ndim=1)
|
---|---|
Returns : | true_inds : array
|
Notes
This function is used directly by build_grid and poly_inds