SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
MultitaskTraceLogisticRegression.cpp
浏览该文件的文档.
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 }
virtual int32_t get_num_labels() const =0
CLabels * m_labels
Definition: Machine.h:361
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)
malsar_result_t malsar_low_rank(CDotFeatures *features, double *y, double rho, const malsar_options &options)
CDotFeatures * features
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual bool train_locked_implementation(SGVector< index_t > *tasks)
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 机器学习工具包 - 项目文档