SHOGUN  6.1.3
MachineEvaluation.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Copyright (C) 2012 Jacob Walker
8  *
9  * Some code adapted from CrossValidation class by
10  * Heiko Strathmann
11  */
12 
13 #ifndef CMACHINEEVALUATION_H_
14 #define CMACHINEEVALUATION_H_
15 
16 #include <shogun/lib/config.h>
17 
18 #include <shogun/base/SGObject.h>
22 
23 #include <condition_variable>
24 #include <mutex>
25 
26 namespace shogun
27 {
28 
29 #define EVALUATION_CONTROLLERS \
30  if (cancel_evaluation()) \
31  continue; \
32  pause_evaluation();
33 
34  class CMachine;
35  class CFeatures;
36  class CLabels;
37  class CSplittingStrategy;
38  class CEvaluation;
39 
45  {
46 
47  public:
49 
60  CMachine* machine, CFeatures* features, CLabels* labels,
61  CSplittingStrategy* splitting_strategy,
62  CEvaluation* evaluation_criterion, bool autolock = true);
63 
72  CMachine* machine, CLabels* labels,
73  CSplittingStrategy* splitting_strategy,
74  CEvaluation* evaluation_criterion, bool autolock = true);
75 
76  virtual ~CMachineEvaluation();
77 
80 
89  virtual CEvaluationResult* evaluate();
90 
92  CMachine* get_machine() const;
93 
96  void set_autolock(bool autolock)
97  {
98  m_autolock = autolock;
99  }
100 
101 #ifndef SWIG
102 
104  {
105  return m_cancel_computation.load();
106  }
107 #endif
108 
109 #ifndef SWIG
110 
112  {
113  if (m_pause_computation_flag.load())
114  {
115  std::unique_lock<std::mutex> lck(m_mutex);
116  while (m_pause_computation_flag.load())
117  m_pause_computation.wait(lck);
118  }
119  }
120 #endif
121 
122 #ifndef SWIG
123 
125  {
126  std::unique_lock<std::mutex> lck(m_mutex);
127  m_pause_computation_flag = false;
128  m_pause_computation.notify_all();
129  }
130 #endif
131 
132  protected:
134  virtual void init();
135 
142  virtual CEvaluationResult* evaluate_impl() = 0;
143 
145  rxcpp::subscription connect_to_signal_handler();
146 
149  {
150  m_cancel_computation = false;
151  m_pause_computation_flag = false;
152  }
153 
156  virtual void on_next()
157  {
158  m_cancel_computation.store(true);
159  }
160 
163  virtual void on_pause()
164  {
165  m_pause_computation_flag.store(true);
166  /* Here there should be the actual code*/
168  }
169 
172  virtual void on_complete()
173  {
174  }
175 
176  protected:
179 
182 
185 
188 
191 
194 
197 
199  std::atomic<bool> m_cancel_computation;
200 
202  std::atomic<bool> m_pause_computation_flag;
203 
205  std::condition_variable m_pause_computation;
206 
208  std::mutex m_mutex;
209  };
210 
211 } /* namespace shogun */
212 
213 #endif /* CMACHINEEVALUATION_H_ */
void set_autolock(bool autolock)
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
SG_FORCED_INLINE void resume_evaluation()
Abstract base class for all splitting types. Takes a CLabels instance and generates a desired number ...
A generic learning machine interface.
Definition: Machine.h:151
#define SG_FORCED_INLINE
Definition: common.h:91
rxcpp::subscription connect_to_signal_handler()
std::atomic< bool > m_pause_computation_flag
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:124
CMachine * get_machine() const
EEvaluationDirection
Definition: Evaluation.h:29
Abstract class that contains the result generated by the MachineEvaluation class. ...
Machine Evaluation is an abstract class that evaluates a machine according to some criterion...
EEvaluationDirection get_evaluation_direction()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual CEvaluationResult * evaluate()
The class Features is the base class of all feature objects.
Definition: Features.h:69
SG_FORCED_INLINE bool cancel_evaluation() const
std::condition_variable m_pause_computation
SG_FORCED_INLINE void pause_evaluation()
virtual CEvaluationResult * evaluate_impl()=0
std::atomic< bool > m_cancel_computation
Class Evaluation, a base class for other classes used to evaluate labels, e.g. accuracy of classifica...
Definition: Evaluation.h:40
CSplittingStrategy * m_splitting_strategy

SHOGUN Machine Learning Toolbox - Documentation