Go to the documentation of this file.00001 #include <icf_core/client/Client.h>
00002 #include <icf_core/base/EvaluationResult.hpp>
00003 #include <icf_core/base/ConfusionMatrix.hpp>
00004 #include <icf_core/base/ClassificationResult.hpp>
00005
00006 ...
00007
00008 std::map<int, std::string> classnames;
00009 std::string classifier;
00010 std::string parameters;
00011
00012 Eigen::MatrixXf conf_mat;
00013
00014
00015 ClassifierManager* g_manager;
00016 ServerSideRepo* data_store;
00017 ClassifierClient* client_test;
00018
00019 ~Destructor ()
00020 {
00021
00022 delete g_manager;
00023 delete data_store;
00024 delete client_test;
00025 }
00026
00027 Constructor()
00028 {
00029
00030 classifier = "knn";
00031 parameters = "-m chisquared -k 10 -w";
00032
00033
00034 std::string model_file_base = "~/.ros/vfh_subsets1to3_with_evaluation_knn";
00035
00036 classnames[1]="Armchair";
00037 classnames[2]="Chair1";
00038 classnames[3]="Chair2";
00039 classnames[4]="Chair3";
00040 classnames[5]="Sideboard";
00041 classnames[6]="Table1";
00042 classnames[7]="Table2";
00043 classnames[8]="Table3";
00044
00045
00046
00047 std::string manager_name = "kinect_uima_bridge";
00048 data_store = new ServerSideRepo(n, manager_name);
00049 client_test = new ClassifierClient(n, manager_name, classifier, parameters);
00050 client_test->load(model_file_base);
00051
00052
00053 conf_mat = client_test->getConfusionMatrix()->getCM().cast<float>();
00054 Eigen::ArrayXf col_sums = conf_mat.colwise().sum();
00055
00056
00057 for (int i=0; i<conf_mat.rows(); ++i)
00058 for (int j=0; j<conf_mat.cols(); ++j)
00059 conf_mat(i,j) /= col_sums(j);
00060
00061 }
00062
00063 void classify (std::vector<float> feature)
00064 {
00065 try
00066 {
00067
00068 DS ds;
00069 DS::Matrix feature_matrix(1, feature.size());
00070 feature_matrix.row(0) = Eigen::VectorXf::Map(&feature[0], feature.size()).cast<double>();
00071 ds.setFeatureMatrix(feature_matrix, "/x");
00072
00073 data_store->uploadData(ds, "test");
00074
00075
00076 client_test->assignData("test", icf::Classify);
00077 ClassificationResult classificationResult = client_test->classify();
00078
00079
00080 int result = classificationResult.results->at(0);
00081
00082
00083 for(std::map<int,std::string>::iterator mit = classnames.begin(); mit != classnames.end(); ++mit)
00084 {
00085
00086 float accuracy = conf_mat(mit->first-1,result-1);
00087 float confidence = classificationResult.confidenceFor(0,mit->first);
00088 float score = confidence * accuracy;
00089 }
00090 }
00091 catch (ICFException& e)
00092 {
00093 std::cerr << boost::diagnostic_information(e);
00094 std::vector<service_unavailable_error>* err = boost::get_error_info<service_unavailable_collection>(e);
00095 if (err != NULL)
00096 {
00097 for (std::vector<service_unavailable_error>::iterator iter = err->begin(); iter != err->end(); iter++)
00098 std::cerr << "Error: " << iter->value() << std::endl;
00099 }
00100 else
00101 std::cerr << "No service availability related errors" << std::endl;
00102 }
00103 }
00104