Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
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(CSGInterface* ui_)
00022 : CSGObject(), ui(ui_), estimator(NULL),
00023 pos_pseudo(1e-10), neg_pseudo(1e-10)
00024 {
00025 }
00026
00027 CGUIPluginEstimate::~CGUIPluginEstimate()
00028 {
00029 SG_UNREF(estimator);
00030 }
00031
00032 bool CGUIPluginEstimate::new_estimator(float64_t pos, float64_t neg)
00033 {
00034 SG_UNREF(estimator);
00035 estimator=new CPluginEstimate(pos, neg);
00036 SG_REF(estimator);
00037
00038 if (!estimator)
00039 SG_ERROR("Could not create new plugin estimator, pos_pseudo %f, neg_pseudo %f\n", pos_pseudo, neg_pseudo);
00040 else
00041 SG_INFO("Created new plugin estimator (%p), pos_pseudo %f, neg_pseudo %f\n", estimator, pos_pseudo, neg_pseudo);
00042
00043 return true;
00044 }
00045
00046 bool CGUIPluginEstimate::train()
00047 {
00048 CLabels* trainlabels=ui->ui_labels->get_train_labels();
00049 CStringFeatures<uint16_t>* trainfeatures=(CStringFeatures<uint16_t>*) ui->
00050 ui_features->get_train_features();
00051 bool result=false;
00052
00053 if (!trainlabels)
00054 SG_ERROR("No labels available.\n");
00055
00056 if (!trainfeatures)
00057 SG_ERROR("No features available.\n");
00058
00059 ASSERT(trainfeatures->get_feature_type()==F_WORD);
00060
00061 estimator->set_features(trainfeatures);
00062 estimator->set_labels(trainlabels);
00063 if (estimator)
00064 result=estimator->train();
00065 else
00066 SG_ERROR("No estimator available.\n");
00067
00068 return result;
00069 }
00070
00071 bool CGUIPluginEstimate::load(char* param)
00072 {
00073 bool result=false;
00074 return result;
00075 }
00076
00077 bool CGUIPluginEstimate::save(char* param)
00078 {
00079 bool result=false;
00080 return result;
00081 }
00082
00083 CLabels* CGUIPluginEstimate::apply()
00084 {
00085 CFeatures* testfeatures=ui->ui_features->get_test_features();
00086
00087 if (!estimator)
00088 {
00089 SG_ERROR( "no estimator available") ;
00090 return 0;
00091 }
00092
00093 if (!testfeatures)
00094 {
00095 SG_ERROR( "no test features available") ;
00096 return 0;
00097 }
00098
00099 estimator->set_features((CStringFeatures<uint16_t>*) testfeatures);
00100
00101 return estimator->apply();
00102 }
00103
00104 float64_t CGUIPluginEstimate::apply(int32_t idx)
00105 {
00106 CFeatures* testfeatures=ui->ui_features->get_test_features();
00107
00108 if (!estimator)
00109 {
00110 SG_ERROR( "no estimator available") ;
00111 return 0;
00112 }
00113
00114 if (!testfeatures)
00115 {
00116 SG_ERROR( "no test features available") ;
00117 return 0;
00118 }
00119
00120 estimator->set_features((CStringFeatures<uint16_t>*) testfeatures);
00121
00122 return estimator->apply(idx);
00123 }