Doxygen 1.9.1
Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN: Tasmanian v8.2 (development)
Multi-Index manipulation algorithms
Collaboration diagram for Multi-Index manipulation algorithms:

Files

file  tsgIndexManipulator.hpp
 Algorithms for manipulating sets of multi-indexes.
 

Classes

struct  TasGrid::MultiIndexManipulations::ProperWeights
 Holds anisotropic weights in a usable format. More...
 

Functions

MultiIndexSet TasGrid::MultiIndexManipulations::generateFullTensorSet (std::vector< int > const &num_entries)
 Create a full-tensor multi-index set with num_entries in each direction. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::generateLowerMultiIndexSet (size_t num_dimensions, std::function< bool(const std::vector< int > &index)> inside)
 Generate the multi-index with entries satisfying the inside(), assumes that inside() defines a lower-complete set. . More...
 
void TasGrid::MultiIndexManipulations::completeSetToLower (MultiIndexSet &set)
 Expand the set with the minimum number of multi-indexes that will result in a lower complete set. . More...
 
std::vector< int > TasGrid::MultiIndexManipulations::computeLevels (MultiIndexSet const &mset)
 Returns a vector that is the sum of entries of each multi-index in the set. More...
 
std::vector< int > TasGrid::MultiIndexManipulations::getMaxIndexes (const MultiIndexSet &mset)
 Returns a vector with the maximum index in each dimension. More...
 
Data2D< int > TasGrid::MultiIndexManipulations::computeDAGup (MultiIndexSet const &mset)
 Returns a Data2D structure where each strip holds the slot-index of the parents of indexes in mset (for each direction), using one-point-growth hierarchy. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::selectFlaggedChildren (const MultiIndexSet &mset, const std::vector< bool > &flagged, const std::vector< int > &level_limits)
 Using the flagged map, create a set with the flagged children of mset but only if they obey the level_limits. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::generateNestedPoints (const MultiIndexSet &tensors, std::function< int(int)> getNumPoints)
 Converts a set of nested tensors to the actual points, where each level has getNumPoints() in each direction. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::generateNonNestedPoints (const MultiIndexSet &tensors, const OneDimensionalWrapper &wrapper)
 Converts a set of non-nested active tensors to the actual points, the wrapper gives mapping between level and point indexes. More...
 
void TasGrid::MultiIndexManipulations::resortIndexes (const MultiIndexSet &iset, std::vector< std::vector< int >> &map, std::vector< std::vector< int >> &lines1d)
 Creates a map with sorted indexes dimension by dimension. More...
 
template<bool nested>
std::vector< int > TasGrid::MultiIndexManipulations::referencePoints (const int levels[], const OneDimensionalWrapper &wrapper, const MultiIndexSet &points)
 Find the indexes of all points associated with the tensor with levels within the global points set. More...
 
std::vector< int > TasGrid::MultiIndexManipulations::computeTensorWeights (MultiIndexSet const &mset)
 Computes the weights for the tensor linear combination, mset must be a lower complete set. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::createActiveTensors (const MultiIndexSet &mset, const std::vector< int > &weights)
 Creates a set containing only the entries of mset that have non-zero weights. More...
 
void TasGrid::MultiIndexManipulations::computeActiveTensorsWeights (MultiIndexSet const &tensors, MultiIndexSet &active_tensors, std::vector< int > &active_w)
 Uses the computeTensorWeights() and createActiveTensors() to extract the active tensors and the active (non-zero) weights.
 
MultiIndexSet TasGrid::MultiIndexManipulations::createPolynomialSpace (const MultiIndexSet &tensors, std::function< int(int)> exactness)
 For a set of tensors compute the corresponding polynomial space assuming the 1D rules have given exactness(). More...
 
bool TasGrid::MultiIndexManipulations::isLowerComplete (std::vector< int > const &point, MultiIndexSet const &mset, std::vector< int > &scratch)
 Assuming that mset is lower complete, return true if adding the point will preserve completeness. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::getLargestCompletion (MultiIndexSet const &current, MultiIndexSet const &candidates)
 Return the largest subset of candidates such that adding it to current will preserve lower completeness. More...
 
