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

virtual void Impala::Core::Training::Svm::PredictForActiveLearn ( Matrix::DistributedAccess da,
Table::QuidTable columnQuids,
Core::Table::SimilarityTableSet::SimTableType result 
) [inline, virtual]

Deprecated:
Note:
Works only with kernel models. It uses a model trained from distributed kernels. Then 'patches' that so it can be fed a non-distributed kernel problem.
This function is used by Ork (and Koen). In the new paradigm onw would create a custum TrainDataSrc. Of course this needs some more works as one would need to 'patch the model'

Definition at line 133 of file Svm.h.

References Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Add(), Impala::Core::Table::QuidTable::Contains(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get1(), Impala::Core::Matrix::DistributedAccess::GetColumn(), Impala::Core::Matrix::DistributedAccess::GetColumnQuids(), Impala::Core::Matrix::DistributedAccess::GetColumns(), Impala::Core::Matrix::DistributedAccess::GetRowQuids(), Impala::Core::Matrix::DistributedAccess::GetRows(), ILOG_ERROR, ILOG_INFO, svm_node::index, svm_parameter::kernel_type, mModel, svm_model::param, PredictSingle(), Impala::Core::Table::Table::SetSize(), Impala::Core::Table::Table::Size(), and svm_node::value.

Referenced by Impala::Application::LearnConceptFromAnnotations().

00136     {
00137         /* this function can be used when the number of column quids is very,
00138            very small and the matrix is very big.  This function will cache the
00139            whole (!) matrix part used, so the prediction is faster.  WARNING:
00140            the columnQuids are the quids you have learned from! So NOT the quids
00141            to apply to; it will be applied to all quids that are available.
00142         */
00143         if(!mModel)
00144         {
00145             ILOG_ERROR("[PredictForActiveLearn] classifier untrained\n");
00146             return;
00147         }
00148         
00149         result->SetSize(0);
00150         ILOG_INFO("starting PredictForActiveLearn");
00151         
00152         Table::QuidTable* rowQuids = da.GetRowQuids();
00153         Table::QuidTable* allColumns = da.GetColumnQuids();
00154         int rowCount = da.GetRows();
00155         
00156         std::vector<Quid>    sortedColumnQuids;
00157         std::vector<int>     sortedColumnQuidIndices;
00158         std::vector<Real64*> sortedColumnQuidData;
00159         for(int i = 0; i < allColumns->Size(); i++)
00160         {
00161             if(columnQuids->Contains(allColumns->Get1(i)))
00162             {
00163                 // we have this one
00164                 sortedColumnQuids.push_back(allColumns->Get1(i));
00165                 sortedColumnQuidIndices.push_back(i);
00166                 Real64* buf = new Real64[rowCount];
00167                 int received = da.GetColumn(i, buf, rowCount);
00168                 if(received != rowCount)
00169                     ILOG_ERROR("[PredictForActiveLearn] didn't receive column");
00170                 sortedColumnQuidData.push_back(buf);
00171                 //ILOG_INFO("Loaded " << i << " " << allColumns->Get1(i));
00172             }
00173         }
00174         if(sortedColumnQuids.size() != columnQuids->Size())
00175         {
00176             ILOG_ERROR("not all column  quids are in the table?!");
00177             return;
00178         }
00179 
00180         ILOG_INFO("Done loading");
00181         // PATCH THE MODEL
00182         mModel->param.kernel_type = PRECOMPUTED;
00183 
00184         int colCount = da.GetColumns();
00185         struct svm_node* x = new struct svm_node[colCount + 2];
00186         for(int i = 0; i < colCount + 2; i++)
00187         {
00188             x[i].index = 0;
00189             x[i].value = 0;
00190         }
00191         for(int i = 0; i < rowCount; i++)
00192         {
00193             x[0].index = 0;
00194             x[0].value = -1; // for predict this value is not necessary
00195             // fill it with values
00196             for(int j = 0; j < sortedColumnQuids.size(); j++)
00197             {
00198                 int index = sortedColumnQuidIndices[j];
00199                 x[index].index = index;
00200                 x[index].value = sortedColumnQuidData[j][i];
00201             }
00202             x[colCount+1].index = -1; // end-of-vector marker
00203             x[colCount+1].value = 0;  // not used
00204 
00205             //ILOG_INFO("predict " << i);
00206             double score = PredictSingle(x);
00207             result->Add(score);
00208         }
00209         delete x;
00210         for(int i = 0; i < sortedColumnQuidData.size(); i++)
00211         {
00212             delete sortedColumnQuidData[i];
00213         }
00214         ILOG_INFO("done predict");
00215     }

Here is the call graph for this function:


Generated on Fri Mar 19 11:23:59 2010 for ImpalaSrc by  doxygen 1.5.1