aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::learning::LocalSearchWithTabuList Class Reference

The local search with tabu list learning algorithm (for directed graphs) More...

#include <localSearchWithTabuList.h>

+ Inheritance diagram for gum::learning::LocalSearchWithTabuList:
+ Collaboration diagram for gum::learning::LocalSearchWithTabuList:

Public Attributes

Signaler3< Size, double, doubleonProgress
 Progression, error and time. More...
 
Signaler1< std::string > onStop
 Criteria messageApproximationScheme. More...
 

Public Member Functions

Constructors / Destructors
 LocalSearchWithTabuList ()
 default constructor More...
 
 LocalSearchWithTabuList (const LocalSearchWithTabuList &from)
 copy constructor More...
 
 LocalSearchWithTabuList (LocalSearchWithTabuList &&from)
 move constructor More...
 
virtual ~LocalSearchWithTabuList ()
 destructor More...
 
Operators
LocalSearchWithTabuListoperator= (const LocalSearchWithTabuList &from)
 copy operator More...
 
LocalSearchWithTabuListoperator= (LocalSearchWithTabuList &&from)
 move operator More...
 
Accessors / Modifiers
ApproximationSchemeapproximationScheme ()
 returns the approximation policy of the learning algorithm More...
 
void setMaxNbDecreasingChanges (Size nb)
 set the max number of changes decreasing the score that we allow to apply More...
 
