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) 1999-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/machine/Machine.h> 00012 #include <shogun/base/Parameter.h> 00013 #include <shogun/mathematics/Math.h> 00014 00015 using namespace shogun; 00016 00017 CMachine::CMachine() : CSGObject(), max_train_time(0), labels(NULL), 00018 solver_type(ST_AUTO) 00019 { 00020 m_parameters->add(&max_train_time, "max_train_time", 00021 "Maximum training time."); 00022 m_parameters->add((machine_int_t*) &solver_type, "solver_type"); 00023 m_parameters->add((CSGObject**) &labels, "labels"); 00024 m_parameters->add(&m_store_model_features, "store_model_features", 00025 "Should feature data of model be stored after training?"); 00026 00027 m_store_model_features=false; 00028 } 00029 00030 CMachine::~CMachine() 00031 { 00032 SG_UNREF(labels); 00033 } 00034 00035 bool CMachine::train(CFeatures* data) 00036 { 00037 bool result = train_machine(data); 00038 00039 if (m_store_model_features) 00040 store_model_features(); 00041 00042 return result; 00043 } 00044 00045 float64_t CMachine::apply(int32_t num) 00046 { 00047 SG_NOTIMPLEMENTED; 00048 return CMath::INFTY; 00049 } 00050 00051 bool CMachine::load(FILE* srcfile) 00052 { 00053 ASSERT(srcfile); 00054 return false; 00055 } 00056 00057 bool CMachine::save(FILE* dstfile) 00058 { 00059 ASSERT(dstfile); 00060 return false; 00061 } 00062 00063 void CMachine::set_labels(CLabels* lab) 00064 { 00065 SG_UNREF(labels); 00066 SG_REF(lab); 00067 labels = lab; 00068 } 00069 00070 CLabels* CMachine::get_labels() 00071 { 00072 SG_REF(labels); 00073 return labels; 00074 } 00075 00076 float64_t CMachine::get_label(int32_t i) 00077 { 00078 if (!labels) 00079 SG_ERROR("No Labels assigned\n"); 00080 00081 return labels->get_label(i); 00082 } 00083 00084 void CMachine::set_max_train_time(float64_t t) 00085 { 00086 max_train_time = t; 00087 } 00088 00089 float64_t CMachine::get_max_train_time() 00090 { 00091 return max_train_time; 00092 } 00093 00094 EClassifierType CMachine::get_classifier_type() 00095 { 00096 return CT_NONE; 00097 } 00098 00099 void CMachine::set_solver_type(ESolverType st) 00100 { 00101 solver_type = st; 00102 } 00103 00104 ESolverType CMachine::get_solver_type() 00105 { 00106 return solver_type; 00107 } 00108 00109 void CMachine::set_store_model_features(bool store_model) 00110 { 00111 m_store_model_features = store_model; 00112 } 00113 00114