10 std::shared_ptr<MultiIndexSet> y)
17 std::shared_ptr<MultiIndex> y)
24 shared_ptr<MultiIndexLimiter> limiterIn) : maxOrders(Eigen::VectorXi::Zero(dimIn)),
34 for(
int globalInd=0; globalInd<
allMultis.size(); ++globalInd)
37 if(!limiterIn->IsFeasible(
allMultis.at(globalInd))){
38 std::stringstream msg;
39 msg <<
"Invalid limiter passed to MultiIndexSet::SetLimiter. The active multi-index, ";
40 msg <<
allMultis.at(globalInd)->GetVector() <<
", is not valid with the new limiter.\n";
41 throw std::invalid_argument(msg.str());
45 if(!limiterIn->IsFeasible(
allMultis.at(globalInd))){
46 for(
int inNode :
inEdges[globalInd])
59 auto output = make_shared<MultiIndexSet>(original->dim, original->limiter);
61 output->active2global = original->active2global;
62 output->outEdges = original->outEdges;
63 output->inEdges = original->inEdges;
64 output->maxOrders = original->maxOrders;
65 output->allMultis = original->allMultis;
104 inEdges.push_back(std::set<int>());
105 outEdges.push_back(std::set<int>());
142 }
else if(
limiter->IsFeasible(newNode)){
172 if(!
limiter->IsFeasible(multi))
180 for(
int inNode :
inEdges.at(globalIndex)){
185 if(numAdmiss==multi->nzInds.size()){
221 auto& newNode =
allMultis.at(globalIndex);
231 for(
auto pair : newNode->nzInds)
252 Eigen::RowVectorXi base =
allMultis.at(globalIndex)->GetVector();
254 shared_ptr<MultiIndex> newNode;
255 for(
unsigned int i=0; i<base.size(); ++i)
259 newNode = make_shared<MultiIndex>(base);
261 if(
limiter->IsFeasible(newNode)){
266 inEdges.at(iter->second).insert(globalIndex);
267 outEdges.at(globalIndex).insert(iter->second);
268 }
else if(addInactive){
280 vector<shared_ptr<MultiIndex>> output;
281 for(
auto neighbor :
outEdges[globalInd])
284 output.push_back(
allMultis.at(neighbor));
292 std::vector<unsigned int> frontierInds;
294 for(
unsigned int activeInd = 0; activeInd<
active2global.size(); ++activeInd) {
296 frontierInds.push_back(activeInd);
304 std::vector<unsigned int> frontierInds;
306 for(
unsigned int activeInd = 0; activeInd<
active2global.size(); ++activeInd) {
310 bool isStrict =
true;
311 for(
auto neighbor :
outEdges[globalInd])
312 isStrict = isStrict && (!
IsActive(neighbor));
315 frontierInds.push_back(activeInd);
325 std::vector<unsigned int> output;
326 for(
auto neighbor :
inEdges[globalInd])
338 unsigned int globalInd = iter->second;
339 std::vector<unsigned int> output;
340 for(
auto neighbor :
inEdges[globalInd])
351 unsigned int numActive = 0;
352 for(
auto neighbor :
outEdges[globalInd])
368 Eigen::RowVectorXi base =
allMultis.at(globalIndex)->GetVector();
370 shared_ptr<MultiIndex> newNode;
371 for(
unsigned int i=0; i<base.size(); ++i)
377 newNode = make_shared<MultiIndex>(base);
379 if(
limiter->IsFeasible(newNode)){
383 outEdges.at(iter->second).insert(globalIndex);
384 inEdges.at(globalIndex).insert(iter->second);
385 }
else if(addInactive){
397 std::stringstream msg;
398 msg <<
"Invalid index passed to MultiIndexSet::Expand. A value of " << activeIndex <<
" was passed to the function, but only " <<
active2global.size() <<
" active components exist in the set.\n";
399 throw std::out_of_range(msg.str());
402 vector<unsigned> newIndices;
406 std::set<int> tempSet =
outEdges.at(globalIndex);
407 for(
int neighbor : tempSet)
423 vector<unsigned> newIndices;
427 std::set<int>& tempSet =
outEdges.at(globalIndex);
428 for(
int neighbor : tempSet)
446 std::set<int>& tempSet =
inEdges.at(globalIndex);
447 for(
int ind : tempSet)
455 assert(
limiter->IsFeasible(multiIndex));
458 vector<unsigned int> newIndices;
480 int oldTerms =
Size();
482 for(
int i = 0; i < rhs.
allMultis.size(); ++i) {
485 if(
limiter->IsFeasible(newMulti)){
494 return Size() - oldTerms;
514 unsigned int numTerms =
Size();
521 for(
unsigned int i=0; i<numTerms; ++i)
534 unsigned int numTerms = dset.
rows();
535 unsigned int dim = dset.
cols();
538 auto output = std::make_shared<MultiIndexSet>(
dim);
541 for(
unsigned int i=0; i<numTerms; ++i){
542 auto multi = std::make_shared<MultiIndex>(dset.
row(i));
543 output->AddActive(multi);
H5Object & CreateDataset(std::string const &setName, unsigned int rows, unsigned int cols=0)
BlockDataset row(unsigned row) const
A class for holding, sorting, and adapting sets of multiindices.
std::vector< std::shared_ptr< MultiIndex > > allMultis
virtual bool IsActive(std::shared_ptr< MultiIndex > const &multiIndex) const
Return true if the multiIndex is active.
virtual bool IsExpandable(unsigned int activeIndex) const
Return true if one of the forward neighbors of index is admissible but not active.
virtual MultiIndexSet & operator+=(const MultiIndexSet &rhs)
Add another set of multiindices to this one.
virtual std::vector< unsigned > Expand(unsigned int activeIndex)
virtual unsigned int Size() const
std::shared_ptr< MultiIndexLimiter > limiter
static std::shared_ptr< MultiIndexSet > FromHDF5(std::string filename, std::string dsetName="/multiiindices")
Loads a multiindex set from an HDF5 file.
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.
virtual int Union(const MultiIndexSet &rhs)
Add all terms in rhs to this instance.
virtual unsigned int NumActiveForward(unsigned int activeInd) const
Returns the number of active forward neighbors.
virtual void SetLimiter(std::shared_ptr< MultiIndexLimiter > const &limiterIn)
virtual unsigned int NumForward(unsigned int activeInd) const
Returns the number of forward neighbors (active or inactive)
std::vector< std::set< int > > inEdges
virtual std::vector< unsigned int > GetStrictFrontier() const
virtual std::vector< unsigned int > GetFrontier() const
Eigen::VectorXi maxOrders
virtual unsigned int GetMultiLength() const
void AddBackwardNeighbors(unsigned int globalIndex, bool addInactive)
std::vector< std::set< int > > outEdges
std::map< std::shared_ptr< MultiIndex >, unsigned int, MultiPtrComp > multi2global
std::vector< int > global2active
virtual std::vector< unsigned > ForciblyActivate(std::shared_ptr< MultiIndex > const &multiIndex)
virtual int MultiToIndex(std::shared_ptr< MultiIndex > const &input) const
virtual void Activate(std::shared_ptr< MultiIndex > const &multiIndex)
void ToHDF5(std::string filename, std::string dsetName="/multiindices") const
Saves the multiindex set to a group in an HDF5 file.
int AddInactive(std::shared_ptr< MultiIndex > const &newNode)
int AddMulti(std::shared_ptr< MultiIndex > const &newMulti)
void AddForwardNeighbors(unsigned int globalIndex, bool addInactive)
virtual bool IsAdmissible(std::shared_ptr< MultiIndex > const &multiIndex) const
Determines whether the input multiIndex is currently admissible.
virtual std::vector< unsigned > ForciblyExpand(unsigned int const activeIndex)
virtual int AddActive(std::shared_ptr< MultiIndex > const &newNode)
virtual std::shared_ptr< MultiIndex > const & IndexToMulti(unsigned activeIndex) const
virtual std::vector< std::shared_ptr< MultiIndex > > GetAdmissibleForwardNeighbors(unsigned int activeIndex)
virtual std::vector< unsigned int > GetBackwardNeighbors(unsigned int activeIndex) const
std::vector< unsigned > active2global
std::shared_ptr< MultiIndexSet > operator+=(std::shared_ptr< MultiIndexSet > x, std::shared_ptr< MultiIndexSet > y)
H5Object OpenFile(std::string const &filename)
Open an HDF5 file and return the root object.