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

KernelMatrix.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Training_KernelMatrix_h
00002 #define Impala_Core_Training_KernelMatrix_h
00003 
00004 #include "Core/Feature/FeatureTable.h"
00005 #include "Core/Matrix/DistributedAccess.h"
00006 #include "Core/Array/Diff.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Training
00013 {
00014 
00015 
00018 class KernelMatrix
00019 {
00020 public:
00021 
00022     typedef Vector::VectorTem<Real64> Vector64;
00023 
00024     KernelMatrix()
00025     {
00026         mFeatureTab = 0;
00027         mDA = 0;
00028     }
00029 
00030     KernelMatrix(Feature::FeatureTable* tab)
00031     {
00032         mFeatureTab = tab;
00033         mDA = 0;
00034     }
00035 
00036     KernelMatrix(Matrix::DistributedAccess* da)
00037     {
00038         mFeatureTab = 0;
00039         mDA = da;
00040     }
00041 
00042     virtual
00043     ~KernelMatrix()
00044     {
00045         if (mFeatureTab)
00046             delete mFeatureTab;
00047         if (mDA)
00048             delete mDA;
00049     }
00050 
00051     Matrix::DistributedAccess*
00052     GetDA()
00053     {
00054         return mDA;
00055     }
00056 
00057     Feature::FeatureTable*
00058     GetFeatureTab()
00059     {
00060         return mFeatureTab;
00061     }
00062 
00063     int
00064     Diff(KernelMatrix* arg) const
00065     {
00066         if (mFeatureTab)
00067             return mFeatureTab->DiffMatrix(arg->mFeatureTab);
00068         if (mDA)
00069         {
00070             ILOG_INFO("Checking row quids");
00071             Table::QuidTable* q1 = mDA->GetRowQuids();
00072             Table::QuidTable* q2 = arg->mDA->GetRowQuids();
00073             int diff = q1->Diff(q2);
00074             if (diff > 0)
00075                 return diff;
00076 
00077             ILOG_INFO("Checking column quids");
00078             q1 = mDA->GetColumnQuids();
00079             q2 = arg->mDA->GetColumnQuids();
00080             diff = q1->Diff(q2);
00081             if (diff > 0)
00082                 return diff;
00083 
00084             ILOG_INFO("Checking features, weight, and average");
00085             for (int i=0 ; i<mDA->GetNrFeatures() ; i++)
00086             {
00087                 if (mDA->GetFeature(i) != arg->mDA->GetFeature(i))
00088                     diff++;
00089                 else if (mDA->GetWeight(i) != arg->mDA->GetWeight(i))
00090                     diff++;
00091                 else if (fabs(mDA->GetAverage(i) - arg->mDA->GetAverage(i))
00092                          > 0.00001)
00093                 {
00094                     ILOG_INFO("[Diff] average " << i << " differs: " <<
00095                               mDA->GetAverage(i) << " vs "
00096                               << arg->mDA->GetAverage(i));
00097                     diff++;
00098                 }
00099             }
00100             if (diff > 0)
00101             {
00102                 ILOG_ERROR("Found " << diff << " diffs in features, etc.");
00103                 return diff;
00104             }
00105 
00106             ILOG_INFO("Checking data");
00107             diff = mDA->Diff(arg->mDA);
00108             return diff;
00109         }
00110         ILOG_ERROR("Diff: logic error");
00111         return 1;
00112     }
00113 
00114     virtual void
00115     Dump(Database::RawDataSet* dataSet, int from = 0, int to = -1)
00116     {
00117         /*
00118         if (to == -1 || to > Size())
00119             to = Size();
00120         if (to < from)
00121             to = from;
00122         */
00123         if (mFeatureTab)
00124             mFeatureTab->Dump(dataSet, from, to);
00125         if (mDA)
00126         {
00127             mDA->Dump();
00128         }
00129     }
00130 
00131     int
00132     NrRow()
00133     {
00134         if (mFeatureTab)
00135             return mFeatureTab->Size();
00136         if (mDA)
00137             return mDA->GetRows();
00138         return 0;
00139     }
00140 
00141     int
00142     NrCol()
00143     {
00144         if (mFeatureTab)
00145             return mFeatureTab->GetFeatureVectorLength();
00146         if (mDA)
00147             return mDA->GetColumns();
00148         return 0;
00149     }
00150 
00151     Table::QuidTable*
00152     GetQuids()
00153     {
00154         if (mDA)
00155             return mDA->GetRowQuids();
00156         return 0;
00157     }
00158 
00159     int
00160     GetRow(int rowNr, Real64* buffer, int bufferSize)
00161     {
00162         if (mDA)
00163             return mDA->GetRow(rowNr, buffer, bufferSize);
00164         return 0;
00165     }
00166 
00167 private:
00168 
00169     Feature::FeatureTable*     mFeatureTab;
00170     Matrix::DistributedAccess* mDA;
00171 
00172     ILOG_VAR_DEC;
00173 
00174 };
00175 
00176 ILOG_VAR_INIT(KernelMatrix, Impala.Core.Training);
00177 
00178 } // namespace Training
00179 } // namespace Core
00180 } // namespace Impala
00181 
00182 #endif

Generated on Thu Jan 13 09:04:41 2011 for ImpalaSrc by  doxygen 1.5.1