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) 1999-2008 Soeren Sonnenburg 00008 * Written (W) 1999-2008 Gunnar Raetsch 00009 * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society 00010 */ 00011 00012 #include <shogun/ui/SGInterface.h> 00013 #include <shogun/ui/GUIPluginEstimate.h> 00014 00015 #include <shogun/lib/config.h> 00016 #include <shogun/io/SGIO.h> 00017 #include <shogun/features/StringFeatures.h> 00018 00019 using namespace shogun; 00020 00021 CGUIPluginEstimate::CGUIPluginEstimate() : CSGObject() 00022 { 00023 init(); 00024 } 00025 00026 CGUIPluginEstimate::CGUIPluginEstimate(CSGInterface* ui_) 00027 : CSGObject() 00028 { 00029 init(); 00030 00031 ui=ui_; 00032 } 00033 00034 CGUIPluginEstimate::~CGUIPluginEstimate() 00035 { 00036 SG_UNREF(estimator); 00037 } 00038 00039 void CGUIPluginEstimate::init() 00040 { 00041 ui=NULL; 00042 estimator=NULL; 00043 pos_pseudo=1e-10; 00044 neg_pseudo=1e-10; 00045 } 00046 00047 bool CGUIPluginEstimate::new_estimator(float64_t pos, float64_t neg) 00048 { 00049 SG_UNREF(estimator); 00050 estimator=new CPluginEstimate(pos, neg); 00051 SG_REF(estimator); 00052 00053 if (!estimator) 00054 SG_ERROR("Could not create new plugin estimator, pos_pseudo %f, neg_pseudo %f\n", pos_pseudo, neg_pseudo) 00055 else 00056 SG_INFO("Created new plugin estimator (%p), pos_pseudo %f, neg_pseudo %f\n", estimator, pos_pseudo, neg_pseudo) 00057 00058 return true; 00059 } 00060 00061 bool CGUIPluginEstimate::train() 00062 { 00063 CLabels* trainlabels=ui->ui_labels->get_train_labels(); 00064 CStringFeatures<uint16_t>* trainfeatures=(CStringFeatures<uint16_t>*) ui-> 00065 ui_features->get_train_features(); 00066 bool result=false; 00067 00068 if (!trainlabels) 00069 SG_ERROR("No labels available.\n") 00070 00071 if (!trainfeatures) 00072 SG_ERROR("No features available.\n") 00073 00074 ASSERT(trainfeatures->get_feature_type()==F_WORD) 00075 00076 estimator->set_features(trainfeatures); 00077 estimator->set_labels(trainlabels); 00078 if (estimator) 00079 result=estimator->train(); 00080 else 00081 SG_ERROR("No estimator available.\n") 00082 00083 return result; 00084 } 00085 00086 bool CGUIPluginEstimate::load(char* param) 00087 { 00088 bool result=false; 00089 return result; 00090 } 00091 00092 bool CGUIPluginEstimate::save(char* param) 00093 { 00094 bool result=false; 00095 return result; 00096 } 00097 00098 CLabels* CGUIPluginEstimate::apply() 00099 { 00100 CFeatures* testfeatures=ui->ui_features->get_test_features(); 00101 00102 if (!estimator) 00103 { 00104 SG_ERROR("no estimator available") 00105 return 0; 00106 } 00107 00108 if (!testfeatures) 00109 { 00110 SG_ERROR("no test features available") 00111 return 0; 00112 } 00113 00114 estimator->set_features((CStringFeatures<uint16_t>*) testfeatures); 00115 00116 return estimator->apply(); 00117 } 00118 00119 float64_t CGUIPluginEstimate::apply_one(int32_t idx) 00120 { 00121 CFeatures* testfeatures=ui->ui_features->get_test_features(); 00122 00123 if (!estimator) 00124 { 00125 SG_ERROR("no estimator available") 00126 return 0; 00127 } 00128 00129 if (!testfeatures) 00130 { 00131 SG_ERROR("no test features available") 00132 return 0; 00133 } 00134 00135 estimator->set_features((CStringFeatures<uint16_t>*) testfeatures); 00136 00137 return estimator->apply_one(idx); 00138 }