31 #ifndef __TSG_HIERARCHY_MANIPULATOR_HPP
32 #define __TSG_HIERARCHY_MANIPULATOR_HPP
34 #include "tsgRuleLocalPolynomial.hpp"
74 namespace HierarchyManipulations{
87 template<RuleLocal::erule effrule>
108 template<RuleLocal::erule effrule>
122 template<RuleLocal::erule effrule>
131 template<RuleLocal::erule effrule>
147 template<RuleLocal::erule effrule>
156 template<RuleLocal::erule effrule,
typename callable_method>
158 int max_kids = RuleLocal::getMaxNumKids<effrule>();
159 for(
auto &v : point){
163 v = RuleLocal::getParent<effrule>(save);
165 int parent_index = mset.
getSlot(point);
166 if (parent_index > -1)
170 v = RuleLocal::getStepParent<effrule>(save);
172 int parent_index = mset.
getSlot(point);
173 if (parent_index > -1)
177 for(
int k=0; k<max_kids; k++){
178 v = RuleLocal::getKid<effrule>(save, k);
180 int kid_index = mset.
getSlot(point);
197 template<RuleLocal::erule effrule>
200 while(RuleLocal::getParent<effrule>(num_parents) == -1) num_parents++;
211 template<RuleLocal::erule effrule>
217 MultiIndexSet level_zero = getLevelZeroPoints<effrule>(num_dimensions);
223 if (!total.
empty()) level_zero = level_zero - total;
228 std::vector<int> p(level_zero.
getIndex(i), level_zero.
getIndex(i) + num_dimensions);
239 int max_kids = RuleLocal::getMaxNumKids<effrule>();
240 int max_relatives = RuleLocal::getMaxNumParents<effrule>() + max_kids;
246 std::vector<int> relative(total.
getIndex(i), total.
getIndex(i) + num_dimensions);
247 for(
auto &r : relative){
249 for(
int j=0; j<max_relatives; j++){
250 r = (j < max_kids) ? RuleLocal::getKid<effrule>(k, j)
251 : ((j - max_kids == 0) ? RuleLocal::getParent<effrule>(k) : RuleLocal::getStepParent<effrule>(k));
252 if ((r != -1) && !candidates.
missing(relative) && total.
missing(relative))
261 result += update_set;
278 std::vector<Data2D<T>>
splitByLevels(
size_t stride,
typename std::vector<T>::const_iterator ibegin,
typename std::vector<T>::const_iterator iend, std::vector<int>::const_iterator ilevels){
279 size_t top_level = (size_t) *std::max_element(ilevels, ilevels + std::distance(ibegin, iend) / stride);
281 std::vector<Data2D<T>> split(top_level + 1,
Data2D<T>(stride, 0));
283 for(
struct { std::vector<int>::const_iterator il;
typename std::vector<T>::const_iterator idata;} v = {ilevels, ibegin};
285 v.il++, std::advance(v.idata, stride))
286 split[*v.il].appendStrip(v.idata);
305 return splitByLevels<T>(data.
getStride(), data.
begin(), data.
end(), levels.begin());
313 return splitByLevels<double>(stortage.
getNumOutputs(), stortage.
begin(), stortage.
end(), levels.begin());
339 int getMaxNumPoints()
const {
return (job_pnts.size() > 0) ? (int) std::max_element(job_pnts.begin(), job_pnts.end(),
340 [&](std::vector<int>
const &a, std::vector<int>
const& b)->
bool{
return (a.size() < b.size()); })->size() : 0; }
343 std::vector<int> job_directions;
344 std::vector<std::vector<int>> job_pnts;
Generic 2D data structure divided into contiguous strips of fixed length (similar to a matrix).
Definition: tsgIndexSets.hpp:104
std::vector< T >::iterator begin()
Returns an iterator to the beginning of the internal data.
Definition: tsgIndexSets.hpp:167
void appendStrip(typename std::vector< T >::const_iterator const &x)
Uses std::vector::insert to append the data.
Definition: tsgIndexSets.hpp:179
std::vector< T >::iterator end()
Returns an iterator to the end of the internal data.
Definition: tsgIndexSets.hpp:171
int getNumStrips() const
Returns the number of strips.
Definition: tsgIndexSets.hpp:149
size_t getStride() const
Returns the stride.
Definition: tsgIndexSets.hpp:147
Reorganize the points into sets of nodes that align in one-dimension, used for directional localp ref...
Definition: tsgHierarchyManipulator.hpp:323
int getJobDirection(int job) const
Return the direction for the job.
Definition: tsgHierarchyManipulator.hpp:333
int getNumJobs() const
Returns the number of one dimensional jobs.
Definition: tsgHierarchyManipulator.hpp:331
~SplitDirections()
Destroy all data.
Definition: tsgHierarchyManipulator.hpp:328
SplitDirections(const MultiIndexSet &points)
Constructor, deinfe the set to split into directions.
int getMaxNumPoints() const
Return the max number of points for any job.
Definition: tsgHierarchyManipulator.hpp:339
int getJobNumPoints(int job) const
Return the number of points associated with the job.
Definition: tsgHierarchyManipulator.hpp:335
const int * getJobPoints(int job) const
Return the indexes of the points associated with the job.
Definition: tsgHierarchyManipulator.hpp:337
Class that stores multi-indexes in sorted (lexicographical) order.
Definition: tsgIndexSets.hpp:234
size_t getNumDimensions() const
Returns the number of dimensions.
Definition: tsgIndexSets.hpp:263
int getSlot(const int *p) const
Returns the slot containing index p, returns -1 if not found.
bool missing(const std::vector< int > &p) const
Returns true if p is missing from the set, false otherwise.
Definition: tsgIndexSets.hpp:291
const int * getIndex(int i) const
Returns the i-th index of the set, useful to loop over all indexes or to cross reference with values.
Definition: tsgIndexSets.hpp:294
int getNumIndexes() const
Returns the number of indexes.
Definition: tsgIndexSets.hpp:265
bool empty() const
Returns true if there are no multi-indexes in the set, false otherwise.
Definition: tsgIndexSets.hpp:260
std::vector< int >::const_iterator begin() const
Returns a const iterator to the beginning of the internal data.
Definition: tsgIndexSets.hpp:277
std::vector< int >::const_iterator end() const
Returns a const iterator to the end of the internal data.
Definition: tsgIndexSets.hpp:279
Class that stores values, i.e., model outputs, the order of the values is in sync with the order of s...
Definition: tsgIndexSets.hpp:334
size_t getNumOutputs() const
Returns the number of outputs.
Definition: tsgIndexSets.hpp:366
std::vector< double >::const_iterator end() const
Returns a const iterator to the end of the internal data.
Definition: tsgIndexSets.hpp:389
std::vector< double >::const_iterator begin() const
Returns a const iterator to the beginning of the internal data.
Definition: tsgIndexSets.hpp:387
void completeToLower(MultiIndexSet const &mset, MultiIndexSet &refined)
Complete refined so that the union of refined and mset is lower w.r.t. the rule. .
MultiIndexSet getLevelZeroPoints(size_t num_dimensions)
Return the tensor set of all points that sit on level zero (i.e., have no parents).
Definition: tsgHierarchyManipulator.hpp:198
MultiIndexSet getLargestConnected(MultiIndexSet const ¤t, MultiIndexSet const &candidates)
Return the largest subset of candidates such that adding it to current will result in a connected gra...
Definition: tsgHierarchyManipulator.hpp:212
Data2D< int > computeDAGup(MultiIndexSet const &mset)
Cache the indexes slot numbers of the parents of the multi-indexes in mset.
std::vector< int > computeLevels(MultiIndexSet const &mset)
Returns a vector that is the sum of the one dimensional levels of each multi-index in the set....
Data2D< int > computeDAGDown(MultiIndexSet const &mset)
Cache the indexes slot numbers of the children of the multi-indexes in mset.
std::vector< Data2D< T > > splitByLevels(size_t stride, typename std::vector< T >::const_iterator ibegin, typename std::vector< T >::const_iterator iend, std::vector< int >::const_iterator ilevels)
Split the range between ibegin and iend into strips of stride and orders those by levels according to...
Definition: tsgHierarchyManipulator.hpp:278
void touchAllImmediateRelatives(std::vector< int > &point, MultiIndexSet const &mset, callable_method apply)
Will call apply() with the slot index in mset of each parent/child of point..
Definition: tsgHierarchyManipulator.hpp:157
MultiIndexSet generateFullTensorSet(std::vector< int > const &num_entries)
Create a full-tensor multi-index set with num_entries in each direction.
Definition: tsgIndexManipulator.hpp:79
Encapsulates the Tasmanian Sparse Grid module.
Definition: TasmanianSparseGrid.hpp:68
Algorithms for manipulating sets of multi-indexes.