SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultitaskTraceLogisticRegression.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 
14 #include <shogun/lib/SGVector.h>
15 
16 namespace shogun
17 {
18 
20  CMultitaskLogisticRegression(), m_rho(0.0)
21 {
22  init();
23 }
24 
26  float64_t rho, CDotFeatures* train_features,
27  CBinaryLabels* train_labels, CTaskGroup* task_group) :
28  CMultitaskLogisticRegression(0.0,train_features,train_labels,(CTaskRelation*)task_group)
29 {
30  set_rho(rho);
31  init();
32 }
33 
34 void CMultitaskTraceLogisticRegression::init()
35 {
36  SG_ADD(&m_rho,"rho","rho",MS_AVAILABLE);
37 }
38 
40 {
41  m_rho = rho;
42 }
43 
45 {
46  return m_rho;
47 }
48 
50 {
51 }
52 
54 {
56  for (int32_t i=0; i<y.vlen; i++)
57  y[i] = ((CBinaryLabels*)m_labels)->get_label(i);
58 
59  malsar_options options = malsar_options::default_options();
60  options.termination = m_termination;
61  options.tolerance = m_tolerance;
62  options.max_iter = m_max_iter;
63  options.n_tasks = ((CTaskGroup*)m_task_relation)->get_num_tasks();
64  options.tasks_indices = tasks;
65 
66 #ifdef HAVE_EIGEN3
67  malsar_result_t model = malsar_low_rank(
68  features, y.vector, m_rho, options);
69 
70  m_tasks_w = model.w;
71  m_tasks_c = model.c;
72 #else
73  SG_WARNING("Please install Eigen3 to use MultitaskTraceLogisticRegression\n");
74  m_tasks_w = SGMatrix<float64_t>(((CDotFeatures*)features)->get_dim_feature_space(), options.n_tasks);
75  m_tasks_c = SGVector<float64_t>(options.n_tasks);
76 #endif
77  return true;
78 }
79 
81 {
82  if (data && (CDotFeatures*)data)
83  set_features((CDotFeatures*)data);
84 
88 
90  for (int32_t i=0; i<y.vlen; i++)
91  y[i] = ((CBinaryLabels*)m_labels)->get_label(i);
92 
93  malsar_options options = malsar_options::default_options();
94  options.termination = m_termination;
95  options.tolerance = m_tolerance;
96  options.max_iter = m_max_iter;
97  options.n_tasks = ((CTaskGroup*)m_task_relation)->get_num_tasks();
98  options.tasks_indices = ((CTaskGroup*)m_task_relation)->get_tasks_indices();
99 
100 #ifdef HAVE_EIGEN3
101  malsar_result_t model = malsar_low_rank(
102  features, y.vector, m_rho, options);
103 
104  m_tasks_w = model.w;
105  m_tasks_c = model.c;
106 #else
107  SG_WARNING("Please install Eigen3 to use MultitaskTraceLogisticRegression\n");
108  m_tasks_w = SGMatrix<float64_t>(((CDotFeatures*)features)->get_dim_feature_space(), options.n_tasks);
109  m_tasks_c = SGVector<float64_t>(options.n_tasks);
110 #endif
111 
112  for (int32_t i=0; i<options.n_tasks; i++)
113  options.tasks_indices[i].~SGVector<index_t>();
114  SG_FREE(options.tasks_indices);
115 
116  return true;
117 }
118 
119 }

SHOGUN Machine Learning Toolbox - Documentation