template<bool limited>
MultiIndexSet TasGrid::MultiIndexManipulations::addExclusiveChildren (const MultiIndexSet &tensors, const MultiIndexSet &exclude, const std::vector< int > level_limits)
 For a set of tensors create an mset that contain the children of indexes in tensors that are missing from exclude and obey the level_limits. More...
 
template<class IndexList , class RuleLike , class OutputIteratorLike >
OutputIteratorLike TasGrid::MultiIndexManipulations::indexesToNodes (IndexList const &list, RuleLike const &rule, OutputIteratorLike nodes)
 Converts int-indexes to double-valued abscissas using the provided rule. More...
 
template<class IteratorLike , class RuleLike , class OutputIteratorLike >
OutputIteratorLike TasGrid::MultiIndexManipulations::indexesToNodes (IteratorLike ibegin, size_t num_entries, RuleLike const &rule, OutputIteratorLike nodes)
 Overload that uses a begin and a number of entries.
 
template<class IndexList , class RuleLike >
std::vector< double > TasGrid::MultiIndexManipulations::getIndexesToNodes (IndexList const &list, RuleLike const &rule)
 Overload that returns the result in a vector.
 
template<class IteratorLike , class RuleLike >
std::vector< double > TasGrid::MultiIndexManipulations::getIndexesToNodes (IteratorLike ibegin, size_t num_entries, RuleLike const &rule)
 Overload that returns the result in a vector.
 
std::vector< int > TasGrid::MultiIndexManipulations::inferAnisotropicWeights (AccelerationContext const *acceleration, TypeOneDRule rule, TypeDepth depth, MultiIndexSet const &points, std::vector< double > const &coefficients, double tol)
 Overload that returns the result in a vector. More...
 
template<bool use_parents_direction>
void TasGrid::MultiIndexManipulations::repeatAddIndexes (std::function< bool(const std::vector< int > &index)> inside, std::vector< MultiIndexSet > &level_sets)
 Generate a series of level_sets where each set has the parents/children of the previous one that satisfy the inside() criteria. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::unionSets (std::vector< MultiIndexSet > &level_sets)
 Retuns the union of all level_sets, all sets are destroyed in the process. More...
 
MultiIndexSet TasGrid::MultiIndexManipulations::generateGeneralMultiIndexSet (size_t num_dimensions, std::function< bool(const std::vector< int > &index)> criteria)
 Generate the minimum lower complete multi-index set that includes the indexes satisfying criteria(), assumes criteria() defines a connected set. More...
 
template<bool check_limits>
MultiIndexSet TasGrid::MultiIndexManipulations::selectGeneralSet (ProperWeights const &weights, std::function< int(int i)> rule_exactness, int normalized_offset, std::vector< int > const &level_limits)
 Generates the minimum lower complete set that contains all indexes with weights less than normalized_offset. More...
 

Detailed Description

Multi-Index manipulation algorithms
A series of templates, lambda, and regular functions that allow the manipulation of multi-indexes and sets of multi-indexes. The algorithms include the selection of multi-indexes according to a criteria, union of a vector of multi-index sets, normalization of anisotropic weights, map parents and children within a set (which generates a DAG structure), complete a set to satisfy the lower-property, etc.

Function Documentation

◆ generateFullTensorSet()

MultiIndexSet TasGrid::MultiIndexManipulations::generateFullTensorSet ( std::vector< int > const &  num_entries)
inline

Create a full-tensor multi-index set with num_entries in each direction.

◆ generateLowerMultiIndexSet()

MultiIndexSet TasGrid::MultiIndexManipulations::generateLowerMultiIndexSet ( size_t  num_dimensions,
std::function< bool(const std::vector< int > &index)>  inside 
)
inline

Generate the multi-index with entries satisfying the inside(), assumes that inside() defines a lower-complete set. .

◆ completeSetToLower()

void TasGrid::MultiIndexManipulations::completeSetToLower ( MultiIndexSet set)

Expand the set with the minimum number of multi-indexes that will result in a lower complete set. .

◆ computeLevels()

std::vector< int > TasGrid::MultiIndexManipulations::computeLevels ( MultiIndexSet const &  mset)

Returns a vector that is the sum of entries of each multi-index in the set.

◆ getMaxIndexes()

std::vector< int > TasGrid::MultiIndexManipulations::getMaxIndexes ( const MultiIndexSet mset)

Returns a vector with the maximum index in each dimension.

◆ computeDAGup()

Data2D< int > TasGrid::MultiIndexManipulations::computeDAGup ( MultiIndexSet const &  mset)

Returns a Data2D structure where each strip holds the slot-index of the parents of indexes in mset (for each direction), using one-point-growth hierarchy.

Adds -1 in places where the parents are missing.

◆ selectFlaggedChildren()

MultiIndexSet TasGrid::MultiIndexManipulations::selectFlaggedChildren ( const MultiIndexSet mset,
const std::vector< bool > &  flagged,
const std::vector< int > &  level_limits 
)

Using the flagged map, create a set with the flagged children of mset but only if they obey the level_limits.

◆ generateNestedPoints()

MultiIndexSet TasGrid::MultiIndexManipulations::generateNestedPoints ( const MultiIndexSet tensors,
std::function< int(int)>  getNumPoints 
)

Converts a set of nested tensors to the actual points, where each level has getNumPoints() in each direction.

Working with nested points, it is more efficient to interpret the tensors as a surplus operators and generate only the surplus points; then take the union without repeated indexes. This can work if and only if tensors is a lower-complete set, i.e., the tensors in GridGlobal and not the active_tensors.

◆ generateNonNestedPoints()

MultiIndexSet TasGrid::MultiIndexManipulations::generateNonNestedPoints ( const MultiIndexSet tensors,
const OneDimensionalWrapper wrapper 
)

Converts a set of non-nested active tensors to the actual points, the wrapper gives mapping between level and point indexes.

For each index in tensor, generate a local set of points and then remap them to the global index using the wrapper.getPointIndex().

◆ resortIndexes()

void TasGrid::MultiIndexManipulations::resortIndexes ( const MultiIndexSet iset,
std::vector< std::vector< int >> &  map,
std::vector< std::vector< int >> &  lines1d 
)

Creates a map with sorted indexes dimension by dimension.

Parameters
isetis a non-empty set of indexes
map(output) the i-th index in the order with d as the fastest changing (contiguous) dimension is map[d][i]
lines1dfor each dimension d the indexes that match in all but d-dimension will be between lines1d[d][i] and lines1d[d][i+1] (not including the last entry) This is similar to the pntr index of row-compressed sparse matrix

◆ referencePoints()

template<bool nested>
std::vector<int> TasGrid::MultiIndexManipulations::referencePoints ( const int  levels[],
const OneDimensionalWrapper wrapper,
const MultiIndexSet points 
)

Find the indexes of all points associated with the tensor with levels within the global points set.

The order in which the tensors are formed here must match the order in which they will be used, e.g., when computing interpolation and quadrature weights.

◆ computeTensorWeights()

std::vector< int > TasGrid::MultiIndexManipulations::computeTensorWeights ( MultiIndexSet const &  mset)

Computes the weights for the tensor linear combination, mset must be a lower complete set.

◆ createActiveTensors()

MultiIndexSet TasGrid::MultiIndexManipulations::createActiveTensors ( const MultiIndexSet mset,
const std::vector< int > &  weights 
)
inline

Creates a set containing only the entries of mset that have non-zero weights.

◆ createPolynomialSpace()

MultiIndexSet TasGrid::MultiIndexManipulations::createPolynomialSpace ( const MultiIndexSet tensors,
std::function< int(int)>  exactness 
)

For a set of tensors compute the corresponding polynomial space assuming the 1D rules have given exactness().

◆ isLowerComplete()

bool TasGrid::MultiIndexManipulations::isLowerComplete ( std::vector< int > const &  point,
MultiIndexSet const &  mset,
std::vector< int > &  scratch 
)
inline

Assuming that mset is lower complete, return true if adding the point will preserve completeness.

Parameters
pointis the new point to add to an existing set
msetis an existing lower complete set
scratchis scratch space, must have size equal to point.size() and will be used for temporary storage the scratch reduces allocations

◆ getLargestCompletion()

MultiIndexSet TasGrid::MultiIndexManipulations::getLargestCompletion ( MultiIndexSet const &  current,
MultiIndexSet const &  candidates 
)
inline

Return the largest subset of candidates such that adding it to current will preserve lower completeness.

◆ addExclusiveChildren()

template<bool limited>
MultiIndexSet TasGrid::MultiIndexManipulations::addExclusiveChildren ( const MultiIndexSet tensors,
const MultiIndexSet exclude,
const std::vector< int >  level_limits 
)

For a set of tensors create an mset that contain the children of indexes in tensors that are missing from exclude and obey the level_limits.

If limited is false, then the level_limits are ignored.

◆ indexesToNodes()

template<class IndexList , class RuleLike , class OutputIteratorLike >
OutputIteratorLike TasGrid::MultiIndexManipulations::indexesToNodes ( IndexList const &  list,
RuleLike const &  rule,
OutputIteratorLike  nodes 
)

Converts int-indexes to double-valued abscissas using the provided rule.

Nodes of the sparse grid are stored as multi-indexes in either vectors or MultiIndexSet classes. The nodes are converted to double precision numbers according to a specified one-dimensional rule.

Template Parameters
IndexListis either a MultiIndexSet or a std::vector<int>, both of which have a begin and end methods, the begin and end must allow iteration over a range of integers.
RuleLikeis either a OneDimensionalWrapper, derived from BaseRuleLocalPolynomial, or RuleWavelet, or any other class with getNode method that converts an int to a double; GridSequence class provides the getNode() method too.
OutputIteratorLikeindicates where the write the output, e.g., an iterator or an array, the output matches with OutputIteratorLike as defined by std::transform.
Parameters
listdefines a range of integers to be converted to double precision numbers.
ruleis a class with getNode method that defines the conversion.
nodesmarks the beginning of the output range.
Returns
OutputIteratorLike at the end of the range that has been written.

Overloads are provided that work with an ibegin iterator and a number of entries in place of the list, as well as returning the result in a std::vector<double> as opposed to writing to a nodes iterator. See the brief descriptions at the top of the page.

◆ inferAnisotropicWeights()

std::vector< int > TasGrid::MultiIndexManipulations::inferAnisotropicWeights ( AccelerationContext const *  acceleration,
TypeOneDRule  rule,
TypeDepth  depth,
MultiIndexSet const &  points,
std::vector< double > const &  coefficients,
double  tol 
)

Overload that returns the result in a vector.

Infers the weights that best describe the decay-rate of the normalized coefficients given the rule and depth. The points represent either the polynomial powers of the frequencies of the Fourier transform and tol is the cutoff tolerance, i.e., use only the coefficients with magnitude exceeding tol.

◆ repeatAddIndexes()

template<bool use_parents_direction>
void TasGrid::MultiIndexManipulations::repeatAddIndexes ( std::function< bool(const std::vector< int > &index)>  inside,
std::vector< MultiIndexSet > &  level_sets 
)

Generate a series of level_sets where each set has the parents/children of the previous one that satisfy the inside() criteria.

On entry, level_sets must constain at least one set. The function takes the last set in level_sets and adds a new set of eithe the parents or children that also satisfy the inside() condition. The process is repeated until the new set is empty.

◆ unionSets()

MultiIndexSet TasGrid::MultiIndexManipulations::unionSets ( std::vector< MultiIndexSet > &  level_sets)
inline

Retuns the union of all level_sets, all sets are destroyed in the process.

◆ generateGeneralMultiIndexSet()

MultiIndexSet TasGrid::MultiIndexManipulations::generateGeneralMultiIndexSet ( size_t  num_dimensions,
std::function< bool(const std::vector< int > &index)>  criteria 
)
inline

Generate the minimum lower complete multi-index set that includes the indexes satisfying criteria(), assumes criteria() defines a connected set.

◆ selectGeneralSet()

template<bool check_limits>
MultiIndexSet TasGrid::MultiIndexManipulations::selectGeneralSet ( ProperWeights const &  weights,
std::function< int(int i)>  rule_exactness,
int  normalized_offset,
std::vector< int > const &  level_limits 
)

Generates the minimum lower complete set that contains all indexes with weights less than normalized_offset.

The weight of an index uses the weights combined with the rule_exactness(). Called only for contour type_curved and caches values on-the-fly.

If check_limits is false, then level_limits are ignored for speedup.