Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Copyright (C) 2012 Sergey Lisitsyn | ||
*/ | ||
|
||
#include <shogun/transfer/multitask/MultitaskROCEvaluation.h> | ||
#include <shogun/mathematics/Math.h> | ||
|
||
#include <set> | ||
#include <vector> | ||
|
||
using namespace std; | ||
using namespace shogun; | ||
|
||
void CMultitaskROCEvaluation::set_indices(SGVector<index_t> indices) | ||
{ | ||
indices.display_vector("indices"); | ||
ASSERT(m_task_relation); | ||
|
||
set<index_t> indices_set; | ||
for (int32_t i=0; i<indices.vlen; i++) | ||
indices_set.insert(indices[i]); | ||
|
||
if (m_num_tasks>0) | ||
{ | ||
for (int32_t t=0; t<m_num_tasks; t++) | ||
m_tasks_indices[t].~SGVector<index_t>(); | ||
SG_FREE(m_tasks_indices); | ||
} | ||
m_num_tasks = m_task_relation->get_num_tasks(); | ||
m_tasks_indices = SG_MALLOC(SGVector<index_t>, m_num_tasks); | ||
|
||
SGVector<index_t>* tasks_indices = m_task_relation->get_tasks_indices(); | ||
for (int32_t t=0; t<m_num_tasks; t++) | ||
{ | ||
new (&m_tasks_indices[t]) SGVector<index_t>(); | ||
vector<index_t> task_indices_cut; | ||
SGVector<index_t> task_indices = tasks_indices[t]; | ||
//task_indices.display_vector("task indices"); | ||
for (int32_t i=0; i<task_indices.vlen; i++) | ||
{ | ||
if (indices_set.count(task_indices[i])) | ||
{ | ||
//SG_SPRINT("%d is in %d task\n",task_indices[i],t); | ||
task_indices_cut.push_back(task_indices[i]); | ||
} | ||
} | ||
|
||
SGVector<index_t> cutted(task_indices_cut.size()); | ||
for (int32_t i=0; i<cutted.vlen; i++) | ||
cutted[i] = task_indices_cut[i]; | ||
//cutted.display_vector("cutted"); | ||
m_tasks_indices[t] = cutted; | ||
tasks_indices[t].~SGVector<index_t>(); | ||
} | ||
SG_FREE(tasks_indices); | ||
} | ||
|
||
float64_t CMultitaskROCEvaluation::evaluate(CLabels* predicted, CLabels* ground_truth) | ||
{ | ||
//SG_SPRINT("Evaluate\n"); | ||
predicted->remove_all_subsets(); | ||
ground_truth->remove_all_subsets(); | ||
float64_t result = 0.0; | ||
for (int32_t t=0; t<m_num_tasks; t++) | ||
{ | ||
//SG_SPRINT("%d task", t); | ||
//m_tasks_indices[t].display_vector(); | ||
predicted->add_subset(m_tasks_indices[t]); | ||
ground_truth->add_subset(m_tasks_indices[t]); | ||
result += evaluate_roc(predicted,ground_truth)/m_tasks_indices[t].vlen; | ||
predicted->remove_subset(); | ||
ground_truth->remove_subset(); | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Copyright (C) 2012 Sergey Lisitsyn | ||
*/ | ||
|
||
#ifndef MULTITASKROCEVALUATION_H_ | ||
#define MULTITASKROCEVALUATION_H_ | ||
|
||
#include <shogun/transfer/multitask/TaskRelation.h> | ||
#include <shogun/evaluation/ROCEvaluation.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** @brief Class MultitaskROCEvalution used to evaluate ROC | ||
* (Receiver Operating Characteristic) and an area | ||
* under ROC curve (auROC) of each task separately. | ||
* | ||
*/ | ||
class CMultitaskROCEvaluation: public CROCEvaluation | ||
{ | ||
public: | ||
/** constructor */ | ||
CMultitaskROCEvaluation() : | ||
CROCEvaluation(), m_task_relation(NULL), m_tasks_indices(NULL), | ||
m_num_tasks(0) | ||
{ | ||
} | ||
|
||
/** constructor */ | ||
CMultitaskROCEvaluation(CTaskRelation* task_relation) : | ||
CROCEvaluation(), m_task_relation(NULL), m_tasks_indices(NULL), | ||
m_num_tasks(0) | ||
{ | ||
set_task_relation(task_relation); | ||
} | ||
|
||
/** destructor */ | ||
virtual ~CMultitaskROCEvaluation() | ||
{ | ||
for (int32_t i=0; i<m_num_tasks; i++) | ||
m_tasks_indices[i].~SGVector<index_t>(); | ||
SG_FREE(m_tasks_indices); | ||
} | ||
|
||
/** set task relation */ | ||
void set_task_relation(CTaskRelation* task_relation) | ||
{ | ||
SG_REF(task_relation); | ||
SG_UNREF(m_task_relation); | ||
m_task_relation = task_relation; | ||
} | ||
|
||
/** get task relation */ | ||
CTaskRelation* get_task_relation() const | ||
{ | ||
SG_REF(m_task_relation); | ||
return m_task_relation; | ||
} | ||
|
||
/** set absolute indices of labels to be evaluated next | ||
* used by multitask evaluations | ||
* | ||
* @param indices indices | ||
*/ | ||
virtual void set_indices(SGVector<index_t> indices); | ||
|
||
/** get name */ | ||
virtual const char* get_name() const { return "MultitaskROCEvaluation"; }; | ||
|
||
/** evaluate ROC and auROC | ||
* @param predicted labels | ||
* @param ground_truth labels assumed to be correct | ||
* @return auROC | ||
*/ | ||
virtual float64_t evaluate(CLabels* predicted, CLabels* ground_truth); | ||
|
||
/** get evaluation direction */ | ||
virtual EEvaluationDirection get_evaluation_direction() | ||
{ | ||
return ED_MAXIMIZE; | ||
} | ||
|
||
protected: | ||
|
||
/** task relation */ | ||
CTaskRelation* m_task_relation; | ||
|
||
/** indices */ | ||
SGVector<index_t>* m_tasks_indices; | ||
|
||
/** num tasks */ | ||
int32_t m_num_tasks; | ||
}; | ||
|
||
} | ||
|
||
#endif /* MULTITASKROCEVALUATION_H_ */ |