template<typename GRAPH_CHANGES_SELECTOR >
DAG learnStructure (GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
 learns the structure of a Bayes net More...
 
template<typename GUM_SCALAR = double, typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR >
BayesNet< GUM_SCALAR > learnBN (GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
 learns the structure and the parameters of a BN More...
 
Getters and setters
void setEpsilon (double eps)
 Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|. More...
 
double epsilon () const
 Returns the value of epsilon. More...
 
void disableEpsilon ()
 Disable stopping criterion on epsilon. More...
 
void enableEpsilon ()
 Enable stopping criterion on epsilon. More...
 
bool isEnabledEpsilon () const
 Returns true if stopping criterion on epsilon is enabled, false otherwise. More...
 
void setMinEpsilonRate (double rate)
 Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|). More...
 
double minEpsilonRate () const
 Returns the value of the minimal epsilon rate. More...
 
void disableMinEpsilonRate ()
 Disable stopping criterion on epsilon rate. More...
 
void enableMinEpsilonRate ()
 Enable stopping criterion on epsilon rate. More...
 
bool isEnabledMinEpsilonRate () const
 Returns true if stopping criterion on epsilon rate is enabled, false otherwise. More...
 
void setMaxIter (Size max)
 Stopping criterion on number of iterations. More...
 
Size maxIter () const
 Returns the criterion on number of iterations. More...
 
void disableMaxIter ()
 Disable stopping criterion on max iterations. More...
 
void enableMaxIter ()
 Enable stopping criterion on max iterations. More...
 
bool isEnabledMaxIter () const
 Returns true if stopping criterion on max iterations is enabled, false otherwise. More...
 
void setMaxTime (double timeout)
 Stopping criterion on timeout. More...
 
double maxTime () const
 Returns the timeout (in seconds). More...
 
double currentTime () const
 Returns the current running time in second. More...
 
void disableMaxTime ()
 Disable stopping criterion on timeout. More...
 
void enableMaxTime ()
 Enable stopping criterion on timeout. More...
 
bool isEnabledMaxTime () const
 Returns true if stopping criterion on timeout is enabled, false otherwise. More...
 
void setPeriodSize (Size p)
 How many samples between two stopping is enable. More...
 
Size periodSize () const
 Returns the period size. More...
 
void setVerbosity (bool v)
 Set the verbosity on (true) or off (false). More...
 
bool verbosity () const
 Returns true if verbosity is enabled. More...
 
ApproximationSchemeSTATE stateApproximationScheme () const
 Returns the approximation scheme state. More...
 
Size nbrIterations () const
 Returns the number of iterations. More...
 
const std::vector< double > & history () const
 Returns the scheme history. More...
 
void initApproximationScheme ()
 Initialise the scheme. More...
 
bool startOfPeriod ()
 Returns true if we are at the beginning of a period (compute error is mandatory). More...
 
void updateApproximationScheme (unsigned int incr=1)
 Update the scheme w.r.t the new error and increment steps. More...
 
Size remainingBurnIn ()
 Returns the remaining burn in. More...
 
void stopApproximationScheme ()
 Stop the approximation scheme. More...
 
bool continueApproximationScheme (double error)
 Update the scheme w.r.t the new error. More...
 
Getters and setters
std::string messageApproximationScheme () const
 Returns the approximation scheme message. More...
 

Public Types

enum  ApproximationSchemeSTATE : char {
  ApproximationSchemeSTATE::Undefined, ApproximationSchemeSTATE::Continue, ApproximationSchemeSTATE::Epsilon, ApproximationSchemeSTATE::Rate,
  ApproximationSchemeSTATE::Limit, ApproximationSchemeSTATE::TimeLimit, ApproximationSchemeSTATE::Stopped
}
 The different state of an approximation scheme. More...
 

Protected Attributes

double current_epsilon_
 Current epsilon. More...
 
double last_epsilon_
 Last epsilon value. More...
 
double current_rate_
 Current rate. More...
 
Size current_step_
 The current step. More...
 
Timer timer_
 The timer. More...
 
ApproximationSchemeSTATE current_state_
 The current state. More...
 
std::vector< doublehistory_
 The scheme history, used only if verbosity == true. More...
 
double eps_
 Threshold for convergence. More...
 
bool enabled_eps_
 If true, the threshold convergence is enabled. More...
 
double min_rate_eps_
 Threshold for the epsilon rate. More...
 
bool enabled_min_rate_eps_
 If true, the minimal threshold for epsilon rate is enabled. More...
 
double max_time_
 The timeout. More...
 
bool enabled_max_time_
 If true, the timeout is enabled. More...
 
Size max_iter_
 The maximum iterations. More...
 
bool enabled_max_iter_
 If true, the maximum iterations stopping criterion is enabled. More...
 
Size burn_in_
 Number of iterations before checking stopping criteria. More...
 
Size period_size_
 Checking criteria frequency. More...
 
bool verbosity_
 If true, verbosity is enabled. More...
 

Detailed Description

The local search with tabu list learning algorithm (for directed graphs)

The LocalSearchWithTabuList class implements a greedy search in which we allow applying at most N consecutive graph changes that decrease the score. To prevent infinite loops, when using local search, you should use a structural constraint that includes a tabu list of at least N elements.

Definition at line 60 of file localSearchWithTabuList.h.

Member Enumeration Documentation

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 64 of file IApproximationSchemeConfiguration.h.

64  : char
65  {
66  Undefined,
67  Continue,
68  Epsilon,
69  Rate,
70  Limit,
71  TimeLimit,
72  Stopped
73  };

Constructor & Destructor Documentation

◆ LocalSearchWithTabuList() [1/3]

gum::learning::LocalSearchWithTabuList::LocalSearchWithTabuList ( )

default constructor

◆ LocalSearchWithTabuList() [2/3]

gum::learning::LocalSearchWithTabuList::LocalSearchWithTabuList ( const LocalSearchWithTabuList from)

copy constructor

◆ LocalSearchWithTabuList() [3/3]

gum::learning::LocalSearchWithTabuList::LocalSearchWithTabuList ( LocalSearchWithTabuList &&  from)

move constructor

◆ ~LocalSearchWithTabuList()

virtual gum::learning::LocalSearchWithTabuList::~LocalSearchWithTabuList ( )
virtual

destructor

Member Function Documentation

◆ approximationScheme()

ApproximationScheme& gum::learning::LocalSearchWithTabuList::approximationScheme ( )

returns the approximation policy of the learning algorithm

◆ continueApproximationScheme()

INLINE bool gum::ApproximationScheme::continueApproximationScheme ( double  error)
inherited

Update the scheme w.r.t the new error.

Test the stopping criterion that are enabled.

Parameters
errorThe new error value.
Returns
false if state become != ApproximationSchemeSTATE::Continue
Exceptions
OperationNotAllowedRaised if state != ApproximationSchemeSTATE::Continue.

Definition at line 226 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

226  {
227  // For coherence, we fix the time used in the method
228 
229  double timer_step = timer_.step();
230 
231  if (enabled_max_time_) {
232  if (timer_step > max_time_) {
234  return false;
235  }
236  }
237 
238  if (!startOfPeriod()) { return true; }
239 
241  GUM_ERROR(OperationNotAllowed,
242  "state of the approximation scheme is not correct : "
244  }
245 
246  if (verbosity()) { history_.push_back(error); }
247 
248  if (enabled_max_iter_) {
249  if (current_step_ > max_iter_) {
251  return false;
252  }
253  }
254 
256  current_epsilon_ = error; // eps rate isEnabled needs it so affectation was
257  // moved from eps isEnabled below
258 
259  if (enabled_eps_) {
260  if (current_epsilon_ <= eps_) {
262  return false;
263  }
264  }
265 
266  if (last_epsilon_ >= 0.) {
267  if (current_epsilon_ > .0) {
268  // ! current_epsilon_ can be 0. AND epsilon
269  // isEnabled can be disabled !
272  }
273  // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
274  // infinity the else means a return false if we isEnabled the rate below,
275  // as we would have returned false if epsilon isEnabled was enabled
276  else {
278  }
279 
280  if (enabled_min_rate_eps_) {
281  if (current_rate_ <= min_rate_eps_) {
283  return false;
284  }
285  }
286  }
287 
289  if (onProgress.hasListener()) {
291  }
292 
293  return true;
294  } else {
295  return false;
296  }
297  }
double max_time_
The timeout.
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:41
Signaler3< Size, double, double > onProgress
Progression, error and time.
ApproximationSchemeSTATE current_state_
The current state.
void stopScheme_(ApproximationSchemeSTATE new_state)
Stop the scheme given a new state.
bool startOfPeriod()
Returns true if we are at the beginning of a period (compute error is mandatory). ...
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
double last_epsilon_
Last epsilon value.
double eps_
Threshold for convergence.
double min_rate_eps_
Threshold for the epsilon rate.
bool enabled_max_time_
If true, the timeout is enabled.
double current_rate_
Current rate.
Size max_iter_
The maximum iterations.
double current_epsilon_
Current epsilon.
bool enabled_eps_
If true, the threshold convergence is enabled.
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
std::vector< double > history_
The scheme history, used only if verbosity == true.
bool verbosity() const
Returns true if verbosity is enabled.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
Size current_step_
The current step.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:41
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ currentTime()

INLINE double gum::ApproximationScheme::currentTime ( ) const
virtualinherited

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 127 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

127 { return timer_.step(); }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:41
+ Here is the call graph for this function:

◆ disableEpsilon()

INLINE void gum::ApproximationScheme::disableEpsilon ( )
virtualinherited

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 53 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

53 { enabled_eps_ = false; }
bool enabled_eps_
If true, the threshold convergence is enabled.
+ Here is the call graph for this function:

◆ disableMaxIter()

INLINE void gum::ApproximationScheme::disableMaxIter ( )
virtualinherited

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 104 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

104 { enabled_max_iter_ = false; }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
+ Here is the call graph for this function:

◆ disableMaxTime()

INLINE void gum::ApproximationScheme::disableMaxTime ( )
virtualinherited

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 130 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

130 { enabled_max_time_ = false; }
bool enabled_max_time_
If true, the timeout is enabled.
+ Here is the call graph for this function:

◆ disableMinEpsilonRate()

INLINE void gum::ApproximationScheme::disableMinEpsilonRate ( )
virtualinherited

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 78 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

78  {
79  enabled_min_rate_eps_ = false;
80  }
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the call graph for this function:

◆ enableEpsilon()

INLINE void gum::ApproximationScheme::enableEpsilon ( )
virtualinherited

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 56 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

56 { enabled_eps_ = true; }
bool enabled_eps_
If true, the threshold convergence is enabled.
+ Here is the call graph for this function:

◆ enableMaxIter()

INLINE void gum::ApproximationScheme::enableMaxIter ( )
virtualinherited

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 107 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

107 { enabled_max_iter_ = true; }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
+ Here is the call graph for this function:

◆ enableMaxTime()

INLINE void gum::ApproximationScheme::enableMaxTime ( )
virtualinherited

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 133 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

133 { enabled_max_time_ = true; }
bool enabled_max_time_
If true, the timeout is enabled.
+ Here is the call graph for this function:

◆ enableMinEpsilonRate()

INLINE void gum::ApproximationScheme::enableMinEpsilonRate ( )
virtualinherited

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 83 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

83  {
84  enabled_min_rate_eps_ = true;
85  }
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the call graph for this function:

◆ epsilon()

INLINE double gum::ApproximationScheme::epsilon ( ) const
virtualinherited

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 50 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

50 { return eps_; }
double eps_
Threshold for convergence.
+ Here is the call graph for this function:

◆ history()

INLINE const std::vector< double > & gum::ApproximationScheme::history ( ) const
virtualinherited

Returns the scheme history.

Returns
Returns the scheme history.
Exceptions
OperationNotAllowedRaised if the scheme did not performed or if verbosity is set to false.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 172 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

172  {
174  GUM_ERROR(OperationNotAllowed,
175  "state of the approximation scheme is udefined");
176  }
177 
178  if (verbosity() == false) {
179  GUM_ERROR(OperationNotAllowed, "No history when verbosity=false");
180  }
181 
182  return history_;
183  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
std::vector< double > history_
The scheme history, used only if verbosity == true.
bool verbosity() const
Returns true if verbosity is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ initApproximationScheme()

INLINE void gum::ApproximationScheme::initApproximationScheme ( )
inherited

Initialise the scheme.

Definition at line 186 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

186  {
188  current_step_ = 0;
190  history_.clear();
191  timer_.reset();
192  }
ApproximationSchemeSTATE current_state_
The current state.
void reset()
Reset the timer.
Definition: timer_inl.h:31
double current_rate_
Current rate.
double current_epsilon_
Current epsilon.
std::vector< double > history_
The scheme history, used only if verbosity == true.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ isEnabledEpsilon()

INLINE bool gum::ApproximationScheme::isEnabledEpsilon ( ) const
virtualinherited

Returns true if stopping criterion on epsilon is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 60 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

60  {
61  return enabled_eps_;
62  }
bool enabled_eps_
If true, the threshold convergence is enabled.
+ Here is the call graph for this function:

◆ isEnabledMaxIter()

INLINE bool gum::ApproximationScheme::isEnabledMaxIter ( ) const
virtualinherited

Returns true if stopping criterion on max iterations is enabled, false otherwise.

Returns
Returns true if stopping criterion on max iterations is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 111 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

111  {
112  return enabled_max_iter_;
113  }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
+ Here is the call graph for this function:

◆ isEnabledMaxTime()

INLINE bool gum::ApproximationScheme::isEnabledMaxTime ( ) const
virtualinherited

Returns true if stopping criterion on timeout is enabled, false otherwise.

Returns
Returns true if stopping criterion on timeout is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 137 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

137  {
138  return enabled_max_time_;
139  }
bool enabled_max_time_
If true, the timeout is enabled.
+ Here is the call graph for this function:

◆ isEnabledMinEpsilonRate()

INLINE bool gum::ApproximationScheme::isEnabledMinEpsilonRate ( ) const
virtualinherited

Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 89 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

89  {
90  return enabled_min_rate_eps_;
91  }
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the call graph for this function:

◆ learnBN()

template<typename GUM_SCALAR , typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR >
BayesNet< GUM_SCALAR > gum::learning::LocalSearchWithTabuList::learnBN ( GRAPH_CHANGES_SELECTOR &  selector,
PARAM_ESTIMATOR &  estimator,
DAG  initial_dag = DAG() 
)

learns the structure and the parameters of a BN

Definition at line 201 of file localSearchWithTabuList_tpl.h.

References gum::learning::genericBNLearner::Database::Database().

203  {
204  return DAG2BNLearner<>::createBN< GUM_SCALAR >(
205  estimator,
206  learnStructure(selector, initial_dag));
207  }
static BayesNet< GUM_SCALAR > createBN(ParamEstimator< ALLOC > &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
+ Here is the call graph for this function:

◆ learnStructure()

template<typename GRAPH_CHANGES_SELECTOR >
DAG gum::learning::LocalSearchWithTabuList::learnStructure ( GRAPH_CHANGES_SELECTOR &  selector,
DAG  initial_dag = DAG() 
)

learns the structure of a Bayes net

Parameters
selectorA selector class that computes the best changes that can be applied and that enables the user to get them very easily. Typically, the selector is a GraphChangesSelector4DiGraph<SCORE, STRUCT_CONSTRAINT, GRAPH_CHANGES_GENERATOR>.
initial_dagthe DAG we start from for our learning

Definition at line 38 of file localSearchWithTabuList_tpl.h.

References gum::learning::genericBNLearner::Database::Database().

39  {
40  selector.setGraph(dag);
41 
42  unsigned int nb_changes_applied = 0;
43  Idx applied_change_with_positive_score = 0;
44  Idx current_N = 0;
45 
47 
48  // a vector that indicates which queues have valid scores, i.e., scores
49  // that were not invalidated by previously applied changes
50  std::vector< bool > impacted_queues(dag.size(), false);
51 
52  // the best dag found so far with its score
53  DAG best_dag = dag;
54  double best_score = 0;
55  double current_score = 0;
56  double delta_score = 0;
57 
58  do {
59  applied_change_with_positive_score = 0;
60  delta_score = 0;
61 
62  std::vector< std::pair< NodeId, double > > ordered_queues
63  = selector.nodesSortedByBestScore();
64 
65  for (Idx j = 0; j < dag.size(); ++j) {
66  NodeId i = ordered_queues[j].first;
67 
68  if (!selector.empty(i)
69  && (!nb_changes_applied || (selector.bestScore(i) > 0))) {
70  // pick up the best change
71  const GraphChange& change = selector.bestChange(i);
72 
73  // perform the change
74  switch (change.type()) {
76  if (!impacted_queues[change.node2()]
77  && selector.isChangeValid(change)) {
78  if (selector.bestScore(i) > 0) {
79  ++applied_change_with_positive_score;
80  } else if (current_score > best_score) {
81  best_score = current_score;
82  best_dag = dag;
83  }
84 
85  // std::cout << "apply arc addition " << change.node1()
86  // << " -> " << change.node2()
87  // << " delta = " << selector.bestScore( i )
88  // << std::endl;
89 
90  delta_score += selector.bestScore(i);
91  current_score += selector.bestScore(i);
92  dag.addArc(change.node1(), change.node2());
93  impacted_queues[change.node2()] = true;
94  selector.applyChangeWithoutScoreUpdate(change);
95  ++nb_changes_applied;
96  }
97 
98  break;
99 
101  if (!impacted_queues[change.node2()]
102  && selector.isChangeValid(change)) {
103  if (selector.bestScore(i) > 0) {
104  ++applied_change_with_positive_score;
105  } else if (current_score > best_score) {
106  best_score = current_score;
107  best_dag = dag;
108  }
109 
110  // std::cout << "apply arc deletion " << change.node1()
111  // << " -> " << change.node2()
112  // << " delta = " << selector.bestScore( i )
113  // << std::endl;
114 
115  delta_score += selector.bestScore(i);
116  current_score += selector.bestScore(i);
117  dag.eraseArc(Arc(change.node1(), change.node2()));
118  impacted_queues[change.node2()] = true;
119  selector.applyChangeWithoutScoreUpdate(change);
120  ++nb_changes_applied;
121  }
122 
123  break;
124 
126  if ((!impacted_queues[change.node1()])
127  && (!impacted_queues[change.node2()])
128  && selector.isChangeValid(change)) {
129  if (selector.bestScore(i) > 0) {
130  ++applied_change_with_positive_score;
131  } else if (current_score > best_score) {
132  best_score = current_score;
133  best_dag = dag;
134  }
135 
136  // std::cout << "apply arc reversal " << change.node1()
137  // << " -> " << change.node2()
138  // << " delta = " << selector.bestScore( i )
139  // << std::endl;
140 
141  delta_score += selector.bestScore(i);
142  current_score += selector.bestScore(i);
143  dag.eraseArc(Arc(change.node1(), change.node2()));
144  dag.addArc(change.node2(), change.node1());
145  impacted_queues[change.node1()] = true;
146  impacted_queues[change.node2()] = true;
147  selector.applyChangeWithoutScoreUpdate(change);
148  ++nb_changes_applied;
149  }
150 
151  break;
152 
153  default:
154  GUM_ERROR(OperationNotAllowed,
155  "edge modifications are not "
156  "supported by local search");
157  }
158 
159  break;
160  }
161  }
162 
163  selector.updateScoresAfterAppliedChanges();
164 
165  // reset the impacted queue and applied changes structures
166  for (auto iter = impacted_queues.begin(); iter != impacted_queues.end();
167  ++iter) {
168  *iter = false;
169  }
170 
171  updateApproximationScheme(nb_changes_applied);
172 
173  // update current_N
174  if (applied_change_with_positive_score) {
175  current_N = 0;
176  nb_changes_applied = 0;
177  } else {
178  ++current_N;
179  }
180 
181  // std::cout << "current N = " << current_N << std::endl;
182  } while ((current_N <= MaxNbDecreasing__)
183  && continueApproximationScheme(delta_score));
184 
185  stopApproximationScheme(); // just to be sure of the
186  // approximationScheme has
187  // been notified of the end of looop
188 
189  if (current_score > best_score) {
190  return dag;
191  } else {
192  return best_dag;
193  }
194  }
void initApproximationScheme()
Initialise the scheme.
Size MaxNbDecreasing__
the max number of changes decreasing the score that we allow to apply
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
void stopApproximationScheme()
Stop the approximation scheme.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
+ Here is the call graph for this function:

◆ maxIter()

INLINE Size gum::ApproximationScheme::maxIter ( ) const
virtualinherited

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 101 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

101 { return max_iter_; }
Size max_iter_
The maximum iterations.
+ Here is the call graph for this function:

◆ maxTime()

INLINE double gum::ApproximationScheme::maxTime ( ) const
virtualinherited

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 124 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

124 { return max_time_; }
double max_time_
The timeout.
+ Here is the call graph for this function:

◆ messageApproximationScheme()

INLINE std::string gum::IApproximationSchemeConfiguration::messageApproximationScheme ( ) const
inherited

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 39 of file IApproximationSchemeConfiguration_inl.h.

References gum::Set< Key, Alloc >::emplace().

39  {
40  std::stringstream s;
41 
42  switch (stateApproximationScheme()) {
44  s << "in progress";
45  break;
46 
48  s << "stopped with epsilon=" << epsilon();
49  break;
50 
52  s << "stopped with rate=" << minEpsilonRate();
53  break;
54 
56  s << "stopped with max iteration=" << maxIter();
57  break;
58 
60  s << "stopped with timeout=" << maxTime();
61  break;
62 
64  s << "stopped on request";
65  break;
66 
68  s << "undefined state";
69  break;
70  };
71 
72  return s.str();
73  }
virtual double epsilon() const =0
Returns the value of epsilon.
virtual ApproximationSchemeSTATE stateApproximationScheme() const =0
Returns the approximation scheme state.
virtual double maxTime() const =0
Returns the timeout (in seconds).
virtual Size maxIter() const =0
Returns the criterion on number of iterations.
virtual double minEpsilonRate() const =0
Returns the value of the minimal epsilon rate.
+ Here is the call graph for this function:

◆ minEpsilonRate()

INLINE double gum::ApproximationScheme::minEpsilonRate ( ) const
virtualinherited

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 73 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

73  {
74  return min_rate_eps_;
75  }
double min_rate_eps_
Threshold for the epsilon rate.
+ Here is the call graph for this function:

◆ nbrIterations()

INLINE Size gum::ApproximationScheme::nbrIterations ( ) const
virtualinherited

Returns the number of iterations.

Returns
Returns the number of iterations.
Exceptions
OperationNotAllowedRaised if the scheme did not perform.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 162 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

162  {
164  GUM_ERROR(OperationNotAllowed,
165  "state of the approximation scheme is undefined");
166  }
167 
168  return current_step_;
169  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
Size current_step_
The current step.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ operator=() [1/2]

LocalSearchWithTabuList& gum::learning::LocalSearchWithTabuList::operator= ( const LocalSearchWithTabuList from)

copy operator

◆ operator=() [2/2]

LocalSearchWithTabuList& gum::learning::LocalSearchWithTabuList::operator= ( LocalSearchWithTabuList &&  from)

move operator

◆ periodSize()

INLINE Size gum::ApproximationScheme::periodSize ( ) const
virtualinherited

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 148 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

148 { return period_size_; }
Size period_size_
Checking criteria frequency.
+ Here is the call graph for this function:

◆ remainingBurnIn()

INLINE Size gum::ApproximationScheme::remainingBurnIn ( )
inherited

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 209 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

209  {
210  if (burn_in_ > current_step_) {
211  return burn_in_ - current_step_;
212  } else {
213  return 0;
214  }
215  }
Size burn_in_
Number of iterations before checking stopping criteria.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ setEpsilon()

INLINE void gum::ApproximationScheme::setEpsilon ( double  eps)
virtualinherited

Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.

If the criterion was disabled it will be enabled.

Parameters
epsThe new epsilon value.
Exceptions
OutOfLowerBoundRaised if eps < 0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 42 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

42  {
43  if (eps < 0.) { GUM_ERROR(OutOfLowerBound, "eps should be >=0"); }
44 
45  eps_ = eps;
46  enabled_eps_ = true;
47  }
double eps_
Threshold for convergence.
bool enabled_eps_
If true, the threshold convergence is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMaxIter()

INLINE void gum::ApproximationScheme::setMaxIter ( Size  max)
virtualinherited

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

Parameters
maxThe maximum number of iterations.
Exceptions
OutOfLowerBoundRaised if max <= 1.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 94 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

94  {
95  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
96  max_iter_ = max;
97  enabled_max_iter_ = true;
98  }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
Size max_iter_
The maximum iterations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMaxNbDecreasingChanges()

void gum::learning::LocalSearchWithTabuList::setMaxNbDecreasingChanges ( Size  nb)

set the max number of changes decreasing the score that we allow to apply

◆ setMaxTime()

INLINE void gum::ApproximationScheme::setMaxTime ( double  timeout)
virtualinherited

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

Parameters
timeoutThe timeout value in seconds.
Exceptions
OutOfLowerBoundRaised if timeout <= 0.0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 117 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

117  {
118  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0."); }
119  max_time_ = timeout;
120  enabled_max_time_ = true;
121  }
double max_time_
The timeout.
bool enabled_max_time_
If true, the timeout is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMinEpsilonRate()

INLINE void gum::ApproximationScheme::setMinEpsilonRate ( double  rate)
virtualinherited

Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).

If the criterion was disabled it will be enabled

Parameters
rateThe minimal epsilon rate.
Exceptions
OutOfLowerBoundif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 65 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

65  {
66  if (rate < 0) { GUM_ERROR(OutOfLowerBound, "rate should be >=0"); }
67 
68  min_rate_eps_ = rate;
69  enabled_min_rate_eps_ = true;
70  }
double min_rate_eps_
Threshold for the epsilon rate.
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setPeriodSize()

INLINE void gum::ApproximationScheme::setPeriodSize ( Size  p)
virtualinherited

How many samples between two stopping is enable.

Parameters
pThe new period value.
Exceptions
OutOfLowerBoundRaised if p < 1.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 142 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

142  {
143  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1"); }
144 
145  period_size_ = p;
146  }
Size period_size_
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setVerbosity()

INLINE void gum::ApproximationScheme::setVerbosity ( bool  v)
virtualinherited

Set the verbosity on (true) or off (false).

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 151 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

151 { verbosity_ = v; }
bool verbosity_
If true, verbosity is enabled.
+ Here is the call graph for this function:

◆ startOfPeriod()

INLINE bool gum::ApproximationScheme::startOfPeriod ( )
inherited

Returns true if we are at the beginning of a period (compute error is mandatory).

Returns
Returns true if we are at the beginning of a period (compute error is mandatory).

