sgpykit.tools.idxset_functions
Functions
|
Check if a multiindex is admissible with respect to an index set. |
|
Check if a given index set is admissible and return the admissible set. |
|
Define the level-to-knots and index set functions for a given sparse grid rule. |
|
Generate the total-degree multi-index set TD(w) in N dimensions. |
|
Generate a set of multi-dimensional box indices up to a given shape. |
|
Generate all multi-indexes of length N with elements such that rule(M_I) <= w. |
|
Plot the index set I for 2D and 3D cases. |
- sgpykit.tools.idxset_functions.check_index_admissibility(idx, idx_set, sort_option=None)[source]
Check if a multiindex is admissible with respect to an index set.
Given a multiindex idx as a row vector, checks if it is admissible with respect to the index set idx_set (matrix with indices as rows). If it is admissible, returns is_adm = True. Otherwise, returns is_adm = False and the function will return the completed_set and a list of the indices added stored in missing_set.
- Parameters:
- idxarray_like
Multiindex to check for admissibility.
- idx_setarray_like
Matrix of indices (rows) representing the index set.
- sort_optionstr, optional
If ‘sorting’, returns completed_set and missing_set sorted in lexicographic order.
- Returns:
- is_admbool
True if the multiindex is admissible, False otherwise.
- completed_setndarray
The completed index set after adding missing indices.
- missing_setndarray
The list of indices added to make the set admissible.
Notes
The starting idx_set is assumed to be admissible, so its multi-indices will not be checked for admissibility. However, being admissible is not necessary for this function to work, since the core is setdiff, which does not assume any ordering. Assumes 0-based indexing.
- sgpykit.tools.idxset_functions.check_set_admissibility(I, matlab_idx=True)[source]
Check if a given index set is admissible and return the admissible set.
- Parameters:
- Iarray_like
The index set to check for admissibility.
- matlab_idxbool, optional
If True, the input index set I is assumed to be in 1-based index format. C will use 1-based indexing then. Default is True.
- Returns:
- admbool
True if the input index set is admissible, False otherwise.
- Cndarray
The admissible index set in lexicographic order. If the input set is not admissible, the missing indices are added to make it admissible. If matlab_idx is True, C will use 1-based indexing.
Notes
The function checks each index in the set for admissibility and adds any missing indices to ensure the set is admissible. A warning is logged if the set is not admissible and indices are added.
- sgpykit.tools.idxset_functions.define_functions_for_rule(rule, input2)[source]
Define the level-to-knots and index set functions for a given sparse grid rule.
This function sets the functions lev2nodes and idxset to be used in create_sparse_grid to build the desired isotropic or anisotropic sparse grid.
- Parameters:
- rulestr
The rule for constructing the sparse grid. Can be one of the following: ‘TP’, ‘TD’, ‘HC’, ‘SM’.
- input2int or array_like
If scalar, the number of variables (N). If array_like, the rates vector for anisotropic sparse grids.
- Returns:
- lev2nodesfunction
A function that maps a level to the number of knots.
- idxsetfunction
A function that computes the index set for a given multi-index.
- Raises:
- ValueError
If the rule is unknown.
- sgpykit.tools.idxset_functions.fast_TD_set(N, w, base=0)[source]
Generate the total-degree multi-index set TD(w) in N dimensions.
- Parameters:
- Nint
Number of dimensions.
- wint
Total degree.
- baseint, optional
Base index to offset the multiindices (default is 0).
- Returns:
- ndarray or int
The multiindex set as a numpy array (or scalar if TDsize == 1 and N == 1).
- sgpykit.tools.idxset_functions.multiidx_box_set(shape, min_idx=0)[source]
Generate a set of multi-dimensional box indices up to a given shape.
Given an index shape, generates C_with, the box indices set up to that shape. min_idx is either 0 or 1. C_without is C_with without shape itself.
- Parameters:
- shapearray_like
The shape of the box. Can be a scalar or a list/array of non-negative integers.
- min_idxint
Minimum index value, either 0 or 1.
- Returns:
- tuple
A tuple containing two elements: - C_with : ndarray
The full set of multi-indices up to shape.
- C_withoutndarray
The set of multi-indices without the last index.
Notes
If shape is a column vector with more than one entry, it is converted to a row vector with all entries equal to the minimum value of shape.
- sgpykit.tools.idxset_functions.multiidx_gen(N, rule, w, base=0, multiidx=None, MULTI_IDX=None)[source]
Generate all multi-indexes of length N with elements such that rule(M_I) <= w.
This function recursively explores the tree of all possible multi-indexes and stores the valid ones as rows of the matrix MULTI_IDX. The indices start from the specified base (either 0 or 1).
- Parameters:
- Nint
Length of the multi-index.
- rulecallable
Function that evaluates the rule for a given multi-index.
- wfloat
Threshold for the rule.
- baseint, optional
Starting index for the multi-index elements (default is 0).
- multiidxlist, optional
Current multi-index being constructed (default is None).
- MULTI_IDXlist or numpy.ndarray, optional
Accumulator for valid multi-indexes (default is None).
- Returns:
- numpy.ndarray or int
Matrix of valid multi-indexes (or scalar if single element).
Notes
The function works recursively, exploring in depth the tree of all possible multi-indexes. The starting point is the empty multi-index: [], and MULTI_IDX is empty at the first call of the function. That’s why the call from keyboard comes with [], [] as input argument: multiidx_gen(L,rule,w,[],[]).
- sgpykit.tools.idxset_functions.plot_multiidx_set(ax, I, *args, **kwargs)[source]
Plot the index set I for 2D and 3D cases.
- Parameters:
- axmatplotlib.axes.Axes
The axes to plot on.
- Inumpy.ndarray
The index set to plot, shape (n, N) where N is the dimension.
- *argstuple, optional
Additional positional arguments passed to the plot function.
- **kwargsdict, optional
Additional keyword arguments passed to the plot function.
- Returns:
- hmatplotlib.collections.PathCollection or matplotlib.lines.Line2D
The plot handle.
- Raises:
- ValueError
If the dimension of I is greater than 3.