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

SHOGUN Machine Learning Toolbox - Documentation