All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Protected Member Functions | List of all members
anab::MVAWrapperBase Class Reference

Helper functions for MVAReader and MVAWriter wrappers. More...

#include <MVAWrapperBase.h>

Inheritance diagram for anab::MVAWrapperBase:
anab::MVAReader< T, N > anab::MVAWriter< N >

Protected Member Functions

template<class T , size_t N>
std::array< float, NpAccumulate (std::vector< art::Ptr< T > > const &items, std::vector< FeatureVector< N > > const &outs) const
 
template<class T , size_t N>
std::array< float, NpAccumulate (std::vector< art::Ptr< T > > const &items, std::vector< float > const &weights, std::vector< FeatureVector< N > > const &outs) const
 
template<class T , size_t N>
std::array< float, NpAccumulate (std::vector< art::Ptr< T > > const &items, std::function< float(T const &)> fweight, std::vector< FeatureVector< N > > const &outs) const
 
template<class T , size_t N>
std::array< float, NpAccumulate (std::vector< art::Ptr< T > > const &items, std::function< float(art::Ptr< T > const &)> fweight, std::vector< FeatureVector< N > > const &outs) const
 
template<class T , size_t N>
std::array< float, NpAccumulate (std::vector< art::Ptr< T > > const &items, std::vector< FeatureVector< N > > const &outs, std::array< char, N > const &mask) const
 

Detailed Description

Helper functions for MVAReader and MVAWriter wrappers.

Definition at line 36 of file MVAWrapperBase.h.

Member Function Documentation

template<class T , size_t N>
std::array< float, N > anab::MVAWrapperBase::pAccumulate ( std::vector< art::Ptr< T > > const &  items,
std::vector< FeatureVector< N > > const &  outs 
) const
protected

Definition at line 80 of file MVAWrapperBase.h.

83 {
84  std::array<double, N> acc;
85  acc.fill(0);
86 
87  float pmin = 1.0e-6, pmax = 1.0 - pmin;
88  float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
89 
90  for (auto const & ptr : items)
91  {
92  auto const & vout = outs[ptr.key()];
93  for (size_t i = 0; i < vout.size(); ++i)
94  {
95  float v;
96  if (vout[i] < pmin) v = log_pmin;
97  else if (vout[i] > pmax) v = log_pmax;
98  else v = std::log(vout[i]);
99 
100  acc[i] += v;
101  }
102  }
103 
104  if (!items.empty())
105  {
106  double totp = 0.0;
107  for (size_t i = 0; i < N; ++i)
108  {
109  acc[i] = exp(acc[i] / items.size());
110  totp += acc[i];
111  }
112  for (size_t i = 0; i < N; ++i)
113  {
114  acc[i] /= totp;
115  }
116  }
117  else std::fill(acc.begin(), acc.end(), 1.0 / N);
118 
119 
120  std::array<float, N> result;
121  for (size_t i = 0; i < N; ++i) result[i] = acc[i];
122  return result;
123 }
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
process_name largeant stream1 can override from command line with o or output physics producers generator N
template<class T , size_t N>
std::array< float, N > anab::MVAWrapperBase::pAccumulate ( std::vector< art::Ptr< T > > const &  items,
std::vector< float > const &  weights,
std::vector< FeatureVector< N > > const &  outs 
) const
protected

Definition at line 127 of file MVAWrapperBase.h.

130 {
131  std::array<double, N> acc;
132  acc.fill(0);
133 
134  float pmin = 1.0e-6, pmax = 1.0 - pmin;
135  float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
136  double totw = 0.0;
137 
138  for (size_t k = 0; k < items.size(); ++k)
139  {
140  auto const & ptr = items[k];
141  float w = weights[k];
142 
143  if (w == 0) continue;
144 
145  auto const & vout = outs[ptr.key()];
146  for (size_t i = 0; i < vout.size(); ++i)
147  {
148  float v;
149  if (vout[i] < pmin) v = log_pmin;
150  else if (vout[i] > pmax) v = log_pmax;
151  else v = std::log(vout[i]);
152 
153  acc[i] += w * v;
154  }
155  totw += w;
156  }
157 
158  if (!items.empty())
159  {
160  double totp = 0.0;
161  for (size_t i = 0; i < N; ++i)
162  {
163  acc[i] = exp(acc[i] / totw);
164  totp += acc[i];
165  }
166  for (size_t i = 0; i < N; ++i)
167  {
168  acc[i] /= totp;
169  }
170  }
171  else std::fill(acc.begin(), acc.end(), 1.0 / N);
172 
173 
174  std::array<float, N> result;
175  for (size_t i = 0; i < N; ++i) result[i] = acc[i];
176  return result;
177 }
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
process_name largeant stream1 can override from command line with o or output physics producers generator N
pdgs k
Definition: selectors.fcl:22
template<class T , size_t N>
std::array< float, N > anab::MVAWrapperBase::pAccumulate ( std::vector< art::Ptr< T > > const &  items,
std::function< float(T const &)>  fweight,
std::vector< FeatureVector< N > > const &  outs 
) const
protected

Definition at line 181 of file MVAWrapperBase.h.

