MUQ  0.4.3
MultiIndexLimiter.cpp
Go to the documentation of this file.
2 
3 
4 bool muq::Utilities::DimensionLimiter::IsFeasible(std::shared_ptr<MultiIndex> multi) const{
5 
6  for(auto pair = multi->GetNzBegin(); pair!=multi->GetNzEnd(); ++pair){
7  if(((pair->first<lowerDim)||(pair->first>=lowerDim+length))&&(pair->second!=0))
8  return false;
9  }
10  return true;
11 };
12 
13 muq::Utilities::AnisotropicLimiter::AnisotropicLimiter(const Eigen::RowVectorXf& weightsIn, const double epsilonIn) : weights(weightsIn), epsilon(epsilonIn) {
14 
15  // validate weight vector
16  for(int i = 0; i < weights.size(); ++i){
17  if (weights(i) > 1 || weights[i] < 0)
18  throw std::invalid_argument("AnisotropicLimiter requires all weights have to be in [0,1]. Got weight " + std::to_string(weights[i]));
19  }
20  // validate threshold
21  if (epsilon >= 1 || epsilon <= 0)
22  throw std::invalid_argument("AnisotropicLimiter requires epsilon to be in (0,1). Got epsilon = " + std::to_string(epsilon));
23 };
24 
25 bool muq::Utilities::AnisotropicLimiter::IsFeasible(std::shared_ptr<MultiIndex> multi) const{
26 
27  double prod = 1;
28  for(auto pair = multi->GetNzBegin(); pair!=multi->GetNzEnd(); ++pair){
29  if(pair->first >= weights.size())
30  return false;
31  prod *= std::pow(weights(pair->first),(int)pair->second);
32  }
33  return prod >= epsilon;
34 };
35 
36 bool muq::Utilities::MaxOrderLimiter::IsFeasible(std::shared_ptr<MultiIndex> multi) const{
37 
38  if(maxOrders.size()==0){
39  return (multi->Max() <= maxOrder);
40  }else{
41  assert(multi->GetLength()<=maxOrders.size());
42 
43  if(multi->Max() <= vectorMin)
44  return true;
45 
46  for(auto nzIter = multi->GetNzBegin(); nzIter!=multi->GetNzEnd(); ++nzIter){
47  if(nzIter->second>maxOrders(nzIter->first)){
48  return false;
49  }
50  }
51  return true;
52  }
53 };
const Eigen::RowVectorXf & weights
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
AnisotropicLimiter(const Eigen::RowVectorXf &weightsIn, const double epsilonIn)
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.h:25172