-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
MultitaskLinearMachine.h
155 lines (120 loc) · 3.47 KB
/
MultitaskLinearMachine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012 Sergey Lisitsyn
*/
#ifndef MULTITASKMACHINE_H_
#define MULTITASKMACHINE_H_
#include <shogun/lib/config.h>
#ifdef USE_GPL_SHOGUN
#include <shogun/machine/LinearMachine.h>
#include <shogun/transfer/multitask/TaskRelation.h>
#include <shogun/transfer/multitask/TaskGroup.h>
#include <shogun/transfer/multitask/TaskTree.h>
#include <shogun/transfer/multitask/Task.h>
#include <vector>
#include <set>
namespace shogun
{
/** @brief class MultitaskLinearMachine, a base class
* for linear multitask classifiers
*/
class CMultitaskLinearMachine : public CLinearMachine
{
public:
/** default constructor */
CMultitaskLinearMachine();
/** constructor
*
* @param training_data training features
* @param training_labels training labels
* @param task_relation task relation
*/
CMultitaskLinearMachine(
CDotFeatures* training_data,
CLabels* training_labels, CTaskRelation* task_relation);
/** destructor */
virtual ~CMultitaskLinearMachine();
/** get name */
virtual const char* get_name() const
{
return "MultitaskLinearMachine";
}
/** getter for current task
* @return current task index
*/
int32_t get_current_task() const;
/** setter for current task
* @param task task index
*/
void set_current_task(int32_t task);
/** get w
*
* @return weight vector
*/
virtual SGVector<float64_t> get_w() const;
/** set w
*
* @param src_w new w
*/
virtual void set_w(const SGVector<float64_t> src_w);
/** set bias
*
* @param b new bias
*/
virtual void set_bias(float64_t b);
/** get bias
*
* @return bias
*/
virtual float64_t get_bias();
/** getter for task relation
* @return task relation
*/
CTaskRelation* get_task_relation() const;
/** setter for task relation
* @param task_relation task relation
*/
void set_task_relation(CTaskRelation* task_relation);
/** @return whether machine supports locking */
virtual bool supports_locking() const { return true; }
/** post lock */
virtual void post_lock(CLabels* labels, CFeatures* features_);
#ifndef SWIG // SWIG should skip this part
/** train on given indices */
virtual bool train_locked(SGVector<index_t> indices);
/** applies on given indices */
virtual CBinaryLabels* apply_locked_binary(SGVector<index_t> indices);
#endif // SWIG // SWIG should skip this part
/** applies to one vector */
virtual float64_t apply_one(int32_t i);
protected:
/** apply get outputs */
virtual SGVector<float64_t> apply_get_outputs(CFeatures* data=NULL);
/** train machine */
virtual bool train_machine(CFeatures* data=NULL);
/** train locked implementation */
virtual bool train_locked_implementation(SGVector<index_t>* tasks);
/** subset mapped task indices */
SGVector<index_t>* get_subset_tasks_indices();
private:
/** register parameters */
void register_parameters();
protected:
/** current task index */
int32_t m_current_task;
/** feature tree */
CTaskRelation* m_task_relation;
/** tasks w's */
SGMatrix<float64_t> m_tasks_w;
/** tasks interceptss */
SGVector<float64_t> m_tasks_c;
/** vector of sets of indices */
std::vector< std::set<index_t> > m_tasks_indices;
};
}
#endif //USE_GPL_SHOGUN
#endif