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

FeatureTable* Impala::Core::Training::ApplyConceptsHelperKernels::LoadFeatures ( const FeatureLocator featLoc  )  [inline, virtual]

Implements Impala::Core::Training::ApplyConceptsHelper.

Definition at line 61 of file ApplyConceptsHelperKernels.h.

References Impala::Core::Array::Add(), Impala::Core::Vector::Apply(), Impala::Core::Vector::Chi2Distance(), Impala::Core::Table::Copy(), Impala::Core::Array::DivVal(), Impala::Core::Array::Exp(), Impala::Core::Matrix::DistributedAccess::GetAverage(), Impala::CmdOptions::GetBool(), Impala::Persistency::FeatureLocator::GetContainer(), Impala::Core::Matrix::DistributedAccess::GetFeature(), Impala::Persistency::FeatureLocator::GetFeatureString(), Impala::Core::Training::KernelMatrix::GetFeatureTab(), Impala::CmdOptions::GetInstance(), Impala::Core::Database::RawDataSet::GetLocator(), Impala::Core::Matrix::DistributedAccess::GetNrFeatures(), Impala::Core::Database::RawDataSet::GetSetName(), Impala::Core::Matrix::DistributedAccess::GetTotalWeight(), Impala::Persistency::FeatureLocator::GetWalkType(), Impala::Core::Matrix::DistributedAccess::GetWeight(), Impala::Core::Vector::HistogramIntersectionDouble(), ILOG_DEBUG, ILOG_ERROR, ILOG_INFO, mAnnoSet, Impala::Core::Matrix::MatNrCol(), mDA, mFeatureExternal, mFeatureIndexCat, mKernelMatrix, mKernelMatrixName, mModel, Impala::Core::Array::MulVal(), Impala::Core::Array::Set(), Impala::Persistency::FeatureLocator::SetFeatureString(), Impala::Core::Vector::VectorSet< ArrayT >::SetSize(), Impala::Core::Table::Table::Size(), and Impala::StringStartsWith().

00062     {
00063         typedef Persistency::KernelMatrixLocator KernelMatrixLocator;
00064         typedef Persistency::KernelMatrixRepository KernelMatrixRepository;
00065         typedef Persistency::FeatureTableRepository FeatureTableRepository;
00066         CmdOptions& options = CmdOptions::GetInstance();
00067         if (mFeatureExternal)
00068             ILOG_ERROR("features not empty");
00069 
00070         KernelMatrixLocator kernelDataLoc
00071             (featLoc, false, featLoc.GetWalkType(), mAnnoSet->GetSetName(),
00072              mModel, featLoc.GetFeatureString(), featLoc.GetContainer());
00073         kernelDataLoc.SetFeatureIndexCat(mFeatureIndexCat);
00074         if (KernelMatrixRepository().Exists(kernelDataLoc))
00075         {
00076             ILOG_INFO("Using cache from KernelData: " << kernelDataLoc);
00077 
00078             // we have an on-disk cache in the KernelData folder
00079             // mFeatureExternal is used elsewhere for the quids and the size
00080             // so this featuretable can perform that role as well
00081             KernelMatrix* kerData = KernelMatrixRepository().Get(kernelDataLoc);
00082             mFeatureExternal = kerData->GetFeatureTab();
00083             // don't delete kerData, awaiting further refactoring
00084 
00085             // wrap the storage of this feature table in a matrix/array
00086             size_t w = mFeatureExternal->GetColumn2()->GetStorage()->CW();
00087             size_t h = mFeatureExternal->GetColumn2()->GetStorage()->CH();
00088             ILOG_DEBUG("size of kernel matrix is ("<< w <<", "<< h <<")");
00089             mKernelMatrix = new Array::Array2dScalarReal64(w, h, 0, 0, 
00090                 mFeatureExternal->GetColumn2()->GetStorage()->mData, true);
00091             return mFeatureExternal;
00092         }
00093 
00094         int sizeCheck = -1;
00095         Matrix::Mat* accumulator = 0;
00096         bool isHik = StringStartsWith(mModel, "hik");
00097         for (int i=0 ; i<mDA->GetNrFeatures() ; i++)
00098         {
00099             // load apply to feature
00100             FeatureLocator fLoc = featLoc;
00101             fLoc.SetFeatureString(mDA->GetFeature(i));
00102             FeatureTable* feature = FeatureTableRepository().Get(fLoc);
00103             if (sizeCheck == -1)
00104                 sizeCheck = feature->Size();
00105             if (feature->Size() != sizeCheck)
00106             {
00107                 ILOG_ERROR("Size mismatch in the FeatureData for the dataset to"
00108                            << " apply to: have " << sizeCheck << " and " <<
00109                            feature->Size());
00110                 throw "bye";
00111             }
00112             ILOG_INFO("size of apply set " << mDA->GetFeature(i) <<
00113                       " is " << feature->Size());
00114 
00115             // load train feature
00116             FeatureLocator loc(mAnnoSet->GetLocator(), false, true,
00117                                mFeatureIndexCat, mDA->GetFeature(i), "");
00118             FeatureTable* trainFeature =
00119                 Persistency::FeatureTableRepository().Get(loc);
00120             ILOG_INFO("size of train " << mDA->GetFeature(i) << " is "
00121                       << trainFeature->Size());
00122 
00123             // compute kernel distances between features
00124             typedef Feature::FeatureTable::ColumnVectorSet VectorSet;
00125             VectorSet* vectorsV = feature->GetColumn2();
00126             VectorSet* vectorsH = trainFeature->GetColumn2();
00127             vectorsV->SetSize(feature->Size());
00128             vectorsH->SetSize(trainFeature->Size());
00129             ILOG_INFO("Compute distance matrix for feature " << i << "...");
00130             Matrix::Mat* distanceMatrix = 0;
00131             if (isHik)
00132             {
00133                 distanceMatrix = Apply(&Core::Vector::HistogramIntersectionDouble,
00134                                        vectorsH, vectorsV);
00135             }
00136             else
00137             {
00138                 distanceMatrix = Apply(&Core::Vector::Chi2Distance,
00139                                        vectorsH, vectorsV);
00140             }
00141             delete trainFeature;
00142 
00143             // accumulate; this is the part inside the 'exp' in the kernel function
00144             MulVal(distanceMatrix, distanceMatrix, mDA->GetWeight(i));
00145             if (!isHik)
00146                 DivVal(distanceMatrix, distanceMatrix, -mDA->GetAverage(i));
00147             if (accumulator == 0)
00148                 Set(accumulator, distanceMatrix);
00149             else
00150                 Add(accumulator, accumulator, distanceMatrix);
00151             delete distanceMatrix;
00152             if (i == 0)
00153             {
00154                 mFeatureExternal = feature;
00155             }
00156             else
00157             {
00158                 delete feature;
00159             }
00160         }
00161         // only thing to do is weigh and exp
00162         DivVal(accumulator, accumulator, mDA->GetTotalWeight());
00163         if (!isHik)
00164             Exp(accumulator, accumulator);
00165         mKernelMatrix = accumulator;
00166         if (options.GetBool("storeKernelData"))
00167         {
00168             FeatureTable* storage =
00169                 new FeatureTable(mKernelMatrixName, sizeCheck,
00170                                  Matrix::MatNrCol(mKernelMatrix));
00171             Column::Copy(storage->GetColumn1(), mFeatureExternal->GetColumn1(),
00172                          sizeCheck);
00173             // the VectorSet likes owning the storage after setting it,
00174             // so we must create a wrapper to prevent it from deleting the
00175             // kernel matrix when the storage is destroyed
00176             Array::Array2dScalarReal64* wrapper = 
00177                 new Array::Array2dScalarReal64(mKernelMatrix->CW(),
00178                                                mKernelMatrix->CH(), 0, 0,
00179                                                mKernelMatrix->mData, true);
00180             storage->GetColumn2()->SetStorage(wrapper);
00181             storage->GetColumn2()->SetSize(sizeCheck);
00182             storage->SetSize(sizeCheck);
00183             KernelMatrix kerData(storage);
00184             Persistency::KernelMatrixRepository().Add(kernelDataLoc, &kerData);
00185         }
00186         return mFeatureExternal;
00187     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:21:11 2011 for ImpalaSrc by  doxygen 1.5.1