00001 #ifndef Impala_Core_Training_ApplyConceptsHelperFeatures_h 00002 #define Impala_Core_Training_ApplyConceptsHelperFeatures_h 00003 00004 #include "Core/Training/ApplyConceptsHelper.h" 00005 #include "Core/Table/Read.h" 00006 #include "Core/Training/TrainDataSrcFeatureTable.h" 00007 #include "Core/Training/KernelFunctions.h" 00008 00009 namespace Impala 00010 { 00011 namespace Core 00012 { 00013 namespace Training 00014 { 00015 00016 class ApplyConceptsHelperFeatures : public ApplyConceptsHelper 00017 { 00018 public: 00019 ApplyConceptsHelperFeatures() 00020 : mInitialized(false), mFeatures(0) 00021 { 00022 } 00023 00024 void 00025 Initialise(Database::RawDataSet* annoSet, String featureName) 00026 { 00027 mAnnoSet = annoSet; 00028 mFeatures = 0; 00029 mFeatureDef = Feature::FeatureDefinition(featureName); 00030 mInitialized = true; 00031 } 00032 00033 String 00034 GetModelName() 00035 { 00036 return mFeatureDef.AsString(); 00037 } 00038 00039 FeatureTable* 00040 LoadFeatures(Database::PathCreator* pathCreator) 00041 { 00042 if(!mInitialized) 00043 ILOG_ERROR("not initialized"); 00044 if(mFeatures) 00045 ILOG_ERROR("programming error"); 00046 String path = pathCreator->GetFilePathFeatureData(false, false); 00047 mFeatures = FeatureTable::MakeFromFile(mFeatureDef, path, 00048 pathCreator->GetDatabase()); 00049 return mFeatures; 00050 } 00051 00052 Table::ScoreTable* 00053 Predict(String modelName) 00054 { 00055 if(!mInitialized) 00056 ILOG_ERROR("not initialized"); 00057 Training::Classifier* classifier = 00058 Training::LoadClassifier(modelName, mAnnoSet->GetDatabase()); 00059 TrainDataSrcFeatureTable dataSrc(0, mFeatures); 00060 ILOG_DEBUG("data size = " << dataSrc.Size()); 00061 Table::ScoreTable* scores = classifier->Predict(&dataSrc); 00062 delete classifier; 00063 return scores; 00064 } 00065 00066 void 00067 UnloadFeatures() 00068 { 00069 delete mFeatures; 00070 mFeatures = 0; 00071 } 00072 00073 private: 00074 Database::RawDataSet* mAnnoSet; 00075 FeatureTable* mFeatures; 00076 Feature::FeatureDefinition mFeatureDef; 00077 bool mInitialized; 00078 ILOG_VAR_DEC; 00079 }; 00080 00081 ILOG_VAR_INIT(ApplyConceptsHelperFeatures, Impala.Core.Training); 00082 00083 } //namespace 00084 } //namespace 00085 } //namespace 00086 00087 #endif