Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

Table::SimilarityTableSet* Impala::Application::LearnConceptFromAnnotations ( CmdOptions &  options,
Matrix::DistributedAccess &  da,
String  concept,
String  modelname,
Table::AnnotationTable *  annotations,
Util::Database *  db 
)

Definition at line 25 of file mainActiveLearner.cpp.

References Impala::Util::PropertySet::Add(), Impala::Core::Table::Copy(), Impala::Core::Matrix::DistributedAccess::GetColumnQuids(), Impala::CmdOptions::GetInt(), Impala::Util::PropertySet::GetName(), Impala::Core::Matrix::DistributedAccess::GetRowQuids(), Impala::Util::PropertySet::GetValue(), ILOG_INFO, ILOG_VAR, Impala::Core::Training::Svm::PredictForActiveLearn(), Impala::Core::Training::Svm::SaveModel(), Impala::Core::Table::Select(), Impala::Util::PropertySet::Size(), and Impala::Core::Training::Svm::Train().

Referenced by RunDistributedLearningEngine().

00030 {
00031     ILOG_VAR(Application.LearnConceptFromAnnotations);
00032 
00033 
00034     ILOG_INFO("concept " << concept);
00035 
00036     //load annotation
00037     Table::QuidTable* allQuids = da.GetColumnQuids();
00038     Table::CriterionElement1InSet<Table::AnnotationTable> c(allQuids);
00039     Table::AnnotationTable* annotation = Select(annotations, c);
00040 
00041     Table::QuidTable* positive = annotation->GetPositive();
00042     Table::QuidTable* negative = annotation->GetNegative();
00043     Table::QuidTable* learnQuids = positive;
00044     learnQuids->Append(negative);
00045     delete negative;
00046 
00047     if((positive->Size() == 0) || (negative->Size() == 0))
00048     {
00049         delete learnQuids;
00050         delete annotation;
00051         return 0;
00052     }
00053 
00054     // read params from best file: the seccond line in the file
00055 /*    filename = dataSet->GetFilePathConceptModel
00056         (conceptSet, modelType, featureDef, concept+".best", false, false);
00057     if (filename.empty())
00058     {
00059         ILOG_INFO("Could not open " << concept << ".best, skipping");
00060         continue;
00061     }*/
00062 
00063 /*    // TODO: estimate .best file
00064 
00065     Util::IOBuffer* ioBuf = db->GetIOBuffer(filename, true, false, "");
00066     String buffer = ioBuf->ReadLine();
00067     ILOG_INFO(buffer);
00068     buffer = ioBuf->ReadLine();
00069     Util::PropertySet params(buffer);
00070 */
00071     Util::PropertySet params;
00072     params.Add("probability", 1);
00073     params.Add("cache", options.GetInt("cache"));
00074 
00075     params.Add("gamma", -1);
00076     params.Add("autoweight", 1);
00077     params.Add("kernel", "dist-precomputed");
00078     params.Add("precompute-kernel", "chi2");
00079     params.Add("evaluator", "AP");
00080     params.Add("C", 1.0);
00081     params.Add("w1", 30.0); // estimate these
00082     params.Add("w2", 1.2); // estimate these
00083     for(int i = 0; i < params.Size(); i++)
00084         ILOG_INFO(params.GetName(i) + " " + params.GetValue(i));
00085 
00086     //compute model:
00087     Core::Training::Svm svm;
00088     Core::Training::TrainDataSrcKernelDistributed* dataSrc = new TrainDataSrcKernelDistributed(&da, annotation);
00089     svm.Train(&params, dataSrc);
00090     if(!modelname.empty())    
00091         svm.SaveModel(modelname, db);
00092 
00093     // compute resulting ranking:
00094     std::vector<std::string> names;
00095     names.push_back(concept);
00096     Table::QuidTable* rowQuids = da.GetRowQuids();
00097     Table::SimilarityTableSet *simSet = new Table::SimilarityTableSet(names, rowQuids->Size());
00098     Core::Table::Copy(simSet->GetQuidTable(), rowQuids);
00099 
00100     ILOG_INFO("applying model");
00101     svm.PredictForActiveLearn(da, learnQuids, simSet->GetSimTable(0));
00102     
00103     ILOG_INFO("ranking");
00104     simSet->ComputeRank(0, true);
00105     
00106     delete annotation;
00107     delete learnQuids;
00108     delete dataSrc;
00109 
00110     return simSet;
00111 
00112 }

Here is the call graph for this function:


Generated on Fri Mar 19 10:36:13 2010 for ImpalaSrc by  doxygen 1.5.1