aGrUM  0.14.2
K2_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it wil be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 
28 namespace gum {
29 
30  namespace learning {
31 
33  INLINE K2::K2() { GUM_CONSTRUCTOR(K2); }
34 
36  INLINE K2::K2(const K2& from) :
37  GreedyHillClimbing(from), __order(from.__order) {
38  GUM_CONS_CPY(K2);
39  }
40 
42  INLINE K2::K2(K2&& from) :
43  GreedyHillClimbing(std::move(from)), __order(std::move(from.__order)) {
44  GUM_CONS_MOV(K2);
45  }
46 
48  INLINE K2::~K2() { GUM_DESTRUCTOR(K2); }
49 
51  INLINE K2& K2::operator=(const K2& from) {
52  if (this != &from) {
54  __order = from.__order;
55  }
56  return *this;
57  }
58 
60  INLINE K2& K2::operator=(K2&& from) {
61  if (this != &from) {
62  GreedyHillClimbing::operator=(std::move(from));
63  __order = std::move(from.__order);
64  }
65  return *this;
66  }
67 
69  INLINE void K2::setOrder(const Sequence< NodeId >& order) { __order = order; }
70 
72  INLINE void K2::setOrder(const std::vector< NodeId >& order) {
73  __order.clear();
74  for (const auto node : order) {
75  __order.insert(node);
76  }
77  }
78 
80  INLINE const Sequence< NodeId >& K2::order() const noexcept { return __order; }
81 
84  INLINE void K2::__checkOrder(const std::vector< Size >& modal) {
85  if (modal.size() != __order.size()) {
86  GUM_ERROR(InvalidArgument,
87  "the number of elements in the order given "
88  "to K2 is not the same as the number of nodes");
89  }
90  bool order_ok = true;
91  for (const auto node : __order) {
92  if (node >= __order.size()) {
93  order_ok = false;
94  break;
95  }
96  }
97  if (!order_ok) {
98  GUM_ERROR(InvalidArgument,
99  "there exist at least one node in the order "
100  "given to K2 that has no domain size");
101  }
102  }
103 
107  }
108 
109  } /* namespace learning */
110 
111 } /* namespace gum */
112 
113 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
void clear()
Clear the sequence.
Definition: sequence_tpl.h:268
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:35
void setOrder(const Sequence< NodeId > &order)
sets the order on the variables
STL namespace.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
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:52
~K2()
destructor
Sequence< NodeId > __order
the order on the variable used for learning
Definition: K2.h:116
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:405
GreedyHillClimbing & operator=(const GreedyHillClimbing &from)
copy operator