sgpykit.tools.lev2knots_functions
Functions
Convert level index to number of knots using the 2-step rule. |
|
|
Map sparse-grid levels to the corresponding number of knots using the Genz-Keister (GK) table. |
Convert level index to number of knots using a doubling rule. |
|
Relation between level and number of points for linear level-to-knots mapping. |
|
Convert sparse-grid level index to number of knots using a tripling rule. |
- sgpykit.tools.lev2knots_functions.lev2knots_2step(I)[source]
Convert level index to number of knots using the 2-step rule.
The 2-step rule defines the number of knots as m = 2(i-1)+1 for i > 0, resulting in an odd number of points (1, 3, 5, …).
- Parameters:
- Iint or array_like
Level(s) for which to compute the number of knots. Must be numeric.
- Returns:
- mint or ndarray
Number of points to be used in each direction. If input is scalar, returns scalar. If input is array, returns array of same shape.
Notes
For i <= 0, the output is 0.
The function preserves the input type (scalar or array).
- sgpykit.tools.lev2knots_functions.lev2knots_GK(I)[source]
Map sparse-grid levels to the corresponding number of knots using the Genz-Keister (GK) table.
This function returns the number of knots corresponding to the given level(s) I, using the pre-tabulated GK_lev_table. For levels beyond the table’s range, a warning is logged and -1 is stored as a sentinel value.
- Parameters:
- Iint or array_like
Level(s) for which to compute the number of knots. Must be non-negative.
- Returns:
- nb_knotsint or ndarray
Number of knots corresponding to the input level(s). If I is a scalar, returns a scalar. If I is an array, returns an array of the same shape. For non-tabulated levels, -1 is stored.
Notes
The GK_lev_table is a pre-computed lookup table that maps levels to knot counts and quadrature orders. Levels greater than 5 are not tabulated and will result in a warning and a stored value of -1.
- sgpykit.tools.lev2knots_functions.lev2knots_doubling(I)[source]
Convert level index to number of knots using a doubling rule.
This function maps a level index (or an array of indices) to the corresponding number of knots based on a doubling rule. The mapping is defined as:
m = 2^{i-1} + 1 for i > 1 m = 1 for i = 1 m = 0 for i = 0
- Parameters:
- Iint or array_like
Level(s) for which to compute the number of knots. Must be numeric.
- Returns:
- mint or ndarray
Number of knots corresponding to the input level(s). If I is a scalar, returns a scalar. If I is an array, returns an array of the same shape.
Notes
The function handles both scalar and array inputs. For array inputs, the output array will have the same shape as the input array.
- sgpykit.tools.lev2knots_functions.lev2knots_lin(I)[source]
Relation between level and number of points for linear level-to-knots mapping.
This function maps a given level I to the number of points m by simply returning the same integer (i.e., m = I). It is intended for use in constructing sparse grids where a linear level-to-knots mapping is needed.
- Parameters:
- Iint or array-like
Level(s) for which to compute the number of knots.
- Returns:
- mint or array-like
Number of points to be used in each direction.
Notes
- The relationship between level and number of points is given by:
m = I
- sgpykit.tools.lev2knots_functions.lev2knots_tripling(I)[source]
Convert sparse-grid level index to number of knots using a tripling rule.
This function maps a given level index (or array of indices) to the corresponding number of knots based on the tripling rule: m = 3^{i-1} for i > 0, and m = 0 for i = 0.
- Parameters:
- Iint or array_like
Level(s) for which to compute the number of knots. Must be non-negative. Must be numeric.
- Returns:
- mint or ndarray
Number of knots corresponding to the input level(s). Returns a scalar if input is a scalar, otherwise returns a NumPy array of int64 values.
Notes
The tripling rule results in the following sequence of knot counts: - i = 0 -> m = 0 - i = 1 -> m = 1 - i = 2 -> m = 3 - i = 3 -> m = 9 - i = 4 -> m = 27 - etc.