SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MultitaskL12LogisticRegression.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 Sergey Lisitsyn
8  */
9 
13 #include <shogun/lib/SGVector.h>
15 
16 namespace shogun
17 {
18 
20 {
21 public:
22 
25 
28 };
29 
32 {
33  set_rho1(0.0);
34  set_rho2(0.0);
35  init();
36 }
37 
39  float64_t rho1, float64_t rho2, CDotFeatures* train_features,
40  CBinaryLabels* train_labels, CTaskGroup* task_group) :
41  CMultitaskLogisticRegression(0.0,train_features,train_labels,(CTaskRelation*)task_group)
42 {
43  set_rho1(rho1);
44  set_rho2(rho2);
45  init();
46 }
47 
48 void CMultitaskL12LogisticRegression::init()
49 {
50  SG_ADD(&self->m_rho1,"rho1","rho L1/L2 regularization parameter",MS_AVAILABLE);
51  SG_ADD(&self->m_rho2,"rho2","rho L2 regularization parameter",MS_AVAILABLE);
52 }
53 
55 {
56  self->m_rho1 = rho1;
57 }
58 
60 {
61  self->m_rho2 = rho2;
62 }
63 
65 {
66  return self->m_rho1;
67 }
68 
70 {
71  return self->m_rho2;
72 }
73 
75 {
76 }
77 
79 {
81  for (int32_t i=0; i<y.vlen; i++)
82  y[i] = ((CBinaryLabels*)m_labels)->get_label(i);
83 
84  malsar_options options = malsar_options::default_options();
85  options.termination = m_termination;
86  options.tolerance = m_tolerance;
87  options.max_iter = m_max_iter;
88  options.n_tasks = ((CTaskGroup*)m_task_relation)->get_num_tasks();
89  options.tasks_indices = tasks;
90 #ifdef HAVE_EIGEN3
91  malsar_result_t model = malsar_joint_feature_learning(
92  features, y.vector, self->m_rho1, self->m_rho2, options);
93 
94  m_tasks_w = model.w;
95  m_tasks_c = model.c;
96 #else
97  SG_WARNING("Please install Eigen3 to use MultitaskL12LogisticRegression\n")
98  m_tasks_w = SGMatrix<float64_t>(((CDotFeatures*)features)->get_dim_feature_space(), options.n_tasks);
99  m_tasks_c = SGVector<float64_t>(options.n_tasks);
100 #endif
101 
102  return true;
103 }
104 
106 {
107  if (data && (CDotFeatures*)data)
108  set_features((CDotFeatures*)data);
109 
113 
115  for (int32_t i=0; i<y.vlen; i++)
116  y[i] = ((CBinaryLabels*)m_labels)->get_label(i);
117 
118  malsar_options options = malsar_options::default_options();
119  options.termination = m_termination;
120  options.tolerance = m_tolerance;
121  options.max_iter = m_max_iter;
122  options.n_tasks = ((CTaskGroup*)m_task_relation)->get_num_tasks();
123  options.tasks_indices = ((CTaskGroup*)m_task_relation)->get_tasks_indices();
124 
125 #ifdef HAVE_EIGEN3
126  malsar_result_t model = malsar_joint_feature_learning(
127  features, y.vector, self->m_rho1, self->m_rho2, options);
128 
129  m_tasks_w = model.w;
130  m_tasks_c = model.c;
131 #else
132  SG_WARNING("Please install Eigen3 to use MultitaskL12LogisticRegression\n")
133  m_tasks_w = SGMatrix<float64_t>(((CDotFeatures*)features)->get_dim_feature_space(), options.n_tasks);
134  m_tasks_c = SGVector<float64_t>(options.n_tasks);
135 #endif
136 
137  SG_FREE(options.tasks_indices);
138 
139  return true;
140 }
141 
142 }
virtual int32_t get_num_labels() const =0
CLabels * m_labels
Definition: Machine.h:361
virtual bool train_locked_implementation(SGVector< index_t > *tasks)
class TaskGroup used to represent a group of tasks. Tasks in group do not overlap.
Definition: TaskGroup.h:28
Features that support dot products among other operations.
Definition: DotFeatures.h:44
class Multitask Logistic Regression used to solve classification problems with a few tasks related vi...
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
virtual void set_features(CDotFeatures *feat)
CDotFeatures * features
malsar_result_t malsar_joint_feature_learning(CDotFeatures *features, double *y, double rho1, double rho2, const malsar_options &options)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
used to represent tasks in multitask learning
Definition: TaskRelation.h:31
#define SG_WARNING(...)
Definition: SGIO.h:128
#define SG_ADD(...)
Definition: SGObject.h:81

SHOGUN Machine Learning Toolbox - Documentation