SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Task.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 
11 
12 using namespace shogun;
13 
15 {
16  init();
17 
18  m_weight = 0.0;
19  m_name = "task";
20 }
21 
22 CTask::CTask(index_t min_index, index_t max_index,
23  float64_t weight, const char* name) :
24  CSGObject()
25 {
26  init();
27 
28  REQUIRE(min_index<max_index, "min index should be less than max index")
29  m_indices = SGVector<index_t>(max_index-min_index);
30  for (int32_t i=0; i<m_indices.vlen; i++)
31  m_indices[i] = i+min_index;
32  m_weight = weight;
33  m_name = name;
34 }
35 
37  float64_t weight, const char* name) :
38  CSGObject()
39 {
40  init();
41 
42  m_indices = indices;
43 }
44 
45 void CTask::init()
46 {
47  m_subtasks = new CList(true);
49 
50  SG_ADD((CSGObject**)&m_subtasks,"subtasks","subtasks of given task", MS_NOT_AVAILABLE);
51  SG_ADD(&m_indices,"indices","indices of task", MS_NOT_AVAILABLE);
52  SG_ADD(&m_weight,"weight","weight of task", MS_NOT_AVAILABLE);
53 }
54 
56 {
58 }
59 
61 {
62  REQUIRE(m_indices.vlen>1,"Task indices vector must not be empty or contain only one element")
63  bool result = true;
64  for (int32_t i=0; i<m_indices.vlen-1; i++)
65  {
66  if (m_indices[i]!=m_indices[i+1]-1)
67  {
68  result = false;
69  break;
70  }
71  }
72 
73  return result;
74 }
75 
76 void CTask::add_subtask(CTask* subtask)
77 {
78  SGVector<index_t> subtask_indices = subtask->get_indices();
79  for (int32_t i=0; i<subtask_indices.vlen; i++)
80  {
81  bool found = false;
82  for (int32_t j=0; j<m_indices.vlen; j++)
83  {
84  if (subtask_indices[i] == m_indices[j])
85  {
86  found = true;
87  break;
88  }
89  }
90  if (!found)
91  SG_ERROR("Subtask contains indices that are not contained in this task\n")
92  }
93  m_subtasks->append_element(subtask);
94 }
95 
97 {
99  return m_subtasks;
100 }
101 
103 {
104  return m_subtasks->get_num_elements();
105 }
class Task used to represent tasks in multitask learning. Essentially it represent a set of feature v...
Definition: Task.h:27
virtual ~CTask()
Definition: Task.cpp:55
int32_t index_t
Definition: common.h:62
bool is_contiguous()
Definition: Task.cpp:60
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
#define SG_REF(x)
Definition: SGObject.h:54
const char * m_name
Definition: Task.h:131
index_t vlen
Definition: SGVector.h:492
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
double float64_t
Definition: common.h:50
void add_subtask(CTask *sub_task)
Definition: Task.cpp:76
SGVector< index_t > get_indices() const
Definition: Task.h:63
float64_t m_weight
Definition: Task.h:137
int32_t get_num_elements()
Definition: List.h:145
SGVector< index_t > m_indices
Definition: Task.h:134
int32_t get_num_subtasks()
Definition: Task.cpp:102
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
bool append_element(CSGObject *data)
Definition: List.h:331
CList * m_subtasks
Definition: Task.h:128
#define SG_ADD(...)
Definition: SGObject.h:84
Class List implements a doubly connected list for low-level-objects.
Definition: List.h:84
CList * get_subtasks()
Definition: Task.cpp:96

SHOGUN Machine Learning Toolbox - Documentation