Definition at line 196 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

196  {
197  if (current_step_ < burn_in_) { return false; }
198 
199  if (period_size_ == 1) { return true; }
200 
201  return ((current_step_ - burn_in_) % period_size_ == 0);
202  }
Size burn_in_
Number of iterations before checking stopping criteria.
Size period_size_
Checking criteria frequency.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ stateApproximationScheme()

INLINE IApproximationSchemeConfiguration::ApproximationSchemeSTATE gum::ApproximationScheme::stateApproximationScheme ( ) const
virtualinherited

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 157 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

157  {
158  return current_state_;
159  }
ApproximationSchemeSTATE current_state_
The current state.
+ Here is the call graph for this function:

◆ stopApproximationScheme()

INLINE void gum::ApproximationScheme::stopApproximationScheme ( )
inherited

Stop the approximation scheme.

Definition at line 218 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

+ Here is the call graph for this function:

◆ updateApproximationScheme()

INLINE void gum::ApproximationScheme::updateApproximationScheme ( unsigned int  incr = 1)
inherited

Update the scheme w.r.t the new error and increment steps.

Parameters
incrThe new increment steps.

Definition at line 205 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

205  {
206  current_step_ += incr;
207  }
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ verbosity()

INLINE bool gum::ApproximationScheme::verbosity ( ) const
virtualinherited

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 153 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

