SHOGUN  6.1.3
MachineEvaluation.cpp
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 #include <shogun/base/Parameter.h>
18 #include <shogun/machine/Machine.h>
20 
21 #include <rxcpp/rx-lite.hpp>
22 #include <shogun/base/init.h>
23 #include <shogun/lib/Signal.h>
24 
25 using namespace shogun;
26 
28 {
29  init();
30 }
31 
33  CLabels* labels, CSplittingStrategy* splitting_strategy,
34  CEvaluation* evaluation_criterion, bool autolock)
35 {
36  init();
37 
38  m_machine = machine;
39  m_features = features;
40  m_labels = labels;
41  m_splitting_strategy = splitting_strategy;
42  m_evaluation_criterion = evaluation_criterion;
43  m_autolock = autolock;
44 
50 }
51 
53  CSplittingStrategy* splitting_strategy,
54  CEvaluation* evaluation_criterion, bool autolock)
55 {
56  init();
57 
58  m_machine = machine;
59  m_labels = labels;
60  m_splitting_strategy = splitting_strategy;
61  m_evaluation_criterion = evaluation_criterion;
62  m_autolock = autolock;
63 
68 }
69 
71 {
77 }
78 
80 {
81  m_machine = NULL;
82  m_features = NULL;
83  m_labels = NULL;
84  m_splitting_strategy = NULL;
86  m_do_unlock = false;
87  m_autolock = true;
88  m_cancel_computation = false;
90 
91  SG_ADD((CSGObject**)&m_machine, "machine", "Used learning machine",
93  SG_ADD((CSGObject**)&m_features, "features", "Used features",
95  SG_ADD((CSGObject**)&m_labels, "labels", "Used labels",
97  SG_ADD((CSGObject**)&m_splitting_strategy, "splitting_strategy",
98  "Used splitting strategy", MS_NOT_AVAILABLE);
99  SG_ADD((CSGObject**)&m_evaluation_criterion, "evaluation_criterion",
100  "Used evaluation criterion", MS_NOT_AVAILABLE);
101  SG_ADD(&m_do_unlock, "do_unlock",
102  "Whether machine should be unlocked after evaluation",
104  SG_ADD(&m_autolock, "m_autolock",
105  "Whether machine should automatically try to be locked before ",
107 
108 }
109 
111 {
112  SG_DEBUG("entering %s::evaluate()\n", get_name())
113 
114  REQUIRE(
115  m_machine, "%s::evaluate() is only possible if a machine is "
116  "attached\n",
117  get_name());
118 
119  REQUIRE(
120  m_features, "%s::evaluate() is only possible if features are "
121  "attached\n",
122  get_name());
123 
124  REQUIRE(
125  m_labels, "%s::evaluate() is only possible if labels are "
126  "attached\n",
127  get_name());
128 
129  auto sub = connect_to_signal_handler();
130  CEvaluationResult* result = evaluate_impl();
131  sub.unsubscribe();
133 
134  SG_DEBUG("leaving %s::evaluate()\n", get_name())
135  return result;
136 };
137 
139 {
140  SG_REF(m_machine);
141  return m_machine;
142 }
143 
145 {
147 }
148 
150 {
151  // Subscribe this algorithm to the signal handler
152  auto subscriber = rxcpp::make_subscriber<int>(
153  [this](int i) {
154  if (i == SG_PAUSE_COMP)
155  this->on_pause();
156  else
157  this->on_next();
158  },
159  [this]() { this->on_complete(); });
160  return get_global_signal()->get_observable()->subscribe(subscriber);
161 }
virtual const char * get_name() const =0
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual EEvaluationDirection get_evaluation_direction() const =0
Abstract base class for all splitting types. Takes a CLabels instance and generates a desired number ...
#define REQUIRE(x,...)
Definition: SGIO.h:181
#define SG_REF(x)
Definition: SGObject.h:52
A generic learning machine interface.
Definition: Machine.h:151
SGObservableS * get_observable()
Definition: Signal.h:61
rxcpp::subscription connect_to_signal_handler()
std::atomic< bool > m_pause_computation_flag
CSignal * get_global_signal()
Definition: init.cpp:202
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. ...
EEvaluationDirection get_evaluation_direction()
#define SG_UNREF(x)
Definition: SGObject.h:53
#define SG_DEBUG(...)
Definition: SGIO.h:106
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
#define SG_ADD(...)
Definition: SGObject.h:93
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