184 {
185  std::array<double, N> acc;
186  acc.fill(0);
187 
188  float pmin = 1.0e-6, pmax = 1.0 - pmin;
189  float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
190  double totw = 0.0;
191 
192  for (size_t k = 0; k < items.size(); ++k)
193  {
194  auto const & ptr = items[k];
195  float w = fweight(*ptr);
196 
197  if (w == 0) continue;
198 
199  auto const & vout = outs[ptr.key()];
200  for (size_t i = 0; i < vout.size(); ++i)
201  {
202  float v;
203  if (vout[i] < pmin) v = log_pmin;
204  else if (vout[i] > pmax) v = log_pmax;
205  else v = std::log(vout[i]);
206 
207  acc[i] += w * v;
208  }
209  totw += w;
210  }
211 
212  if (!items.empty())
213  {
214  double totp = 0.0;
215  for (size_t i = 0; i < N; ++i)
216  {
217  acc[i] = exp(acc[i] / totw);
218  totp += acc[i];
219  }
220  for (size_t i = 0; i < N; ++i)
221  {
222  acc[i] /= totp;
223  }
224  }
225  else std::fill(acc.begin(), acc.end(), 1.0 / N);
226 
227 
228  std::array<float, N> result;
229  for (size_t i = 0; i < N; ++i) result[i] = acc[i];
230  return result;
231 }
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
process_name largeant stream1 can override from command line with o or output physics producers generator N
pdgs k
Definition: selectors.fcl:22
template<class T , size_t N>
std::array< float, N > anab::MVAWrapperBase::pAccumulate ( std::vector< art::Ptr< T > > const &  items,
std::function< float(art::Ptr< T > const &)>  fweight,
std::vector< FeatureVector< N > > const &  outs 
) const
protected

Definition at line 235 of file MVAWrapperBase.h.

238 {
239  std::array<double, N> acc;
240  acc.fill(0);
241 
242  float pmin = 1.0e-6, pmax = 1.0 - pmin;
243  float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
244  double totw = 0.0;
245 
246  for (size_t k = 0; k < items.size(); ++k)
247  {
248  auto const & ptr = items[k];
249  float w = fweight(ptr);
250 
251  if (w == 0) continue;
252 
253  auto const & vout = outs[ptr.key()];
254  for (size_t i = 0; i < vout.size(); ++i)
255  {
256  float v;
257  if (vout[i] < pmin) v = log_pmin;
258  else if (vout[i] > pmax) v = log_pmax;
259  else v = std::log(vout[i]);
260 
261  acc[i] += w * v;
262  }
263  totw += w;
264  }
265 
266  if (!items.empty())
267  {
268  double totp = 0.0;
269  for (size_t i = 0; i < N; ++i)
270  {
271  acc[i] = exp(acc[i] / totw);
272  totp += acc[i];
273  }
274  for (size_t i = 0; i < N; ++i)
275  {
276  acc[i] /= totp;
277  }
278  }
279  else std::fill(acc.begin(), acc.end(), 1.0 / N);
280 
281 
282  std::array<float, N> result;
283  for (size_t i = 0; i < N; ++i) result[i] = acc[i];
284  return result;
285 }
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
process_name largeant stream1 can override from command line with o or output physics producers generator N
pdgs k
Definition: selectors.fcl:22
template<class T , size_t N>
std::array< float, N > anab::MVAWrapperBase::pAccumulate ( std::vector< art::Ptr< T > > const &  items,
std::vector< FeatureVector< N > > const &  outs,
std::array< char, N > const &  mask 
) const
protected

Definition at line 293 of file MVAWrapperBase.h.

297 {
298  size_t n_groups = 0;
299  std::unordered_map<char, size_t> label2group;
300  std::vector<size_t> nb_entries;
301  std::array<int, N> groupidx;
302  for (size_t i = 0; i < N; ++i)
303  {
304  int idx = -1;
305  if (mask[i] >= 0)
306  {
307  auto search = label2group.find(mask[i]);
308  if (search == label2group.end())
309  {
310  idx = n_groups;
311  label2group[mask[i]] = idx;
312  nb_entries.push_back(0);
313  ++n_groups;
314  }
315  else
316  {
317  idx = search->second;
318  nb_entries[idx]++;
319  }
320  }
321  groupidx[i] = idx;
322  }
323 
324  std::array<double, N> acc;
325  acc.fill(0);
326 
327  float pmin = 1.0e-6, pmax = 1.0 - pmin;
328  float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
329 
330  for (auto const & ptr : items)
331  {
332  auto const & vout = outs[ptr.key()];
333  for (size_t i = 0; i < vout.size(); ++i)
334  {
335  if (groupidx[i] < 0) continue;
336 
337  float v;
338  if (vout[i] < pmin) v = log_pmin;
339  else if (vout[i] > pmax) v = log_pmax;
340  else v = std::log(vout[i]);
341 
342  acc[i] += v;
343  }
344  }
345 
346  if (!items.empty())
347  {
348  std::vector<double> totp(n_groups, 0.0);
349  for (size_t i = 0; i < N; ++i)
350  {
351  if (groupidx[i] >= 0)
352  {
353  acc[i] = exp(acc[i] / items.size());
354  totp[groupidx[i]] += acc[i];
355  }
356  }
357  for (size_t i = 0; i < N; ++i)
358  {
359  if (groupidx[i] >= 0) { acc[i] /= totp[groupidx[i]]; }
360  }
361  }
362  else
363  {
364  for (size_t i = 0; i < N; ++i)
365  {
366  if (groupidx[i] >= 0) { acc[i] = 1 / nb_entries[groupidx[i]]; }
367  }
368  }
369 
370  std::array<float, N> result;
371  for (size_t i = 0; i < N; ++i) result[i] = acc[i];
372  return result;
373 }
process_name largeant stream1 can override from command line with o or output physics producers generator N

The documentation for this class was generated from the following file: