gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
grid.cpp File Reference

Grid sampler. More...

#include <vector>
#include <string>
#include <cmath>
#include <iostream>
#include <sstream>
#include "gambit/ScannerBit/scanner_plugin.hpp"
Include dependency graph for grid.cpp:

Go to the source code of this file.

Functions

std::vector< std::unordered_set< std::string > > parse_sames (const std::vector< std::string > &params)
 
 scanner_plugin (grid, version(1, 0, 0))
 

Detailed Description

Grid sampler.


Authors (add name and date if you modify):

Definition in file grid.cpp.

Function Documentation

◆ parse_sames()

std::vector<std::unordered_set<std::string> > parse_sames ( const std::vector< std::string > &  params)
inline
Author
Gregory Martinez (grego.nosp@m.ry.d.nosp@m.avid..nosp@m.mart.nosp@m.inez@.nosp@m.gmai.nosp@m.l.com)
Date
2013 August

Definition at line 31 of file grid.cpp.

Referenced by scanner_plugin().

32 {
33  std::vector<std::unordered_set<std::string>> paramSet(params.size());
34 
35  for (int i = 0, end = params.size(); i < end; i++)
36  {
37  std::string::size_type pos_old = 0;
38  std::string::size_type pos = params[i].find("+");
39  while (pos != std::string::npos)
40  {
41  paramSet[i].insert(params[i].substr(pos_old, (pos-pos_old)));
42  pos_old = pos + 1;
43  pos = params[i].find("+", pos_old);
44  }
45 
46  paramSet[i].insert(params[i].substr(pos_old));
47  }
48 
49  return paramSet;
50 }
Here is the caller graph for this function:

◆ scanner_plugin()

scanner_plugin ( grid  ,
version(1, 0, 0)   
)

Definition at line 52 of file grid.cpp.

References double, int, generate_raster_scan_settings::n, generate_raster_scan_settings::N, parse_sames(), plugin_constructor, plugin_main, combine_hdf5::rank, reqd_inifile_entries, scan_end, scan_err, and daFunk::vec().

53 {
54  reqd_inifile_entries("grid_pts");
55 
57  {
58 
59  }
60 
61  int plugin_main()
62  {
63  int ma = get_dimension();
64  int numtasks;
65  int rank;
66 
67 #ifdef WITH_MPI
68  MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
69  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
70 #else
71  numtasks = 1;
72  rank = 0;
73 #endif
74 
75  std::vector<int> N = get_inifile_value<std::vector<int>>("grid_pts");
76  int NTot = 1;
77 
78  for (auto it = N.begin(), end = N.end(); it != end; it++)
79  {
80  if (*it < 0)
81  *it = -*it;
82  else if (*it == 0)
83  *it= 1;
84  NTot *= *it;
85  }
86 
87  if (N.size() != (unsigned int)ma)
88  scan_err << "Grid Scanner: The dimension of gambit (" << ma
89  << ") does not match the dimension of the inputed grid_pts (" << N.size() << ")" << scan_end;
90 
91  YAML::Node node = get_inifile_node("parameters");
92  if (node)
93  {
94  auto params = get_prior().getShownParameters();
95  auto user_params = get_yaml_vector<std::string>(node);//node.as<std::vector<std::string>>();
96 
97  if (params.size() != user_params.size())
98  {
99  scan_err << "Grid Scanner: The inputed parameter order is not the same size as the actual parameter number." << scan_end;
100  }
101 
102  std::vector<std::unordered_set<std::string>> paramSet = parse_sames(params);
103 
104  std::vector<int> N_temp(N.size(), -1);
105  for (int i = 0, end = user_params.size(); i < end; i++)
106  {
107  int k = 0;
108  for (int j = 0, endj = user_params.size(); j < endj; j++)
109  {
110  auto it = paramSet[i].find(user_params[j]);
111  if (it != paramSet[i].end())
112  {
113  N_temp[i] = N[j];
114 
115  if (k > 0)
116  {
117  scan_err << "Grid Scanner: Parameter order specified repeats same parameter (" << user_params[i] << ")" << scan_end;
118  }
119  k++;
120  }
121  }
122 
123  if (k == 0)
124  {
125  scan_err << "Grid Scanner: Parameter " << params[i] << " is not given a grid sampling rate." << scan_end;
126  }
127  }
128 
129  for (auto it = N_temp.begin(), end = N_temp.end(); it != end; ++it)
130  {
131  if (*it == -1)
132  {
133  scan_err << "Grid Scanner: Not all parameters are specified in the parameter order." << scan_end;
134  }
135  }
136 
137  N = N_temp;
138  }
139 
140  like_ptr LogLike;
141  LogLike = get_purpose(get_inifile_value<std::string>("like"));
142  std::vector<double> vec(ma, 0.0);
143 
144  for (int i = rank, end = NTot; i < end; i+=numtasks)
145  {
146  int n = i;
147  for (int j = 0; j < ma; j++)
148  {
149  if (N[j] == 1)
150  vec[j] = 0.5;
151  else
152  vec[j] = double(n%N[j])/double(N[j]-1);
153 
154  n /= N[j];
155  }
156 
157  LogLike(vec);
158  }
159 
160  return 0;
161  }
162 }
DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry double
std::vector< std::unordered_set< std::string > > parse_sames(const std::vector< std::string > &params)
Definition: grid.cpp:31
#define plugin_constructor
Runs when the plugin is loaded.
#define reqd_inifile_entries(...)
Tells ScannerBit that these tags are required.
#define scan_err
Defined to macros to output errors in the form: scan_err << "error" << scan_end; scan_warn << "warnin...
#define plugin_main(...)
Declaration of the main function which will be ran by the interface.
DS5_MSPCTM DS_INTDOF int
#define scan_end
std::vector< T > vec(std::vector< T > vector)
Definition: daFunk.hpp:142
Here is the call graph for this function: