gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
plugin.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
10 //
16 
17 #ifndef PLUGIN_PRIOR_HPP
18 #define PLUGIN_PRIOR_HPP
19 
22 
23 namespace Gambit
24 {
25  namespace Priors
26  {
27  class Plugin : public BasePrior
28  {
29  private:
30  typedef Scanner::Plugins::Plugin_Interface<double (const std::vector<double> &), void (const std::vector<double> &, std::unordered_map<std::string,double> &)> plugin_type;
31  mutable plugin_type *plugin;
32 
33  public:
34  Plugin(const std::vector<std::string>& params, const Options& options) : BasePrior(params)
35  {
36  std::string plugin_name;
37  if (options.hasKey("plugin"))
38  {
39  plugin_name = options.getValue<std::string>("plugin");
40  }
41  else
42  {
43  scan_err << "Plugin prior: need to specify plugin with \"plugin\" tag." << scan_end;
44  plugin_name = "";
45  }
46  plugin = new plugin_type("objective", plugin_name, param_names, sizeRef());
47  }
48 
49  void transform(const std::vector<double> &unitpars, std::unordered_map<std::string,double> &outputMap) const
50  {
51  return (*plugin)(unitpars, outputMap);
52  }
53 
54  std::vector<double> inverse_transform(const std::unordered_map<std::string, double> &) const override
55  {
56  scan_err << "inverse transform not supported in plugin prior" << scan_end;
57  return {};
58  }
59 
60  double operator()(const std::vector<double>& vec) const
61  {
62  return (*plugin)(vec);
63  }
64 
66  {
67  delete plugin;
68  }
69  };
70 
72  }
73 }
74 
75 #endif
Abstract base class for priors.
Definition: base_prior.hpp:40
Interface details for scanner plugins.
std::vector< std::string > param_names
Definition: base_prior.hpp:46
Prior object construction routines.
std::vector< double > inverse_transform(const std::unordered_map< std::string, double > &) const override
Transform from parameter back to unit hypercube.
Definition: plugin.hpp:54
void transform(const std::vector< double > &unitpars, std::unordered_map< std::string, double > &outputMap) const
Transform from unit hypercube to parameter.
Definition: plugin.hpp:49
bool hasKey(const args &... keys) const
Getters for key/value pairs (which is all the options node should contain)
TYPE getValue(const args &... keys) const
double operator()(const std::vector< double > &vec) const
Log of PDF density.
Definition: plugin.hpp:60
#define scan_err
Defined to macros to output errors in the form: scan_err << "error" << scan_end; scan_warn << "warnin...
Interface for a ScannerBit plugin.
RangePrior1D< flatprior > LOAD_PRIOR(cos, RangePrior1D< cosprior >) LOAD_PRIOR(sin
Plugin(const std::vector< std::string > &params, const Options &options)
Definition: plugin.hpp:34
#define scan_end
unsigned int & sizeRef()
Definition: base_prior.hpp:81
plugin_type * plugin
Definition: plugin.hpp:31
std::vector< T > vec(std::vector< T > vector)
Definition: daFunk.hpp:142
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.
Scanner::Plugins::Plugin_Interface< double(const std::vector< double > &), void(const std::vector< double > &, std::unordered_map< std::string, double > &)> plugin_type
Definition: plugin.hpp:30