aGrUM  0.16.0
K2_inl.h
Go to the documentation of this file.
1 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 namespace gum {
32 
33  namespace learning {
34 
36  INLINE K2::K2() { GUM_CONSTRUCTOR(K2); }
37 
39  INLINE K2::K2(const K2& from) :
40  GreedyHillClimbing(from), __order(from.__order) {
41  GUM_CONS_CPY(K2);
42  }
43 
45  INLINE K2::K2(K2&& from) :
46  GreedyHillClimbing(std::move(from)), __order(std::move(from.__order)) {
47  GUM_CONS_MOV(K2);
48  }
49 
51  INLINE K2::~K2() { GUM_DESTRUCTOR(K2); }
52 
54  INLINE K2& K2::operator=(const K2& from) {
55  if (this != &from) {
57  __order = from.__order;
58  }
59  return *this;
60  }
61 
63  INLINE K2& K2::operator=(K2&& from) {
64  if (this != &from) {
65  GreedyHillClimbing::operator=(std::move(from));
66  __order = std::move(from.__order);
67  }
68  return *this;
69  }
70 
72  INLINE void K2::setOrder(const Sequence< NodeId >& order) { __order = order; }
73 
75  INLINE void K2::setOrder(const std::vector< NodeId >& order) {
76  __order.clear();
77  for (const auto node : order) {
78  __order.insert(node);
79  }
80  }
81 
83  INLINE const Sequence< NodeId >& K2::order() const noexcept { return __order; }
84 
87  INLINE void K2::__checkOrder(const std::vector< Size >& modal) {
88  if (modal.size() != __order.size()) {
89  GUM_ERROR(InvalidArgument,
90  "the number of elements in the order given "
91  "to K2 is not the same as the number of nodes");
92  }
93  bool order_ok = true;
94  for (const auto node : __order) {
95  if (node >= __order.size()) {
96  order_ok = false;
97  break;
98  }
99  }
100  if (!order_ok) {
101  GUM_ERROR(InvalidArgument,
102  "there exist at least one node in the order "
103  "given to K2 that has no domain size");
104  }
105  }
106 
110  }
111 
112  } /* namespace learning */
113 
114 } /* namespace gum */
115 
116 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
void clear()
Clear the sequence.
Definition: sequence_tpl.h:271
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
void setOrder(const Sequence< NodeId > &order)
sets the order on the variables
STL namespace.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
ApproximationScheme(bool verbosity=false)
const Sequence< NodeId > & order() const noexcept
returns the current order
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
K2 & operator=(const K2 &from)
copy operator
K2()
default constructor
GreedyHillClimbing()
default constructor
void __checkOrder(const std::vector< Size > &modal)
checks that the order passed to K2 is coherent with the variables as specified by their modalities ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
~K2()
destructor
Sequence< NodeId > __order
the order on the variable used for learning
Definition: K2.h:119
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408
GreedyHillClimbing & operator=(const GreedyHillClimbing &from)
copy operator