Skip to content

Commit

Permalink
Added get_binary_for_class method that presents multiclass labels as …
Browse files Browse the repository at this point in the history
…binary subtask
  • Loading branch information
lisitsyn committed May 16, 2012
1 parent 3db552b commit 7e00d0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/shogun/features/Labels.cpp
Expand Up @@ -255,3 +255,16 @@ void CLabels::remove_all_subsets()
{
m_subset_stack->remove_all_subsets();
}

CLabels* CLabels::get_binary_for_class(int32_t i)
{
SGVector<float64_t> binary_labels(get_num_labels());

for (int32_t k=0; binary_labels.vlen; k++)
{
int32_t label = get_int_label(i);
binary_labels[k] = label == i ? +1.0 : -1.0;
}

return new CLabels(binary_labels);
}
7 changes: 7 additions & 0 deletions src/shogun/features/Labels.h
Expand Up @@ -216,6 +216,13 @@ class CLabels : public CSGObject
* Calls subset_changed_post() afterwards */
virtual void remove_all_subsets();

/** returns labels containing +1 at positions with ith class
* and -1 at other positions
* @param i index of class
* @return new binary labels
*/
CLabels* get_binary_for_class(int32_t i);

public:

/** label designates classify reject */
Expand Down

0 comments on commit 7e00d0e

Please sign in to comment.