A class for holding, sorting, and adapting sets of multiindices. More...
#include <MultiIndexSet.h>
A class for holding, sorting, and adapting sets of multiindices.
In the context of polynomial expansions, a multiindex defines a single multivariate polynomial. A finite expansion of multivariate polynomials is then defined by a collection of multiindices, one for each term in the expansion. This class is a tool for defining such a multiindex set, relating members within the set (i.e. defining neighbors), and expanding the set.
Let \(\mbox{j}=[j_1,j_2,\dots,j_D]\) be a \(D\)-dimensional multiindex. The backwards neighbors of \(\mbox{j}\) are the multiindices given by multiindices who are only different from \(\mbox{j}\) in one component, and in that component, the difference is -1. For example, \([j_1-1, j_2,\dots,j_D]\) and \([j_1, j_2-1,\dots,j_D]\) are backwards neighbors of \(\mbox{j}\), but \([j_1-1, j_2-1,\dots,j_D]\) and \([j_1, j_2-2,\dots,j_D]\) are not. Forward neighbors are similarly defined, but with +1. Examples of forward neighbors include \([j_1+1, j_2,\dots,j_D]\) and \([j_1, j_2+1,\dots,j_D]\). As far as this class is concerned, multiindices can be in three different categories: active, inactive, and/or admissable. Active multiindices are those that are currently being used to define a polynomial expansion, inactive multiindices are not currently used but are being tracked, and admissable multiindices are inactive multiindices whose backward neighbors are all active.
This class keeps track of both active and admissable multiindices, but only active indices are included in the linear indexing. Nonactive indices are hidden (i.e. not even considered) in all the public members of this class. For example, the GetAllMultiIndices function will return all active multiindices, and the IndexToMulti function will return \(i^\mbox{th}\) active multiindex. Inactive multiindices are used to check admissability and are added to the active set during adaptation.
In general, members of the MultiIndexFactory class should be used to construct MultiIndexSets directly.
Definition at line 65 of file MultiIndexSet.h.
Public Member Functions | |
MultiIndexSet (const unsigned dimIn, std::shared_ptr< MultiIndexLimiter > limiterIn=std::make_shared< NoLimiter >()) | |
virtual | ~MultiIndexSet ()=default |
virtual void | SetLimiter (std::shared_ptr< MultiIndexLimiter > const &limiterIn) |
virtual std::shared_ptr< MultiIndexLimiter > | GetLimiter () const |
virtual std::vector< std::shared_ptr< MultiIndex > > | GetAllMultiIndices () const |
virtual std::shared_ptr< MultiIndex > const & | IndexToMulti (unsigned activeIndex) const |
virtual int | MultiToIndex (std::shared_ptr< MultiIndex > const &input) const |
virtual unsigned int | GetMultiLength () const |
virtual Eigen::VectorXi | GetMaxOrders () const |
virtual std::shared_ptr< MultiIndex > const & | at (int activeIndex) |
virtual std::shared_ptr< MultiIndex > | operator[] (int activeIndex) |
virtual unsigned int | Size () const |
virtual MultiIndexSet & | operator+= (const MultiIndexSet &rhs) |
Add another set of multiindices to this one. More... | |
virtual MultiIndexSet & | operator+= (std::shared_ptr< MultiIndex > const &rhs) |
Add a single MultiIndex to the set. More... | |
virtual int | Union (const MultiIndexSet &rhs) |
Add all terms in rhs to this instance. More... | |
virtual void | Activate (std::shared_ptr< MultiIndex > const &multiIndex) |
virtual int | AddActive (std::shared_ptr< MultiIndex > const &newNode) |
virtual std::vector< unsigned > | Expand (unsigned int activeIndex) |
virtual std::vector< unsigned > | ForciblyExpand (unsigned int const activeIndex) |
virtual std::vector< unsigned > | ForciblyActivate (std::shared_ptr< MultiIndex > const &multiIndex) |
virtual std::vector< std::shared_ptr< MultiIndex > > | GetAdmissibleForwardNeighbors (unsigned int activeIndex) |
virtual std::vector< unsigned int > | GetFrontier () const |
virtual std::vector< unsigned int > | GetStrictFrontier () const |
virtual std::vector< unsigned int > | GetBackwardNeighbors (unsigned int activeIndex) const |
virtual std::vector< unsigned int > | GetBackwardNeighbors (std::shared_ptr< MultiIndex > const &multiIndex) const |
virtual bool | IsAdmissible (std::shared_ptr< MultiIndex > const &multiIndex) const |
Determines whether the input multiIndex is currently admissible. More... | |
virtual bool | IsExpandable (unsigned int activeIndex) const |
Return true if one of the forward neighbors of index is admissible but not active. More... | |
virtual bool | IsActive (std::shared_ptr< MultiIndex > const &multiIndex) const |
Return true if the multiIndex is active. More... | |
virtual unsigned int | NumActiveForward (unsigned int activeInd) const |
Returns the number of active forward neighbors. More... | |
virtual unsigned int | NumForward (unsigned int activeInd) const |
Returns the number of forward neighbors (active or inactive) More... | |
void | ToHDF5 (std::string filename, std::string dsetName="/multiindices") const |
Saves the multiindex set to a group in an HDF5 file. More... | |
void | ToHDF5 (muq::Utilities::H5Object &group, std::string dsetName="multiindices") const |
Saves the multiindex set to an HDF5 group object. More... | |
Static Public Member Functions | |
static std::shared_ptr< MultiIndexSet > | CloneExisting (std::shared_ptr< MultiIndexSet > const &original) |
NOTE: does not perform a deep copy of the multiindices themselves, only pointers to the multiindices. More... | |
static std::shared_ptr< MultiIndexSet > | FromHDF5 (std::string filename, std::string dsetName="/multiiindices") |
Loads a multiindex set from an HDF5 file. More... | |
static std::shared_ptr< MultiIndexSet > | FromHDF5 (muq::Utilities::H5Object &dset) |
Loads the multiindex from an existing HDF5 group. More... | |
Friends | |
class | MultiIndexFactory |
MultiIndexSet::MultiIndexSet | ( | const unsigned | dimIn, |
std::shared_ptr< MultiIndexLimiter > | limiterIn = std::make_shared<NoLimiter>() |
||
) |
Definition at line 23 of file MultiIndexSet.cpp.
|
virtualdefault |
Default virtual destructor
|
privatedefault |
|
protected |
Definition at line 215 of file MultiIndexSet.cpp.
References active2global, AddBackwardNeighbors(), AddForwardNeighbors(), allMultis, global2active, and maxOrders.
|
virtual |
Make the multi-index active. Assumes that the multiIndex input is already admissible, as checked by an assertion. To be admissable (according to this function), the multiIndex must already exist as an inactive member of this set. If that is not the case, use the AddActive function instead.
[in] | multiIndex | A multiindex to make active. Note that an assert will fail if multiIndex is not admissable. |
Definition at line 239 of file MultiIndexSet.cpp.
References IsAdmissible(), and multi2global.
Referenced by AddActive(), and Expand().
|
virtual |
Add the given multiindex to the set and make it active. The functionality of this function is very similar to Activate; however, this function will add the multiIndex if it does not already exist in the set. This function does not check for admissability. Instead, it will add the multiindex to the set and add all neighbors as inactive. Be careful when using this function as it is possible to create a set with active multiindices that are not admisable.
[in] | newNode | A multiindex we want to add as an active member of the set. |
Definition at line 118 of file MultiIndexSet.cpp.
References Activate(), AddInactive(), and global2active.
Referenced by operator+=(), and Union().
|
protected |
Definition at line 366 of file MultiIndexSet.cpp.
References AddInactive(), allMultis, inEdges, limiter, multi2global, and outEdges.
Referenced by Activate(), and AddMulti().
|
protected |
Definition at line 249 of file MultiIndexSet.cpp.
References AddInactive(), allMultis, inEdges, limiter, multi2global, and outEdges.
Referenced by Activate(), and AddMulti().
|
protected |
Definition at line 134 of file MultiIndexSet.cpp.
References AddMulti(), limiter, and multi2global.
Referenced by AddActive(), AddBackwardNeighbors(), AddForwardNeighbors(), ForciblyActivate(), and Union().
|
private |
Definition at line 95 of file MultiIndexSet.cpp.
References AddBackwardNeighbors(), AddForwardNeighbors(), allMultis, global2active, inEdges, multi2global, and outEdges.
Referenced by AddInactive().
|
inlinevirtual |
This function provides access to each of the MultiIndices.
[in] | activeIndex | The index of the active MultiIndex to return. |
Definition at line 135 of file MultiIndexSet.h.
References IndexToMulti().
|
static |
NOTE: does not perform a deep copy of the multiindices themselves, only pointers to the multiindices.
Definition at line 57 of file MultiIndexSet.cpp.
|
virtual |
If possible, make the neighbors of this index active, and return any that become active. Do not activate a neighbor that is already part of the family.
activeIndex | The linear index of the active multiindex to expand. |
Definition at line 394 of file MultiIndexSet.cpp.
References Activate(), active2global, global2active, IsActive(), IsAdmissible(), and outEdges.
|
protected |
|
virtual |
Add the given multi-index to the active set regardless of whether it's currently admissible. To keep the whole set admissible, recursively add any backward neighbors necessary. Returns a list of indices of any newly added elements, including itself.
multiIndex | The MultiIndex to forcibly add, make active, and make admissable. |
Definition at line 453 of file MultiIndexSet.cpp.
References AddInactive(), limiter, and multi2global.
Referenced by ForciblyExpand().
|
virtual |
Completely expands an index, whether or not it is currently expandable. In order to maintain admissability of the set, it will add backward neighbors needed recursively, and return a list of all the indices it adds.
activeIndex | The linear index of the active multiindex to expand. |
Definition at line 419 of file MultiIndexSet.cpp.
References active2global, ForciblyActivate(), and outEdges.
|
static |
Loads the multiindex from an existing HDF5 group.
This function will read the multiindices in an an HDF5 dataset and construct an instance of the MultiIndexSet class.
[in] | dset | An HDF5 dataset containing an \(N\timesD\) matrix of non-negative integers defining the multiindices. Each row is a multiindex. |
Definition at line 532 of file MultiIndexSet.cpp.
References muq::Utilities::H5Object::cols(), dim, muq::Utilities::H5Object::row(), and muq::Utilities::H5Object::rows().
|
static |
Loads a multiindex set from an HDF5 file.
This function works in tandem with the MultiIndexSet::ToHDF5 function. It will read the multiindices in the HDF5 file and return a pointer to a MultiIndexSet object containing those active multiindices. No limiter information is stored in the HDF5 file, so the limiter in the returned MultiIndexSet will be an instance of the NoLimiter class.
[in] | filename | A string to an HDF5 file. If the file doesn't exist, an exception will be thrown. |
[in] | dsetName | The path to the dataset in the HDF5 file containing the multiindices. |
Definition at line 526 of file MultiIndexSet.cpp.
References muq::Utilities::OpenFile().
|
virtual |
This function returns the admissable forward neighbors of an active multiindex.
[in] | activeIndex | The linear index of the active multiIndex under consideration. |
Definition at line 276 of file MultiIndexSet.cpp.
References active2global, allMultis, IsAdmissible(), and outEdges.
|
inlinevirtual |
Get all the active multiindices in this set.
Definition at line 97 of file MultiIndexSet.h.
References allMultis.
|
virtual |
Returns indices for backward neighbors of an active or inactive multiindex.
Definition at line 332 of file MultiIndexSet.cpp.
References global2active, inEdges, and multi2global.
|
virtual |
Returns the indices for the backward neighbors of a currently active multiindex.
[in] | activeIndex | The linear index of the MultiIndex of interest |
Definition at line 321 of file MultiIndexSet.cpp.
References active2global, global2active, and inEdges.
|
virtual |
Here, we define a term on the "frontier" of the multiindex set as one that has at least one inactive admissable forward neighbors. These terms are expandable.
Definition at line 290 of file MultiIndexSet.cpp.
References active2global, and IsExpandable().
|
inlinevirtual |
Returns the limiter used in this MultiIndexSet.
Definition at line 88 of file MultiIndexSet.h.
References limiter.
|
inlinevirtual |
Assume the \(\mathbf{j}^{\mbox{th}}\) multiindex in this set is given by \(\mathbf{j}=[j_1,j_2,\dots,j_D]\). This function returns a vector containing the maximum value of any multiindex in each direction, i.e., a vector \(\mathbf{m}=[m_1,m_2,\dots,m_D]\) where \(m_d = \max_{\mathbf{j}} j_d\).
Definition at line 128 of file MultiIndexSet.h.
References maxOrders.
|
inlinevirtual |
Get the dimension of the multiindex, i.e. how many components does it have?
Definition at line 119 of file MultiIndexSet.h.
References dim.
Referenced by ToHDF5().
|
virtual |
We define the strict frontier to be the collection of multiindices, whose forward neighbors are all inactive.
Definition at line 302 of file MultiIndexSet.cpp.
References active2global, IsActive(), and outEdges.
|
inlinevirtual |
Given an index into the set, return the corresponding multiindex as an instance of the MultiIndex set. If all the multiindices were stored in a vector called multiVec, the functionality of this method would be equivalent to multiVec[activeIndex].
[in] | activeIndex | Linear index of interest. |
Definition at line 107 of file MultiIndexSet.h.
References active2global, and allMultis.
|
virtual |
Return true if the multiIndex is active.
Definition at line 152 of file MultiIndexSet.cpp.
References multi2global.
Referenced by Expand(), GetStrictFrontier(), IsAdmissible(), IsExpandable(), NumActiveForward(), and SetLimiter().
|
protectedvirtual |
Definition at line 163 of file MultiIndexSet.cpp.
References global2active.
|
virtual |
Determines whether the input multiIndex is currently admissible.
Definition at line 192 of file MultiIndexSet.cpp.
References multi2global.
Referenced by Activate(), Expand(), GetAdmissibleForwardNeighbors(), and IsExpandable().
|
protectedvirtual |
Definition at line 168 of file MultiIndexSet.cpp.
References allMultis, inEdges, IsActive(), and limiter.
|
virtual |
Return true if one of the forward neighbors of index is admissible but not active.
Definition at line 203 of file MultiIndexSet.cpp.
References active2global, IsActive(), IsAdmissible(), and outEdges.
Referenced by GetFrontier().
|
virtual |
Given a multiindex, return the linear index where it is located.
[in] | input | A shared pointer to an instance of the MultiIndex class. |
Definition at line 83 of file MultiIndexSet.cpp.
References global2active, and multi2global.
|
virtual |
Returns the number of active forward neighbors.
Definition at line 347 of file MultiIndexSet.cpp.
References active2global, IsActive(), and outEdges.
|
virtual |
Returns the number of forward neighbors (active or inactive)
Definition at line 360 of file MultiIndexSet.cpp.
References active2global, and outEdges.
|
virtual |
Add another set of multiindices to this one.
Any basis functions in the rhs MultiIndexSet that are not equivalent to basis functions in this instance are added.
[in] | rhs | Another MultiIndex set to add to this one |
Definition at line 472 of file MultiIndexSet.cpp.
References Union().
|
virtual |
Add a single MultiIndex to the set.
This functions checks to see if the input basis function is already in the set and if the input function is unique, it is added to the set.
[in] | rhs | A shared_ptr to the MultiIndex we want to add to the set. |
Definition at line 497 of file MultiIndexSet.cpp.
References AddActive().
|
inlinevirtual |
This function provides access to each of the MultiIndices without any bounds checking on the vector.
[in] | outputIndex | The index of the active MultiIndex we want to return. |
Definition at line 142 of file MultiIndexSet.h.
References active2global, and allMultis.
|
virtual |
Set the limiter of this MultiIndexSet. This function will check to make sure that all currently active nodes are still feasible with the new limiter. If this is not the case, an assert will be thrown.
[in] | limiterIn | A shared pointer to the new limiter. |
Definition at line 30 of file MultiIndexSet.cpp.
References allMultis, inEdges, IsActive(), limiter, and outEdges.
|
inlinevirtual |
Get the number of active MultiIndices in this set.
Definition at line 148 of file MultiIndexSet.h.
References active2global.
void MultiIndexSet::ToHDF5 | ( | muq::Utilities::H5Object & | group, |
std::string | dsetName = "multiindices" |
||
) | const |
Saves the multiindex set to an HDF5 group object.
This function will create (or replace) a dataset in an HDF5 file containing the active multiindices in this set. Note that all information about the multiindex limiter will be lost when saving. The dataset will be an \(N\times D\) matrix of integers, where \(N\) is the number of active multiindices in this set and \(D\) is the length of each multiindex.
[in] | group | An HDF5 object for the group where the dataset should be created. |
[in] | dsetName | A string containing the name of a new dataset to create inside the group. |
Definition at line 511 of file MultiIndexSet.cpp.
References muq::Utilities::H5Object::CreateDataset(), dim, GetMultiLength(), IndexToMulti(), muq::Utilities::H5Object::row(), and Size().
void MultiIndexSet::ToHDF5 | ( | std::string | filename, |
std::string | dsetName = "/multiindices" |
||
) | const |
Saves the multiindex set to a group in an HDF5 file.
This function will create (or replace) a dataset in an HDF5 file containing the active multiindices in this set. Note that all information about the multiindex limiter will be lost when saving. The dataset defaults to "/multiindices" and will contain an \(N\times D\) matrix of integers, where \(N\) is the number of active multiindices in this set and \(D\) is the length of each multiindex.
[in] | filename | A string to the HDF5 file that this multiindexset should be stored in. If the file doesn't exist, it will be created. |
[in] | dsetName | The path to the dataset in the HDF5 file where the multiindices will be stored. If the datset already exists, it will be replaced. Defaults to "/multiindices". |
Definition at line 504 of file MultiIndexSet.cpp.
References muq::Utilities::OpenFile().
|
virtual |
Add all terms in rhs to this instance.
This function adds all unique MultiIndices from the rhs into this MultiIndexSet. In the event that a multiindex is active in one set, but not the other, the union will set that multiindex to be active.
[in] | rhs | The MultiIndex set we want to add to this instance. |
Definition at line 478 of file MultiIndexSet.cpp.
References AddActive(), AddInactive(), allMultis, global2active, limiter, and Size().
Referenced by operator+=().
|
friend |
Definition at line 67 of file MultiIndexSet.h.
|
protected |
Definition at line 344 of file MultiIndexSet.h.
Referenced by Activate(), Expand(), ForciblyExpand(), GetAdmissibleForwardNeighbors(), GetBackwardNeighbors(), GetFrontier(), GetStrictFrontier(), IndexToMulti(), IsExpandable(), NumActiveForward(), NumForward(), operator[](), and Size().
|
protected |
Definition at line 359 of file MultiIndexSet.h.
Referenced by Activate(), AddBackwardNeighbors(), AddForwardNeighbors(), AddMulti(), GetAdmissibleForwardNeighbors(), GetAllMultiIndices(), IndexToMulti(), IsAdmissible(), operator[](), SetLimiter(), and Union().
|
protected |
Definition at line 356 of file MultiIndexSet.h.
Referenced by FromHDF5(), GetMultiLength(), and ToHDF5().
|
protected |
Definition at line 347 of file MultiIndexSet.h.
Referenced by Activate(), AddActive(), AddMulti(), Expand(), GetBackwardNeighbors(), IsActive(), MultiToIndex(), and Union().
|
protected |
Definition at line 351 of file MultiIndexSet.h.
Referenced by AddBackwardNeighbors(), AddForwardNeighbors(), AddMulti(), GetBackwardNeighbors(), IsAdmissible(), and SetLimiter().
|
protected |
Definition at line 362 of file MultiIndexSet.h.
Referenced by AddBackwardNeighbors(), AddForwardNeighbors(), AddInactive(), ForciblyActivate(), GetLimiter(), IsAdmissible(), SetLimiter(), and Union().
|
protected |
Definition at line 353 of file MultiIndexSet.h.
Referenced by Activate(), and GetMaxOrders().
|
private |
Definition at line 368 of file MultiIndexSet.h.
Referenced by Activate(), AddBackwardNeighbors(), AddForwardNeighbors(), AddInactive(), AddMulti(), ForciblyActivate(), GetBackwardNeighbors(), IsActive(), IsAdmissible(), and MultiToIndex().
|
protected |
Definition at line 350 of file MultiIndexSet.h.
Referenced by AddBackwardNeighbors(), AddForwardNeighbors(), AddMulti(), Expand(), ForciblyExpand(), GetAdmissibleForwardNeighbors(), GetStrictFrontier(), IsExpandable(), NumActiveForward(), NumForward(), and SetLimiter().