MUQ  0.4.3
MultiIndexLimiter.h
Go to the documentation of this file.
1 #ifndef MULTIINDEXLIMITER_H_
2 #define MULTIINDEXLIMITER_H_
3 
4 #include <memory>
5 
7 
8 namespace muq{
9 namespace Utilities{
10 
18 
19  public:
20  virtual ~MultiIndexLimiter() = default;
21 
23  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const = 0;
24 
25  }; // class MultiIndexLimiter
26 
33 
34  public:
35 
36  TotalOrderLimiter(unsigned int totalOrderIn) : totalOrder(totalOrderIn){};
37  virtual ~TotalOrderLimiter() = default;
38 
39  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override {return (multi->Sum() <= totalOrder);};
40 
41  private:
43 
44  unsigned int totalOrder;
45 
46  }; // class TotalOrderLimiter
47 
48 
55 
56  public:
57 
58  DimensionLimiter(unsigned int lowerDimIn, unsigned int lengthIn) : lowerDim(lowerDimIn), length(lengthIn){};
59  virtual ~DimensionLimiter() = default;
60 
61  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override;
62 
63  private:
65 
66  unsigned int lowerDim;
67  unsigned int length;
68 
69  }; // class DimensionLimiter
70 
71 
82 
83  public:
84 
85  AnisotropicLimiter(const Eigen::RowVectorXf& weightsIn, const double epsilonIn);
86 
87  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override;
88 
89  private:
90  const Eigen::RowVectorXf& weights;
91  const double epsilon;
92 
93  }; // class AnisotropicLimiter
94 
95 
101  /*
102  class GeneralLimiter : public MultiIndexLimiter{
103  friend class boost::serialization::access;
104 
105  public:
106  GeneralLimiter(std::shared_ptr<MultiIndexSet> limitingSetIn) : limitingSet(limitingSetIn){};
107  virtual ~GeneralLimiter() = default;
108 
109  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override;
110 
111  private:
112  GeneralLimiter(){};
113 
114  std::shared_ptr<MultiIndexSet> limitingSet;
115 
116  template<class Archive>
117  void serialize(Archive & ar, const unsigned int version){
118  ar & boost::serialization::base_object<MultiIndexLimiter>(*this);
119  ar & limitingSet;
120  };
121 
122  };*/ // class GeneralLimiter
123 
130 
131  public:
132  MaxOrderLimiter(unsigned int maxOrderIn) : maxOrder(maxOrderIn){};
133  MaxOrderLimiter(Eigen::VectorXi const& maxOrdersIn) : maxOrder(-1), maxOrders(maxOrdersIn), vectorMin(maxOrdersIn.minCoeff()){};
134 
135  virtual ~MaxOrderLimiter() = default;
136 
137  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override;
138 
139  private:
141 
142  int maxOrder;
143  Eigen::VectorXi maxOrders;
145 
146  }; // class MaxOrderLimiter
147 
153  class NoLimiter : public MultiIndexLimiter{
154 
155  public:
156  virtual ~NoLimiter() = default;
157  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override {return true;};
158 
159  }; // class NoLimiter
160 
167 
168  public:
169  AndLimiter(std::shared_ptr<MultiIndexLimiter> limitA, std::shared_ptr<MultiIndexLimiter> limitB) : a(limitA), b(limitB){};
170  virtual ~AndLimiter() = default;
171  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override {return (a->IsFeasible(multi)&&b->IsFeasible(multi));};
172 
173  private:
175  std::shared_ptr<MultiIndexLimiter> a, b;
176 
177  }; // class AndLimiter
178 
184  class OrLimiter : public MultiIndexLimiter{
185 
186  public:
187  OrLimiter(std::shared_ptr<MultiIndexLimiter> limitA, std::shared_ptr<MultiIndexLimiter> limitB) : a(limitA), b(limitB){};
188  virtual ~OrLimiter() = default;
189  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override {return (a->IsFeasible(multi)||b->IsFeasible(multi));};
190 
191  private:
193  std::shared_ptr<MultiIndexLimiter> a, b;
194 
195  }; // class OrLimiter
196 
197 
204 
205  public:
206  XorLimiter(std::shared_ptr<MultiIndexLimiter> limitA, std::shared_ptr<MultiIndexLimiter> limitB) : a(limitA), b(limitB){};
207  virtual ~XorLimiter() = default;
208  virtual bool IsFeasible(std::shared_ptr<MultiIndex> multi) const override {return (a->IsFeasible(multi)^b->IsFeasible(multi));};
209 
210  private:
212  std::shared_ptr<MultiIndexLimiter> a, b;
213 
214  }; // class XorLimiter
215 
216 } // namespace muq
217 } // namespace Utilities
218 
219 #endif
Combines two limiters through an AND operation.
std::shared_ptr< MultiIndexLimiter > a
std::shared_ptr< MultiIndexLimiter > b
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
virtual ~AndLimiter()=default
AndLimiter(std::shared_ptr< MultiIndexLimiter > limitA, std::shared_ptr< MultiIndexLimiter > limitB)
Declares multiindices as feasible if their entries for less important dimensions are not too high.
const Eigen::RowVectorXf & weights
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
AnisotropicLimiter(const Eigen::RowVectorXf &weightsIn, const double epsilonIn)
Provides bounds on what dimensions are allowed to have nonzero values.
DimensionLimiter(unsigned int lowerDimIn, unsigned int lengthIn)
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
virtual ~DimensionLimiter()=default
Provides a cap on the maximum value of each component the multiindex.
virtual ~MaxOrderLimiter()=default
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
MaxOrderLimiter(Eigen::VectorXi const &maxOrdersIn)
MaxOrderLimiter(unsigned int maxOrderIn)
An abstract base class for multi index limiters.
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const =0
virtual ~MultiIndexLimiter()=default
Returns true for an multiindex.
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
virtual ~NoLimiter()=default
Combines two limiters through an OR operation.
OrLimiter(std::shared_ptr< MultiIndexLimiter > limitA, std::shared_ptr< MultiIndexLimiter > limitB)
virtual ~OrLimiter()=default
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
std::shared_ptr< MultiIndexLimiter > a
std::shared_ptr< MultiIndexLimiter > b
Provides a cap on the total-order allowed.
virtual ~TotalOrderLimiter()=default
TotalOrderLimiter(unsigned int totalOrderIn)
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
Combines two limiters through an XOR operation.
XorLimiter(std::shared_ptr< MultiIndexLimiter > limitA, std::shared_ptr< MultiIndexLimiter > limitB)
virtual bool IsFeasible(std::shared_ptr< MultiIndex > multi) const override
std::shared_ptr< MultiIndexLimiter > a
virtual ~XorLimiter()=default
std::shared_ptr< MultiIndexLimiter > b