153 { return verbosity_; }
bool verbosity_
If true, verbosity is enabled.
+ Here is the call graph for this function:

Member Data Documentation

◆ burn_in_

Size gum::ApproximationScheme::burn_in_
protectedinherited

Number of iterations before checking stopping criteria.

Definition at line 413 of file approximationScheme.h.

◆ current_epsilon_

double gum::ApproximationScheme::current_epsilon_
protectedinherited

Current epsilon.

Definition at line 368 of file approximationScheme.h.

◆ current_rate_

double gum::ApproximationScheme::current_rate_
protectedinherited

Current rate.

Definition at line 374 of file approximationScheme.h.

◆ current_state_

ApproximationSchemeSTATE gum::ApproximationScheme::current_state_
protectedinherited

The current state.

Definition at line 383 of file approximationScheme.h.

◆ current_step_

Size gum::ApproximationScheme::current_step_
protectedinherited

The current step.

Definition at line 377 of file approximationScheme.h.

◆ enabled_eps_

bool gum::ApproximationScheme::enabled_eps_
protectedinherited

If true, the threshold convergence is enabled.

Definition at line 392 of file approximationScheme.h.

◆ enabled_max_iter_

bool gum::ApproximationScheme::enabled_max_iter_
protectedinherited

If true, the maximum iterations stopping criterion is enabled.

Definition at line 410 of file approximationScheme.h.

◆ enabled_max_time_

bool gum::ApproximationScheme::enabled_max_time_
protectedinherited

If true, the timeout is enabled.

Definition at line 404 of file approximationScheme.h.

◆ enabled_min_rate_eps_

bool gum::ApproximationScheme::enabled_min_rate_eps_
protectedinherited

If true, the minimal threshold for epsilon rate is enabled.

Definition at line 398 of file approximationScheme.h.

◆ eps_

double gum::ApproximationScheme::eps_
protectedinherited

Threshold for convergence.

Definition at line 389 of file approximationScheme.h.

◆ history_

std::vector< double > gum::ApproximationScheme::history_
protectedinherited

The scheme history, used only if verbosity == true.

Definition at line 386 of file approximationScheme.h.

◆ last_epsilon_

double gum::ApproximationScheme::last_epsilon_
protectedinherited

Last epsilon value.

Definition at line 371 of file approximationScheme.h.

◆ max_iter_

Size gum::ApproximationScheme::max_iter_
protectedinherited

The maximum iterations.

Definition at line 407 of file approximationScheme.h.

◆ max_time_

double gum::ApproximationScheme::max_time_
protectedinherited

The timeout.

Definition at line 401 of file approximationScheme.h.

◆ MaxNbDecreasing__

Size gum::learning::LocalSearchWithTabuList::MaxNbDecreasing__ {2}
private

the max number of changes decreasing the score that we allow to apply

Definition at line 128 of file localSearchWithTabuList.h.

◆ min_rate_eps_

double gum::ApproximationScheme::min_rate_eps_
protectedinherited

Threshold for the epsilon rate.

Definition at line 395 of file approximationScheme.h.

◆ onProgress

Signaler3< Size, double, double > gum::IApproximationSchemeConfiguration::onProgress
inherited

Progression, error and time.

Definition at line 58 of file IApproximationSchemeConfiguration.h.

◆ onStop

Signaler1< std::string > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 61 of file IApproximationSchemeConfiguration.h.

◆ period_size_

Size gum::ApproximationScheme::period_size_
protectedinherited

Checking criteria frequency.

Definition at line 416 of file approximationScheme.h.

◆ timer_

Timer gum::ApproximationScheme::timer_
protectedinherited

The timer.

Definition at line 380 of file approximationScheme.h.

◆ verbosity_

bool gum::ApproximationScheme::verbosity_
protectedinherited

If true, verbosity is enabled.

Definition at line 419 of file approximationScheme.h.


The documentation for this class was generated from the following files: