cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
combine_pDs.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef cMHN_UTILITY_COMBINE_PDS_H
4#define cMHN_UTILITY_COMBINE_PDS_H
5
6#include <map>
7#include <vector>
8
9#include <prc.hpp>
10
11namespace cMHN
12{
21 template<class T, class S>
22 static inline auto combinePDs(std::vector<std::map<S, T>> const &pDs,
23 std::vector<pRC::Index> const &lengths)
24 {
25 std::map<S, T> res_pD;
26
27 T sum = pRC::zero<T>();
28
29 for(pRC::Index i = 0; i < pDs.size(); ++i)
30 {
31 auto const pD = pDs[i];
32 auto const length = lengths[i];
33 for(auto const &[k, v] : pD)
34 {
35 res_pD.try_emplace(k, pRC::zero<T>());
36 res_pD[k] += T(length) * v;
37 sum += T(length) * v;
38 }
39 }
40
41 for(auto &[k, v] : res_pD)
42 {
43 v = v / sum;
44 }
45
46 return res_pD;
47 }
48} // namespace cMHN
49
50#endif // cMHN_UTILITY_COMBINE_PDS_H
Definition value.hpp:12
pRC::Float<> T
Definition externs_nonTT.hpp:1
int i
Definition gmock-matchers-comparisons_test.cc:603
Definition calculate_pTheta.hpp:20
static auto combinePDs(std::vector< std::map< S, T > > const &pDs, std::vector< pRC::Index > const &lengths)
Combines multiple data distributions into a single distribution.
Definition combine_pDs.hpp:22
Size Index
Definition basics.hpp:32
static constexpr auto zero()
Definition zero.hpp:12