Helper functions for MVAReader and MVAWriter wrappers.
More...
#include "MVAWrapperBase.h"
|
template<class T , size_t N> |
std::array< float, N > | pAccumulate (std::vector< art::Ptr< T > > const &items, std::vector< FeatureVector< N > > const &outs) const |
|
template<class T , size_t N> |
std::array< float, N > | pAccumulate (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, N > | pAccumulate (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, N > | pAccumulate (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, N > | pAccumulate (std::vector< art::Ptr< T > > const &items, std::vector< FeatureVector< N > > const &outs, std::array< char, N > const &mask) const |
|
Helper functions for MVAReader and MVAWriter wrappers.
Definition at line 36 of file MVAWrapperBase.h.
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.
References trkf::fill().
84 std::array<double, N> acc;
87 float pmin = 1.0e-6, pmax = 1.0 - pmin;
88 float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
90 for (
auto const & ptr : items)
92 auto const & vout = outs[ptr.key()];
93 for (
size_t i = 0; i < vout.size(); ++i)
96 if (vout[i] < pmin) v = log_pmin;
97 else if (vout[i] > pmax) v = log_pmax;
98 else v = std::log(vout[i]);
107 for (
size_t i = 0; i < N; ++i)
109 acc[i] = exp(acc[i] / items.size());
112 for (
size_t i = 0; i < N; ++i)
117 else std::fill(acc.begin(), acc.end(), 1.0 / N);
120 std::array<float, N> result;
121 for (
size_t i = 0; i < N; ++i) result[i] = acc[i];
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
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.
References trkf::fill(), and w.
131 std::array<double, N> acc;
134 float pmin = 1.0e-6, pmax = 1.0 - pmin;
135 float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
138 for (
size_t k = 0; k < items.size(); ++k)
140 auto const & ptr = items[k];
141 float w = weights[k];
143 if (w == 0)
continue;
145 auto const & vout = outs[ptr.key()];
146 for (
size_t i = 0; i < vout.size(); ++i)
149 if (vout[i] < pmin) v = log_pmin;
150 else if (vout[i] > pmax) v = log_pmax;
151 else v = std::log(vout[i]);
161 for (
size_t i = 0; i < N; ++i)
163 acc[i] = exp(acc[i] / totw);
166 for (
size_t i = 0; i < N; ++i)
171 else std::fill(acc.begin(), acc.end(), 1.0 / N);
174 std::array<float, N> result;
175 for (
size_t i = 0; i < N; ++i) result[i] = acc[i];
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
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.
References trkf::fill(), and w.
185 std::array<double, N> acc;
188 float pmin = 1.0e-6, pmax = 1.0 - pmin;
189 float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
192 for (
size_t k = 0; k < items.size(); ++k)
194 auto const & ptr = items[k];
195 float w = fweight(*ptr);
197 if (w == 0)
continue;
199 auto const & vout = outs[ptr.key()];
200 for (
size_t i = 0; i < vout.size(); ++i)
203 if (vout[i] < pmin) v = log_pmin;
204 else if (vout[i] > pmax) v = log_pmax;
205 else v = std::log(vout[i]);
215 for (
size_t i = 0; i < N; ++i)
217 acc[i] = exp(acc[i] / totw);
220 for (
size_t i = 0; i < N; ++i)
225 else std::fill(acc.begin(), acc.end(), 1.0 / N);
228 std::array<float, N> result;
229 for (
size_t i = 0; i < N; ++i) result[i] = acc[i];
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
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.
References trkf::fill(), and w.
239 std::array<double, N> acc;
242 float pmin = 1.0e-6, pmax = 1.0 - pmin;
243 float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
246 for (
size_t k = 0; k < items.size(); ++k)
248 auto const & ptr = items[k];
249 float w = fweight(ptr);
251 if (w == 0)
continue;
253 auto const & vout = outs[ptr.key()];
254 for (
size_t i = 0; i < vout.size(); ++i)
257 if (vout[i] < pmin) v = log_pmin;
258 else if (vout[i] > pmax) v = log_pmax;
259 else v = std::log(vout[i]);
269 for (
size_t i = 0; i < N; ++i)
271 acc[i] = exp(acc[i] / totw);
274 for (
size_t i = 0; i < N; ++i)
279 else std::fill(acc.begin(), acc.end(), 1.0 / N);
282 std::array<float, N> result;
283 for (
size_t i = 0; i < N; ++i) result[i] = acc[i];
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
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.
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)
307 auto search = label2group.find(mask[i]);
308 if (search == label2group.end())
311 label2group[mask[i]] = idx;
312 nb_entries.push_back(0);
317 idx = search->second;
324 std::array<double, N> acc;
327 float pmin = 1.0e-6, pmax = 1.0 - pmin;
328 float log_pmin = std::log(pmin), log_pmax = std::log(pmax);
330 for (
auto const & ptr : items)
332 auto const & vout = outs[ptr.key()];
333 for (
size_t i = 0; i < vout.size(); ++i)
335 if (groupidx[i] < 0)
continue;
338 if (vout[i] < pmin) v = log_pmin;
339 else if (vout[i] > pmax) v = log_pmax;
340 else v = std::log(vout[i]);
348 std::vector<double> totp(n_groups, 0.0);
349 for (
size_t i = 0; i < N; ++i)
351 if (groupidx[i] >= 0)
353 acc[i] = exp(acc[i] / items.size());
354 totp[groupidx[i]] += acc[i];
357 for (
size_t i = 0; i < N; ++i)
359 if (groupidx[i] >= 0) { acc[i] /= totp[groupidx[i]]; }
364 for (
size_t i = 0; i < N; ++i)
366 if (groupidx[i] >= 0) { acc[i] = 1 / nb_entries[groupidx[i]]; }
370 std::array<float, N> result;
371 for (
size_t i = 0; i < N; ++i) result[i] = acc[i];
The documentation for this class was generated from the following file:
- /cvmfs/larsoft.opensciencegrid.org/products/lardata/v07_01_01/source/lardata/ArtDataHelper/MVAWrapperBase.h