8 unsigned int const minOrder,
9 shared_ptr<MultiIndexSet> output,
10 unsigned int const currDim,
11 Eigen::RowVectorXi &base,
12 std::shared_ptr<MultiIndexLimiter> limiter)
14 int currOrder = base.head(currDim+1).sum();
15 const int length = base.size();
19 for(
int i=max<int>(0,minOrder-currOrder); i<=maxOrder-currOrder; ++i)
22 auto newTerm = make_shared<MultiIndex>(base);
23 if(limiter->IsFeasible(newTerm))
24 output->AddActive(newTerm);
27 for(
int i=0; i<=maxOrder-currOrder; ++i)
29 base.tail(length-currDim).setZero();
31 RecursiveTotalOrderFill(maxOrder,minOrder,output,currDim+1,base,limiter);
37 shared_ptr<MultiIndexSet> output,
38 unsigned int const currDim,
39 Eigen::RowVectorXi &base,
41 shared_ptr<MultiIndexLimiter> limiter)
44 for(
int i=0; i<currDim; ++i)
45 currNorm += pow(
static_cast<double>(base(i)),q);
47 const int length = base.size();
51 double newNorm = currNorm;
53 while(newNorm<maxNormPow)
55 auto newTerm = make_shared<MultiIndex>(base);
56 if(limiter->IsFeasible(newTerm))
57 output->AddActive(newTerm);
59 newNorm = currNorm + pow(
static_cast<double>(base(length-1)),q);
63 double newNorm = currNorm;
64 base.tail(length-currDim).setZero();
65 while(newNorm<maxNormPow)
67 RecursiveHyperbolicFill(maxNormPow,output,currDim+1,base,q,limiter);
69 newNorm = currNorm + pow(
static_cast<double>(base(currDim)),q);
77 shared_ptr<MultiIndexSet> output,
78 unsigned int const currDim,
79 Eigen::RowVectorXi &base,
80 std::shared_ptr<MultiIndexLimiter> limiter,
83 const unsigned length = base.size();
87 shared_ptr<MultiIndex> newMulti;
89 for(
int i=0; i<=orders(length-1); ++i)
92 newMulti = make_shared<MultiIndex>(base);
94 if(limiter->IsFeasible(newMulti)){
96 output->AddInactive(newMulti);
98 output->AddActive(newMulti);
106 for(
int i=0; i<=orders(currDim); ++i)
108 base.tail(length-currDim).setZero();
110 RecursiveTensor(orders,output,currDim+1,base,limiter, allInactive);
114 base.tail(length-currDim).setZero();
115 base(currDim) = orders(currDim)+1;
116 RecursiveTensor(orders,output,currDim+1,base,limiter,
true);
123 unsigned int const maxOrder,
124 unsigned int const minOrder,
125 std::shared_ptr<MultiIndexLimiter> limiter)
127 assert(maxOrder>=minOrder);
132 shared_ptr<MultiIndexSet> output = make_shared<MultiIndexSet>(length,limiter);
135 Eigen::RowVectorXi base = Eigen::RowVectorXi::Zero(length);
137 RecursiveTotalOrderFill(maxOrder,minOrder,output,0,base,limiter);
143 unsigned int const maxOrder,
144 unsigned int const minOrder,
145 std::shared_ptr<MultiIndexLimiter> limiter)
148 vector<shared_ptr<MultiIndexSet>> multis(length);
149 for(
int d=0; d<length; ++d){
150 auto dimLimiter = make_shared<AndLimiter>(limiter,make_shared<DimensionLimiter>(0,d+1));
151 multis.at(d) = MultiIndexFactory::CreateTotalOrder(length,maxOrder,minOrder,dimLimiter);
157 unsigned int const maxOrder,
159 std::shared_ptr<MultiIndexLimiter> limiter)
165 shared_ptr<MultiIndexSet> output = make_shared<MultiIndexSet>(length,limiter);
168 Eigen::RowVectorXi base = Eigen::RowVectorXi::Zero(length);
170 const double nugget = 1
e-5;
171 RecursiveHyperbolicFill(pow(
static_cast<double>(maxOrder),q)+nugget,output,0,base,q,limiter);
177 unsigned int const maxOrder,
179 std::shared_ptr<MultiIndexLimiter> limiter)
182 vector<shared_ptr<MultiIndexSet>> multis(length);
183 for(
int d=0; d<length; ++d){
184 auto dimLimiter = make_shared<AndLimiter>(limiter,make_shared<DimensionLimiter>(0,d+1));
185 multis.at(d) = MultiIndexFactory::CreateHyperbolic(length,maxOrder,q,dimLimiter);
191 unsigned int const order,
192 std::shared_ptr<MultiIndexLimiter> limiter)
199 std::shared_ptr<MultiIndexLimiter> limiter)
201 assert(orders.minCoeff()>=0);
202 assert(orders.size()>0);
204 unsigned int length = orders.size();
205 unsigned int numIndices = (orders.array()+2).prod();
206 unsigned int numActiveIndices = (orders.array()+1).prod();
209 shared_ptr<MultiIndexSet> output = make_shared<MultiIndexSet>(length,limiter);
212 Eigen::RowVectorXi base = Eigen::RowVectorXi::Zero(length);
214 RecursiveTensor(orders, output, 0, base, limiter,
false);
222 auto getNextIndex = [](Eigen::RowVectorXi base,
unsigned int d) {
223 auto nextIndex = make_shared<MultiIndex>(base);
224 nextIndex->SetValue(d, nextIndex->GetValue(d) + 1);
228 auto limiter = make_shared<AnisotropicLimiter>(weights, epsilon);
229 auto indexSet = make_shared<MultiIndexSet>(weights.size(),limiter);
231 Eigen::RowVectorXi base = Eigen::RowVectorXi::Zero(weights.size());
232 auto nextIndex = make_shared<MultiIndex>(base);
233 indexSet->AddMulti(nextIndex);
239 nextIndex = getNextIndex(base, d);
240 while(!limiter->IsFeasible(nextIndex)) {
244 if (d >= base.size()) {
245 base.conservativeResize(base.size() + 1);
248 }
else if (base.sum() > 0){
250 while ((d < base.size() - 1) && (base[d] == 0))
255 nextIndex = getNextIndex(base, d);
259 indexSet->AddMulti(nextIndex);
265 std::shared_ptr<MultiIndex> MultiIndexFactory::CreateSingleTerm(
int totalDim,
int nonzeroDim,
int order)
267 shared_ptr<MultiIndex> output = make_shared<MultiIndex>(totalDim);
268 output->SetValue(nonzeroDim,order);
static std::shared_ptr< MultiIndexSet > CreateTotalOrder(unsigned int const length, unsigned int const maxOrder, unsigned int const minOrder=0, std::shared_ptr< MultiIndexLimiter > limiter=std::make_shared< NoLimiter >())
Construct a total order limited MultiIndex.
static std::vector< std::shared_ptr< MultiIndexSet > > CreateTriHyperbolic(unsigned int const length, unsigned int const maxOrder, const double q=0.5, std::shared_ptr< MultiIndexLimiter > limiter=std::make_shared< NoLimiter >())
static void RecursiveTensor(const Eigen::RowVectorXi &orders, std::shared_ptr< MultiIndexSet > output, unsigned int const currDim, Eigen::RowVectorXi &base, std::shared_ptr< MultiIndexLimiter > limiter, bool allInactive)
static std::shared_ptr< MultiIndexSet > CreateFullTensor(unsigned int const length, unsigned int const order, std::shared_ptr< MultiIndexLimiter > limiter=std::make_shared< NoLimiter >())
Construct a full tensor product multiindex set.
static std::shared_ptr< MultiIndexSet > CreateHyperbolic(unsigned int const length, unsigned int const maxOrder, const double q=0.5, std::shared_ptr< MultiIndexLimiter > limiter=std::make_shared< NoLimiter >())
Construct a general hyperbolic MultiIndex.
static std::vector< std::shared_ptr< MultiIndexSet > > CreateTriTotalOrder(unsigned int const length, unsigned int const maxOrder, unsigned int const minOrder=0, std::shared_ptr< MultiIndexLimiter > limiter=std::make_shared< NoLimiter >())
static void RecursiveTotalOrderFill(unsigned int const maxOrder, unsigned int const minOrder, std::shared_ptr< MultiIndexSet > output, unsigned int const currDim, Eigen::RowVectorXi &base, std::shared_ptr< MultiIndexLimiter > limiter)
static void RecursiveHyperbolicFill(const double maxOrderPow, std::shared_ptr< MultiIndexSet > output, unsigned int const currDim, Eigen::RowVectorXi &base, const double q, std::shared_ptr< MultiIndexLimiter > limiter)
static std::shared_ptr< MultiIndexSet > CreateAnisotropic(const Eigen::RowVectorXf &weights, const double epsilon)
Construct an anisotropic multiindex set based on a priori information on the importance of each dimen...