cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
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(std::map<S, T> const &pD)
21 {
22 constexpr pRC::Index D = S::Dimension;
23
25
26 for(auto const &[index, value] : pD)
27 {
28 for(pRC::Index i = 0; i < D; ++i)
29 {
30 if(index[i] == 1)
31 {
32 theta(i, i) += value;
33 }
34 }
35 }
36 theta =
37 diagonal(log(theta / (pRC::unit<pRC::Tensor<T, D, D>>() - theta)));
38 return theta;
39 }
40
41}
42
43#endif // cMHN_COMMON_LEARN_INDEPENDENCE_MODEL_H
pRC::Size const D
Definition CalculatePThetaTests.cpp:9
Definition tensor.hpp:25
int value
Definition gmock-actions_test.cc:1714
int i
Definition gmock-matchers-comparisons_test.cc:603
Definition calculate_pTheta.hpp:20
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
static constexpr auto unit()
Definition unit.hpp:13
Size Index
Definition basics.hpp:32
static constexpr auto zero()
Definition zero.hpp:12