Definition at line 172 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, mModel, PredictSingle(), Impala::Core::Table::Table::SetSize(), and Impala::Core::Table::Table::Size(). Referenced by Impala::Application::LearnConceptFromAnnotations(). 00175 { 00176 /* this function can be used when the number of column quids is very, 00177 very small and the matrix is very big. This function will cache the 00178 whole (!) matrix part used, so the prediction is faster. WARNING: 00179 the columnQuids are the quids you have learned from! So NOT the quids 00180 to apply to; it will be applied to all quids that are available. 00181 */ 00182 if(!mModel) 00183 { 00184 ILOG_ERROR("[PredictForActiveLearn] classifier untrained\n"); 00185 return; 00186 } 00187 00188 result->SetSize(0); 00189 ILOG_INFO("starting PredictForActiveLearn"); 00190 00191 Table::QuidTable* rowQuids = da->GetRowQuids(); 00192 Table::QuidTable* allColumns = da->GetColumnQuids(); 00193 int rowCount = da->GetRows(); 00194 00195 std::vector<Quid> sortedColumnQuids; 00196 std::vector<int> sortedColumnQuidIndices; 00197 std::vector<Real64*> sortedColumnQuidData; 00198 for(int i = 0; i < allColumns->Size(); i++) 00199 { 00200 if(columnQuids->Contains(allColumns->Get1(i))) 00201 { 00202 // we have this one 00203 sortedColumnQuids.push_back(allColumns->Get1(i)); 00204 sortedColumnQuidIndices.push_back(i); 00205 Real64* buf = new Real64[rowCount]; 00206 int received = da->GetColumn(i, buf, rowCount); 00207 if(received != rowCount) 00208 ILOG_ERROR("[PredictForActiveLearn] didn't receive column"); 00209 sortedColumnQuidData.push_back(buf); 00210 //ILOG_INFO("Loaded " << i << " " << allColumns->Get1(i)); 00211 } 00212 } 00213 if(sortedColumnQuids.size() != columnQuids->Size()) 00214 { 00215 ILOG_ERROR("not all column quids are in the table?!"); 00216 return; 00217 } 00218 00219 ILOG_INFO("Done loading"); 00220 // PATCH THE MODEL 00221 mModel->param.kernel_type = PRECOMPUTED; 00222 00223 int colCount = da->GetColumns(); 00224 struct svm_node* x = new struct svm_node[colCount + 2]; 00225 for(int i = 0; i < colCount + 2; i++) 00226 { 00227 x[i].index = 0; 00228 x[i].value = 0; 00229 } 00230 for(int i = 0; i < rowCount; i++) 00231 { 00232 x[0].index = 0; 00233 x[0].value = -1; // for predict this value is not necessary 00234 // fill it with values 00235 for(int j = 0; j < sortedColumnQuids.size(); j++) 00236 { 00237 int index = sortedColumnQuidIndices[j]+1; 00238 x[index].index = index; 00239 x[index].value = sortedColumnQuidData[j][i]; 00240 } 00241 x[colCount+1].index = -1; // end-of-vector marker 00242 x[colCount+1].value = 0; // not used 00243 00244 //ILOG_INFO("predict " << i); 00245 double score = PredictSingle(x); 00246 result->Add(score); 00247 } 00248 delete x; 00249 for(int i = 0; i < sortedColumnQuidData.size(); i++) 00250 { 00251 delete sortedColumnQuidData[i]; 00252 } 00253 ILOG_INFO("done predict"); 00254 }
Here is the call graph for this function:
|