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/features/LatentFeatures.h> 00012 00013 using namespace shogun; 00014 00015 CLatentFeatures::CLatentFeatures() 00016 { 00017 init(); 00018 m_samples = new CDynamicObjectArray(10); 00019 SG_REF(m_samples); 00020 } 00021 00022 CLatentFeatures::CLatentFeatures(int32_t num_samples) 00023 { 00024 init(); 00025 m_samples = new CDynamicObjectArray(num_samples); 00026 SG_REF(m_samples); 00027 } 00028 00029 CLatentFeatures::~CLatentFeatures() 00030 { 00031 SG_UNREF(m_samples); 00032 } 00033 00034 CFeatures* CLatentFeatures::duplicate() const 00035 { 00036 return new CLatentFeatures(*this); 00037 } 00038 00039 EFeatureType CLatentFeatures::get_feature_type() const 00040 { 00041 return F_ANY; 00042 } 00043 00044 EFeatureClass CLatentFeatures::get_feature_class() const 00045 { 00046 return C_LATENT; 00047 } 00048 00049 00050 int32_t CLatentFeatures::get_num_vectors() const 00051 { 00052 if (m_samples == NULL) 00053 return 0; 00054 else 00055 return m_samples->get_array_size(); 00056 } 00057 00058 bool CLatentFeatures::add_sample(CData* example) 00059 { 00060 ASSERT(m_samples != NULL) 00061 if (m_samples != NULL) 00062 { 00063 m_samples->push_back(example); 00064 return true; 00065 } 00066 else 00067 return false; 00068 } 00069 00070 CData* CLatentFeatures::get_sample(index_t idx) 00071 { 00072 ASSERT(m_samples != NULL) 00073 if (idx < 0 || idx >= this->get_num_vectors()) 00074 SG_ERROR("Out of index!\n") 00075 00076 return (CData*) m_samples->get_element(idx); 00077 00078 } 00079 00080 void CLatentFeatures::init() 00081 { 00082 SG_ADD((CSGObject**) &m_samples, "samples", "Array of examples", 00083 MS_NOT_AVAILABLE); 00084 } 00085 00086 CLatentFeatures* CLatentFeatures::obtain_from_generic(CFeatures* base_feats) 00087 { 00088 ASSERT(base_feats != NULL) 00089 if (base_feats->get_feature_class() == C_LATENT) 00090 return (CLatentFeatures*) base_feats; 00091 else 00092 SG_SERROR("base_labels must be of dynamic type CLatentLabels\n") 00093 00094 return NULL; 00095 } 00096