SG++-Doxygen-Documentation
sgpp::base::HashGenerator Class Reference

This class provides the generation functionality of sparse grids based on hashmaps. More...

#include <HashGenerator.hpp>

## Public Member Functions

void cliques (GridStorage &storage, level_t level, size_t clique_size, double T=0)
Generates a regular sparse grid of level levels, without boundaries where dimensions are splitted into a groups with only certain number of dimensions completely connected in a clique. More...

void full (GridStorage &storage, level_t level)
Generates a full grid of level level, without boundaries. More...

void fullWithBoundary (GridStorage &storage, level_t level)
Generates a full grid of level level, with boundary grid points. More...

void regular (GridStorage &storage, level_t level, double T=0)
Generates a regular sparse grid of level levels, without boundaries. More...

void regular_inter (GridStorage &storage, level_t level, const std::unordered_set< std::vector< bool >> &terms, double T=0)

void regularInter (GridStorage &storage, level_t level, const std::vector< std::vector< size_t >> &terms, double T=0)
Generates a regular sparse grid of level level, without boundaries. More...

void regularWithBoundaries (GridStorage &storage, level_t level, level_t boundaryLevel=1)
Generates a regular sparse grid of level levels with boundaries. More...

void regularWithPeriodicBoundaries (GridStorage &storage, level_t level, double T=0)
Generates a regular sparse grid of level levels with boundaries. More...

void squareRoot (GridStorage &storage, level_t level)
Generates a regular square root grid of level level with boundaries. More...

void truncated (GridStorage &storage, level_t level, level_t k)
Generates a truncated boundary grid containing all gridpoints with li<l-k and |l|<l+(dim-1)*k. More...

## Protected Member Functions

void boundaries_rec (GridStorage &storage, GridPoint &index, size_t current_dim, level_t current_level, level_t level)
recursive construction of the spare grid with boundaries, classic level 0 approach, only for level 0 and 1 More...

void boundaries_truncated_rec (GridStorage &storage, GridPoint &index, size_t current_dim, level_t current_level, level_t level, bool bLevelZero)
recursive construction of the spare grid without boundaries More...

void boundaries_Truncated_rec_1d (GridStorage &storage, GridPoint &index, level_t current_level, level_t level, bool bLevelZero)
generate points of the last dimension (dim == 0), version of pentagon cut in sub space scheme More...

void cliques_iter (GridStorage &storage, level_t n, size_t clique_size, double T=0)

void createFullGridIterative (GridStorage &storage, level_t n)
Generate a full grid iteratively (much faster than recursively) without grid points on the boundary. More...

void createFullGridTruncatedIterative (GridStorage &storage, level_t n)
Generate a full grid iteratively (much faster than recursively) with truncated boundary. More...

void decodeCoords (DataVector &coords, std::vector< bool > &result)

void regular_boundary_truncated_iter (GridStorage &storage, level_t n, level_t boundaryLevel=1, double T=0)
Generate a regular sparse grid iteratively (much faster than recursively) with truncated boundary, i.e., the sparse grid on the $$(d-1)$$-dimensional faces of $$[0, 1]^d$$ has a coarser level than the main axes $$x_t = 0.5, t = 1, ..., d$$. More...

void regular_inter_iter (GridStorage &storage, level_t n, const std::unordered_set< std::vector< bool >> &terms, double T=0)

void regular_iter (GridStorage &storage, level_t n, double T=0)
Generate a regular sparse grid iteratively (much faster than recursively) without grid points on the boundary. More...

void regular_periodic_boundary_iter (GridStorage &storage, level_t n, double T=0)
Generate a regular sparse grid iteratively (much faster than recursively) with periodic boundary. More...

void square_rec (GridStorage &storage, GridPoint &index, size_t current_dim, level_t level, level_t small_level, bool tail, size_t sum)
recursive construction of a square root grid with boundaries More...

void trunc_rec (GridStorage &storage, GridPoint &index, size_t current_dim, level_t current_level, level_t level, level_t minlevel)
recursive construction of a super truncated grid with boundaries More...

## Detailed Description

This class provides the generation functionality of sparse grids based on hashmaps.

Grids with and without boundaries are supported.

For boundary grids two cases are supported:

1. the classic sparse grid with level 0 and a diagonal cut through the sub space scheme.
2. a modified boundary grid with level 0 and a pentagon cut trough the sub space scheme.

Furthermore, the creation of full grids (in the hierarchical basis) is supported.

## Member Function Documentation

 void sgpp::base::HashGenerator::boundaries_rec ( GridStorage & storage, GridPoint & index, size_t current_dim, level_t current_level, level_t level )
inlineprotected

recursive construction of the spare grid with boundaries, classic level 0 approach, only for level 0 and 1

Parameters
 storage hashmap that stores the grid points index point's index current_dim current working dimension current_level current level in this construction step level maximum level of the sparse grid

Referenced by regularWithBoundaries().

 void sgpp::base::HashGenerator::boundaries_truncated_rec ( GridStorage & storage, GridPoint & index, size_t current_dim, level_t current_level, level_t level, bool bLevelZero )
inlineprotected

recursive construction of the spare grid without boundaries

Parameters
 storage hashmap that stores the grid points index point's index current_dim current working dimension current_level current level in this construction step level maximum level of the sparse grid generate points of the last dimension (dim == 0), without boundaries storage the hashmap that stores the grid points index point's index that should be created on the grid current_level current level of the grid generation level maximum level of grid recursive construction of the spare grid with boundaries, pentagon cut storage hashmap that stores the grid points index point's index current_dim current working dimension current_level current level in this construction step level maximum level of the sparse grid bLevelZero specifies if the current index has a level zero component
 void sgpp::base::HashGenerator::boundaries_Truncated_rec_1d ( GridStorage & storage, GridPoint & index, level_t current_level, level_t level, bool bLevelZero )
inlineprotected

generate points of the last dimension (dim == 0), version of pentagon cut in sub space scheme

Parameters
 storage the hashmap that stores the grid points index point's index that should be created on the grid current_level current level of the grid generation level maximum level of grid bLevelZero specifies if the current index has a level zero component

Referenced by boundaries_truncated_rec().

 void sgpp::base::HashGenerator::cliques ( GridStorage & storage, level_t level, size_t clique_size, double T = 0 )
inline

Generates a regular sparse grid of level levels, without boundaries where dimensions are splitted into a groups with only certain number of dimensions completely connected in a clique.

Parameters
 storage Hashmap that stores the grid points level Grid level (non-negative value) clique_size number of dimensions in a clique T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces
 void sgpp::base::HashGenerator::cliques_iter ( GridStorage & storage, level_t n, size_t clique_size, double T = 0 )
inlineprotected
 void sgpp::base::HashGenerator::createFullGridIterative ( GridStorage & storage, level_t n )
inlineprotected

Generate a full grid iteratively (much faster than recursively) without grid points on the boundary.

Parameters
 storage Pointer to the storage object into which the grid points should be stored n Level of full grid

Referenced by full().

 void sgpp::base::HashGenerator::createFullGridTruncatedIterative ( GridStorage & storage, level_t n )
inlineprotected

Generate a full grid iteratively (much faster than recursively) with truncated boundary.

Parameters
 storage Pointer to the storage object into which the grid points should be stored n Level of full grid

Referenced by fullWithBoundary().

 void sgpp::base::HashGenerator::decodeCoords ( DataVector & coords, std::vector< bool > & result )
inlineprotected
 void sgpp::base::HashGenerator::full ( GridStorage & storage, level_t level )
inline

Generates a full grid of level level, without boundaries.

Parameters
 storage Hashmap that stores the grid points level Grid level (non-negative value)

References createFullGridIterative(), and sgpp::base::HashGridStorage::getSize().

 void sgpp::base::HashGenerator::fullWithBoundary ( GridStorage & storage, level_t level )
inline

Generates a full grid of level level, with boundary grid points.

Parameters
 storage Hashmap that stores the grid points level Grid level (non-negative value)
 void sgpp::base::HashGenerator::regular ( GridStorage & storage, level_t level, double T = 0 )
inline

Generates a regular sparse grid of level levels, without boundaries.

Parameters
 storage Hashmap that stores the grid points level Grid level (non-negative value) T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces. The effect of T can be seen in:

References sgpp::base::HashGridStorage::getSize(), and regular_iter().

 void sgpp::base::HashGenerator::regular_boundary_truncated_iter ( GridStorage & storage, level_t n, level_t boundaryLevel = 1, double T = 0 )
inlineprotected

Generate a regular sparse grid iteratively (much faster than recursively) with truncated boundary, i.e., the sparse grid on the $$(d-1)$$-dimensional faces of $$[0, 1]^d$$ has a coarser level than the main axes $$x_t = 0.5, t = 1, ..., d$$.

The function adds all hierarchical subspaces $$W_{\vec{\ell}}$$ where

• $$\norm{\vec{\ell}}_1 \le n + d - 1$$ with $$\forall_t\; \ell_t \ge 1$$,
• $$\norm{\vec{\ell}}_1 \le n + d - b - N_{\vec{\ell}}$$ with $$N_{\vec{\ell}} := |\{t \mid \ell_t = 0\}| \ge 1$$, or
• $$\vec{\ell} = \vec{0}$$.

The previous implementation inserted the 1D boundary grid points at higher levels (e.g., at boundaryLevel = 2), which led to the effect that corner points were missing in higher-dimensional grids: For example, if $$d = 2$$, $$n = 3$$, and $$\mathtt{boundaryLevel} = 3$$, then the four corners had level sum $$2 \cdot \mathtt{boundaryLevel} = 6$$ (which is greater than $$n + d - 1 = 4$$), thus they were missing in the sparse grid. The midpoints of the four edges, however, had level sum $$\mathtt{boundaryLevel} + 1 = 4 \le n + d - 1$$ and were thus included in the grid. To get the corners into the grid, too, one would have to choose $$n \ge 4$$.

In contrast, the new implementation makes sure that the corners will always appear first in the grid when increasing the level $$n = 1, 2, 3, \dotsc$$ of the regular grid.

Parameters
 storage pointer to storage object into which the grid points should be stored n level of regular sparse grid boundaryLevel 1 + how much levels the boundary is coarser than the main axes, 1 means same level, 2 means one level coarser, etc.; must be >= 1 T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces

Referenced by regularWithBoundaries().

 void sgpp::base::HashGenerator::regular_inter ( GridStorage & storage, level_t level, const std::unordered_set< std::vector< bool >> & terms, double T = 0 )
inline
 void sgpp::base::HashGenerator::regular_inter_iter ( GridStorage & storage, level_t n, const std::unordered_set< std::vector< bool >> & terms, double T = 0 )
inlineprotected
 void sgpp::base::HashGenerator::regular_iter ( GridStorage & storage, level_t n, double T = 0 )
inlineprotected

Generate a regular sparse grid iteratively (much faster than recursively) without grid points on the boundary.

Parameters
 storage pointer to storage object into which the grid points should be stored n level of regular sparse grid T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces

Referenced by regular().

 void sgpp::base::HashGenerator::regular_periodic_boundary_iter ( GridStorage & storage, level_t n, double T = 0 )
inlineprotected

Generate a regular sparse grid iteratively (much faster than recursively) with periodic boundary.

Parameters
 storage Pointer to storage object into which the grid points should be stored n Level of regular sparse grid T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces

Referenced by regularWithPeriodicBoundaries().

 void sgpp::base::HashGenerator::regularInter ( GridStorage & storage, level_t level, const std::vector< std::vector< size_t >> & terms, double T = 0 )
inline

Generates a regular sparse grid of level level, without boundaries.

The resulting grid only contains interactions that are in the vector terms.

Parameters
 storage Hashmap that stores the grid points level Grid level (non-negative value) terms controls the desired interaction terms. For example, if we want to include grid points that model an interaction between the first and the second predictor, we would include the vector [1,2] in terms. T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces.

Referenced by sgpp::base::StandardGridGenerator::regularInter().

 void sgpp::base::HashGenerator::regularWithBoundaries ( GridStorage & storage, level_t level, level_t boundaryLevel = 1 )
inline

Generates a regular sparse grid of level levels with boundaries.

Parameters
 storage Hashmap, that stores the grid points level maximum level of the sparse grid (non-negative value) boundaryLevel level at which the boundary points should be inserted
 void sgpp::base::HashGenerator::regularWithPeriodicBoundaries ( GridStorage & storage, level_t level, double T = 0 )
inline

Generates a regular sparse grid of level levels with boundaries.

Parameters
 storage Hashmap, that stores the grid points level maximum level of the sparse grid (non-negative value) T modifier for subgrid selection, T = 0 implies standard sparse grid. For further information see Griebel and Knapek's paper optimized tensor-product approximation spaces

Referenced by sgpp::base::PeriodicGridGenerator::regular().

 void sgpp::base::HashGenerator::square_rec ( GridStorage & storage, GridPoint & index, size_t current_dim, level_t level, level_t small_level, bool tail, size_t sum )
inlineprotected

recursive construction of a square root grid with boundaries

Parameters
 storage hashmap that stores the grid points index point's index current_dim current working dimension level maximum level of the square root grid small_level level of coarsest descretization tail true if there is a level of the index>level/2 sum sum of all levels

If a level of the node equals level, and all the others equal small_level, the node is a leaf This is equivalent to saying the sum of levels equals small_level*(dim-1)+level

If the level of the node is smaller than small_level or we didn't have yet a level greater than small_level(!tail) and the level is smaller then level then we can then proceed to the next level on this dimension, otherwise we reached the maximum possible level*

Referenced by squareRoot().

 void sgpp::base::HashGenerator::squareRoot ( GridStorage & storage, level_t level )
inline

Generates a regular square root grid of level level with boundaries.

Parameters
 storage Hashmap, that stores the grid points level maximum level of the square root grid (non-negative value)

Change here to the following code to take the [n/2]+1 grid as small level for odd numbers(and also change FullGridSet getSquare method) int small_level=ceil(level/2); if (level%2==0) level–;

Referenced by sgpp::base::SquareRootGridGenerator::regular().

 void sgpp::base::HashGenerator::trunc_rec ( GridStorage & storage, GridPoint & index, size_t current_dim, level_t current_level, level_t level, level_t minlevel )
inlineprotected

recursive construction of a super truncated grid with boundaries

Parameters
 storage hashmap that stores the grid points index point's index current_dim current working dimension current_level the current level of the gridpoint so far, starts from minlevel*dim level the maximum level of the gridpoint minlevel the level limit given by the user(tells us which fullgrids won't be present in the construction of the sparse grid)

If the source level of the node is smaller than minlevel we don't increase the variable current_level(since we started with minlevel*dim) This trick makes it possible to introduce all nodes with source_level<minlevel without a separate treatment

if the source_level is already >=minlevel we can proceed naturally and increase the current_level which represents the sum of levels so far

Referenced by truncated().

 void sgpp::base::HashGenerator::truncated ( GridStorage & storage, level_t level, level_t k )
inline

Generates a truncated boundary grid containing all gridpoints with li<l-k and |l|<l+(dim-1)*k.

Parameters
 storage Hashmap, that stores the grid points level maximum level of the square root grid (non-negative value) k the parameter which determines the maximum level of the gridpoints for every dimension

The documentation for this class was generated from the following file: