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

SHOGUN Machine Learning Toolbox - Documentation