-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConstraintBasedLearning.hpp
111 lines (90 loc) · 2.93 KB
/
ConstraintBasedLearning.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @file ConstraintBasedLearning.hpp
* @brief Declaration of the classes for constraint-based learning.
* @author Ankit Srivastava <[email protected]>
*
* Copyright 2020 Georgia Institute of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONSTRAINTBASEDLEARNING_HPP_
#define CONSTRAINTBASEDLEARNING_HPP_
#include "BayesianNetwork.hpp"
#include "mxx/comm.hpp"
#include "utils/Timer.hpp"
#include <map>
#include <stdexcept>
#include <unordered_map>
/**
* @brief Exception to be used for not implemented functions.
*/
class NotImplementedError : public std::logic_error {
public:
NotImplementedError(const std::string&);
}; // class NotImplementedError
/**
* @brief Abstract base class for causal discovery using constraint-based learning.
* All the constraint-based learning algorithm implementations should be a
* descendant of this class.
*
* @tparam Data Type of the object which is used for querying the data.
* @tparam Var Type of variable indices (expected to be an integer type).
* @tparam Set Type of set container.
*/
template <typename Data, typename Var, typename Set>
class ConstraintBasedLearning {
public:
ConstraintBasedLearning(const mxx::comm&, const Data&, const double, const Var);
virtual
const Set&
getPC(const Var) const = 0;
virtual
const Set&
getMB(const Var) const = 0;
std::vector<std::tuple<double, Var, Var, Var>>
findVStructures(const Var) const;
BayesianNetwork<Var>
getNetwork(const bool, const bool, const double = 0.0) const;
virtual
~ConstraintBasedLearning();
protected:
Set
getCandidates(const Var) const;
virtual
void
syncSets(std::unordered_map<Var, Set>&) const;
virtual
BayesianNetwork<Var>
getSkeleton_sequential(const bool) const = 0;
bool
fixImbalance(std::vector<std::tuple<Var, Var, double>>&, const double) const;
virtual
BayesianNetwork<Var>
getSkeleton_parallel(const bool, const double) const = 0;
virtual
std::pair<bool, double>
checkCollider(const Var, const Var, const Var) const = 0;
private:
std::vector<std::tuple<double, Var, Var, Var>>
findVStructures(const bool) const;
protected:
const mxx::comm& m_comm;
const Data m_data;
Set m_allVars;
const double m_alpha;
const Var m_maxConditioning;
TIMER_DECLARE(m_tMxx, mutable);
TIMER_DECLARE(m_tDirect, mutable);
}; // class ConstraintBasedLearning
#include "detail/ConstraintBasedLearning.hpp"
#endif // CONSTRAINTBASEDLEARNING_HPP_