SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FactorGraphFeatures.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) 2013 Shell Hu
00008  * Copyright (C) 2013 Shell Hu
00009  */
00010 
00011 #include <shogun/features/FactorGraphFeatures.h>
00012 
00013 using namespace shogun;
00014 
00015 CFactorGraphFeatures::CFactorGraphFeatures()
00016 {
00017     init();
00018     m_samples = new CDynamicObjectArray();
00019     SG_REF(m_samples);
00020 }
00021 
00022 CFactorGraphFeatures::CFactorGraphFeatures(int32_t num_samples)
00023 {
00024     init();
00025     m_samples = new CDynamicObjectArray(num_samples);
00026     SG_REF(m_samples);
00027 }
00028 
00029 CFactorGraphFeatures::~CFactorGraphFeatures()
00030 {
00031     SG_UNREF(m_samples);
00032 }
00033 
00034 CFeatures* CFactorGraphFeatures::duplicate() const
00035 {
00036     return new CFactorGraphFeatures(*this);
00037 }
00038 
00039 EFeatureType CFactorGraphFeatures::get_feature_type() const
00040 {
00041     return F_ANY;
00042 }
00043 
00044 EFeatureClass CFactorGraphFeatures::get_feature_class() const
00045 {
00046     return C_FACTOR_GRAPH;
00047 }
00048 
00049 
00050 int32_t CFactorGraphFeatures::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 CFactorGraphFeatures::add_sample(CFactorGraph* example)
00059 {
00060     if (m_samples != NULL)
00061     {
00062         m_samples->push_back(example);
00063         return true;
00064     }
00065     else
00066         return false;
00067 }
00068 
00069 CFactorGraph* CFactorGraphFeatures::get_sample(index_t idx)
00070 {
00071     REQUIRE(m_samples != NULL, "%s::get_sample(): m_samples is NULL!\n", get_name());
00072     REQUIRE(idx >= 0 && idx < get_num_vectors(), "%s::get_sample(): out of index!\n", get_name());
00073 
00074     return dynamic_cast<CFactorGraph*>(m_samples->get_element(idx));
00075 }
00076 
00077 void CFactorGraphFeatures::init()
00078 {
00079     SG_ADD((CSGObject**) &m_samples, "samples", "Array of examples",
00080             MS_NOT_AVAILABLE);
00081 }
00082 
00083 CFactorGraphFeatures* CFactorGraphFeatures::obtain_from_generic(CFeatures* base_feats)
00084 {
00085     REQUIRE(base_feats != NULL, "CFactorGraphFeatures::obtain_from_generic(): base_feats is NULL!\n");
00086 
00087     if (base_feats->get_feature_class() == C_FACTOR_GRAPH)
00088         return dynamic_cast<CFactorGraphFeatures*>(base_feats);
00089     else
00090         SG_SERROR("base_labels must be of dynamic type CFactorGraph!\n")
00091 
00092     return NULL;
00093 }
00094 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation