Labels.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Written (W) 2011-2012 Heiko Strathmann
00010  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00011  */
00012 
00013 #include <shogun/labels/Labels.h>
00014 #include <shogun/lib/common.h>
00015 #include <shogun/io/SGIO.h>
00016 #include <shogun/base/Parameter.h>
00017 
00018 using namespace shogun;
00019 
00020 CLabels::CLabels()
00021 : CSGObject()
00022 {
00023     init();
00024 }
00025 
00026 CLabels::~CLabels()
00027 {
00028     SG_UNREF(m_subset_stack);
00029 }
00030 
00031 void CLabels::init()
00032 {
00033     SG_ADD((CSGObject**)&m_subset_stack, "subset_stack",
00034             "Current subset stack", MS_NOT_AVAILABLE);
00035 
00036     m_subset_stack=new CSubsetStack();
00037     SG_REF(m_subset_stack);
00038 }
00039 
00040 void CLabels::add_subset(SGVector<index_t> subset)
00041 {
00042     m_subset_stack->add_subset(subset);
00043 }
00044 
00045 void CLabels::remove_subset()
00046 {
00047     m_subset_stack->remove_subset();
00048 }
00049 
00050 void CLabels::remove_all_subsets()
00051 {
00052     m_subset_stack->remove_all_subsets();
00053 }
00054 
00055 float64_t CLabels::get_value(int32_t idx)
00056 {
00057     ASSERT(m_current_values.vector && idx<get_num_labels());
00058     int32_t real_num=m_subset_stack->subset_idx_conversion(idx);
00059     return m_current_values.vector[real_num];
00060 }
00061 
00062 void CLabels::set_value(float64_t value, int32_t idx)
00063 {
00064     int32_t real_num=m_subset_stack->subset_idx_conversion(idx);
00065     ASSERT(m_current_values.vector && idx<get_num_labels());
00066     m_current_values.vector[real_num]=value;
00067 }
00068 
00069 void CLabels::set_values(SGVector<float64_t> values)
00070 {
00071     if (m_current_values.vlen!=0 && m_current_values.vlen!=get_num_labels())
00072     {
00073         SG_ERROR("length of value values should match number of labels or"
00074                 " have zero length (len(labels)=%d, len(values)=%d)\n",
00075                 get_num_labels(), values.vlen);
00076     }
00077 
00078     m_current_values=values;
00079 }
00080 
00081 SGVector<float64_t> CLabels::get_values()
00082 {
00083     return m_current_values;
00084 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation