MUQ  0.4.3
SamplingAlgorithm.h
Go to the documentation of this file.
1 #ifndef SAMPLINGALGORITHM_H_
2 #define SAMPLINGALGORITHM_H_
3 
4 #include "MUQ/config.h"
5 
6 #if MUQ_HAS_PARCER
7 #include <parcer/Communicator.h>
8 #endif
9 
10 #include "MUQ/Modeling/WorkPiece.h"
11 
14 
15 
16 namespace muq {
17  namespace SamplingAlgorithms {
18 
19 
20  class SamplingAlgorithm {//} : public muq::Modeling::WorkPiece {
21  public:
22 
23  SamplingAlgorithm(std::shared_ptr<SampleCollection> const& samples);
24 
25  SamplingAlgorithm(std::shared_ptr<SampleCollection> const& samplesIn, std::shared_ptr<SampleCollection> const& QOIsIn);
26 
27 #if MUQ_HAS_PARCER
28  SamplingAlgorithm(std::shared_ptr<SampleCollection> const& samplesIn, std::shared_ptr<parcer::Communicator> const& comm);
29 #endif
30 
31  virtual ~SamplingAlgorithm() = default;
32 
33  virtual std::shared_ptr<SampleCollection> GetSamples() const;
34 
35  virtual std::shared_ptr<SampleCollection> GetQOIs() const;
36 
37  virtual void SetState(std::vector<Eigen::VectorXd> const& x0);
38 
39  virtual std::shared_ptr<SampleCollection> Run(std::vector<Eigen::VectorXd> const& x0 = std::vector<Eigen::VectorXd>());
40 
41  template<typename... Args>
42  inline std::shared_ptr<SampleCollection> Run(Args const&... args) {
43  std::vector<Eigen::VectorXd> vec;
44  return RunRecurse(vec, args...);
45  }
46 
47 #if MUQ_HAS_PARCER
48  std::shared_ptr<parcer::Communicator> GetCommunicator() const;
49 #endif
50 
51  protected:
52 
53  virtual std::shared_ptr<SampleCollection> RunImpl(std::vector<Eigen::VectorXd> const& x0) = 0;
54 
63  //virtual void EvaluateImpl(muq::Modeling::ref_vector<boost::any> const& inputs) override;
64 
65  std::shared_ptr<SampleCollection> samples;
66 
67  std::shared_ptr<SampleCollection> QOIs;
68 
69 #if MUQ_HAS_PARCER
70  std::shared_ptr<parcer::Communicator> comm = nullptr;
71 #endif
72 
73  private:
74 
75  template<typename... Args>
76  inline std::shared_ptr<SampleCollection> RunRecurse(std::vector<Eigen::VectorXd>& vec, Eigen::VectorXd const& ith, Args const&... args) {
77  vec.push_back(ith);
78  return RunRecurse(vec, args...);
79  }
80 
81  inline std::shared_ptr<SampleCollection> RunRecurse(std::vector<Eigen::VectorXd>& vec, Eigen::VectorXd const& last) {
82  vec.push_back(last);
83  return Run(vec);
84  }
85  };
86  } // namespace SamplingAlgorithms
87 } // namespace muq
88 
89 #endif
virtual std::shared_ptr< SampleCollection > GetSamples() const
virtual void SetState(std::vector< Eigen::VectorXd > const &x0)
virtual std::shared_ptr< SampleCollection > RunImpl(std::vector< Eigen::VectorXd > const &x0)=0
std::shared_ptr< SampleCollection > QOIs
virtual std::shared_ptr< SampleCollection > GetQOIs() const
std::shared_ptr< SampleCollection > RunRecurse(std::vector< Eigen::VectorXd > &vec, Eigen::VectorXd const &last)
std::shared_ptr< parcer::Communicator > comm
std::shared_ptr< parcer::Communicator > GetCommunicator() const
std::shared_ptr< SampleCollection > RunRecurse(std::vector< Eigen::VectorXd > &vec, Eigen::VectorXd const &ith, Args const &... args)
virtual std::shared_ptr< SampleCollection > Run(std::vector< Eigen::VectorXd > const &x0=std::vector< Eigen::VectorXd >())
std::shared_ptr< SampleCollection > Run(Args const &... args)
SamplingAlgorithm(std::shared_ptr< SampleCollection > const &samples)
std::shared_ptr< SampleCollection > samples
const char * last
Definition: json.h:15399