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) 2013 Thoralf Klein 00008 * Written (W) 2012 Fernando José Iglesias García 00009 * Copyright (C) 2012 Fernando José Iglesias García 00010 */ 00011 00012 #include <shogun/machine/LinearStructuredOutputMachine.h> 00013 #include <shogun/structure/MulticlassSOLabels.h> 00014 00015 using namespace shogun; 00016 00017 CLinearStructuredOutputMachine::CLinearStructuredOutputMachine() 00018 : CStructuredOutputMachine() 00019 { 00020 register_parameters(); 00021 } 00022 00023 CLinearStructuredOutputMachine::CLinearStructuredOutputMachine( 00024 CStructuredModel* model, 00025 CStructuredLabels* labs) 00026 : CStructuredOutputMachine(model, labs) 00027 { 00028 register_parameters(); 00029 } 00030 00031 CLinearStructuredOutputMachine::~CLinearStructuredOutputMachine() 00032 { 00033 } 00034 00035 void CLinearStructuredOutputMachine::set_w(SGVector< float64_t > w) 00036 { 00037 m_w = w; 00038 } 00039 00040 SGVector< float64_t > CLinearStructuredOutputMachine::get_w() const 00041 { 00042 return m_w; 00043 } 00044 00045 CStructuredLabels* CLinearStructuredOutputMachine::apply_structured(CFeatures* data) 00046 { 00047 if (data) 00048 { 00049 set_features(data); 00050 } 00051 00052 CFeatures* model_features = this->get_features(); 00053 if (!model_features) 00054 { 00055 return m_model->structured_labels_factory(); 00056 } 00057 00058 int num_input_vectors = model_features->get_num_vectors(); 00059 CStructuredLabels* out; 00060 out = m_model->structured_labels_factory(num_input_vectors); 00061 00062 for ( int32_t i = 0 ; i < num_input_vectors ; ++i ) 00063 { 00064 CResultSet* result = m_model->argmax(m_w, i, false); 00065 out->add_label(result->argmax); 00066 00067 SG_UNREF(result); 00068 } 00069 SG_UNREF(model_features); 00070 return out; 00071 } 00072 00073 void CLinearStructuredOutputMachine::register_parameters() 00074 { 00075 SG_ADD(&m_w, "m_w", "Weight vector", MS_NOT_AVAILABLE); 00076 } 00077 00078 void CLinearStructuredOutputMachine::store_model_features() 00079 { 00080 }