SHOGUN
v3.2.0
|
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) 2012 Viktor Gal 00008 * Copyright (C) 2012 Viktor Gal 00009 */ 00010 00011 #include <shogun/labels/LatentLabels.h> 00012 00013 using namespace shogun; 00014 00015 CLatentLabels::CLatentLabels() 00016 : CLabels() 00017 { 00018 init(); 00019 } 00020 00021 CLatentLabels::CLatentLabels(int32_t num_samples) 00022 : CLabels() 00023 { 00024 init(); 00025 m_latent_labels = new CDynamicObjectArray(num_samples); 00026 SG_REF(m_latent_labels); 00027 } 00028 00029 CLatentLabels::CLatentLabels(CLabels* labels) 00030 : CLabels() 00031 { 00032 init(); 00033 set_labels(labels); 00034 00035 int32_t num_labels = 0; 00036 if (m_labels) 00037 num_labels = m_labels->get_num_labels(); 00038 00039 m_latent_labels = new CDynamicObjectArray(num_labels); 00040 SG_REF(m_latent_labels); 00041 } 00042 00043 CLatentLabels::~CLatentLabels() 00044 { 00045 SG_UNREF(m_latent_labels); 00046 SG_UNREF(m_labels); 00047 } 00048 00049 void CLatentLabels::init() 00050 { 00051 SG_ADD((CSGObject**) &m_latent_labels, "m_latent_labels", "The latent labels", MS_NOT_AVAILABLE); 00052 SG_ADD((CSGObject**) &m_labels, "m_labels", "The labels", MS_NOT_AVAILABLE); 00053 m_latent_labels = NULL; 00054 m_labels = NULL; 00055 } 00056 00057 CDynamicObjectArray* CLatentLabels::get_latent_labels() const 00058 { 00059 SG_REF(m_latent_labels); 00060 return m_latent_labels; 00061 } 00062 00063 CData* CLatentLabels::get_latent_label(int32_t idx) 00064 { 00065 ASSERT(m_latent_labels != NULL) 00066 if (idx < 0 || idx >= get_num_labels()) 00067 SG_ERROR("Out of index!\n") 00068 00069 return (CData*) m_latent_labels->get_element(idx); 00070 } 00071 00072 void CLatentLabels::add_latent_label(CData* label) 00073 { 00074 ASSERT(m_latent_labels != NULL) 00075 m_latent_labels->push_back(label); 00076 } 00077 00078 bool CLatentLabels::set_latent_label(int32_t idx, CData* label) 00079 { 00080 if (idx < get_num_labels()) 00081 { 00082 return m_latent_labels->set_element(label, idx); 00083 } 00084 else 00085 { 00086 return false; 00087 } 00088 } 00089 00090 void CLatentLabels::ensure_valid(const char* context) 00091 { 00092 if (m_latent_labels == NULL) 00093 SG_ERROR("Non-valid LatentLabels in %s", context) 00094 } 00095 00096 int32_t CLatentLabels::get_num_labels() const 00097 { 00098 if (!m_latent_labels || !m_labels) 00099 return 0; 00100 int32_t num_labels = m_latent_labels->get_num_elements(); 00101 00102 ASSERT(num_labels == m_labels->get_num_labels()) 00103 00104 return num_labels; 00105 } 00106 00107 void CLatentLabels::set_labels(CLabels* labels) 00108 { 00109 SG_REF(labels); 00110 SG_UNREF(m_labels); 00111 m_labels = labels; 00112 } 00113 00114 CLabels* CLatentLabels::get_labels() const 00115 { 00116 SG_REF(m_labels); 00117 return m_labels; 00118 } 00119