cMHN 1.0
C++ library for learning MHNs with pRC
learn_independence_model.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef cMHN_COMMON_LEARN_INDEPENDENCE_MODEL_H
4#define cMHN_COMMON_LEARN_INDEPENDENCE_MODEL_H
5
6#include <map>
7
8namespace cMHN
9{
19 template<class T, class S>
20 static inline auto learnIndependenceModel(
21 std::map<S, T> const &pD)
22 {
23 constexpr pRC::Index D = typename S::Dimension();
24
25 pRC::Tensor<T, D, D> theta = pRC::zero();
26
27 for(auto const &[index, value] : pD)
28 {
29 for(pRC::Index i = 0; i < D; ++i)
30 {
31 if(index[i] == 1)
32 {
33 theta(i, i) += value;
34 }
35 }
36 }
37 theta =
38 diagonal(log(theta / (pRC::unit<pRC::Tensor<T, D, D>>() - theta)));
39 return theta;
40 }
41
42}
43
44#endif // cMHN_COMMON_LEARN_INDEPENDENCE_MODEL_H
pRC::Size const D
Definition: CalculatePThetaTests.cpp:9
Definition: calculate_pTheta.hpp:15
static auto learnIndependenceModel(std::map< S, T > const &pD)
Calculate the theta matrix corresponding to the independence model for a given data distribution.
Definition: learn_independence_model.hpp:20