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

void Impala::Core::Training::Fisher::Train ( Util::PropertySet properties  )  [inline]

Definition at line 182 of file Fisher.h.

References Impala::Core::Vector::AddAssign(), Impala::Core::Vector::Avg(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CH(), CNormC(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CW(), Impala::Core::Vector::VectorTem< ElemT >::Elem(), Impala::Core::Vector::VectorSet< ArrayT >::GetVector(), Impala::Core::Matrix::MatMul(), Impala::Core::Matrix::MatPInv(), mOffset, mRotation, mTrainFeatures, mTrainLabels, Impala::Core::Vector::MulAssign(), Impala::Core::Array::Set(), Impala::Core::Vector::SetPart(), Impala::Core::Vector::VectorSet< ArrayT >::SetStorage(), Impala::Core::Array::SetVal(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::SetValue(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::Value(), and Impala::Core::Array::W.

00183     { 
00184         int i,j;
00185         bool debug=false;
00186         int W = mTrainFeatures->CW();
00187         int H = mTrainFeatures->CH();
00188 
00189         Matrix::Mat* tmp    = 0;
00190         Matrix::Mat* tmp2   = 0;
00191         Matrix::Mat* tmp3   = 0;
00192 
00193         Matrix::Mat* Targets= 0;
00194         Matrix::Mat* FeatureAverages   = 0;
00195         Matrix::Mat* CenteredFeatureInverse = 0;
00196         Array::Array2dScalarReal64* CenteredFeatures   = 0;
00197         Array::Array2dScalarReal64* Features = 0;
00198         Array::Array2dScalarReal64* Labels   = 0;
00199 
00200         Vector::VectorSet<Array::Array2dScalarReal64> vs(true, W, H);
00201 
00202         Array::Set(Features,mTrainFeatures);
00203         Array::Set(Labels,mTrainLabels);
00204 
00206         //Clear the transformation if it was already calculated
00207         if(mRotation!=0)
00208             delete mRotation;
00209         if(mOffset!=0)
00210             delete mOffset;
00211 
00213         //Get The Average for each feature
00214         vs.SetStorage(Features);
00215         Vector::VectorTem<Real64> featureMeans=0;
00216         Avg(&featureMeans,&vs,H,0);
00217         
00219         //Center the data around 0 mean:
00220         Vector::MulAssign(featureMeans,Impala::Real64(-1));
00221         for(i=0;i<H;i++){
00222             Vector::VectorTem<Real64> tmpVec = vs.GetVector(i,true);
00223             AddAssign(tmpVec,featureMeans);
00224         }
00225         Vector::MulAssign(featureMeans,Impala::Real64(-1));
00226 
00228         //Now The data is centered around origin
00229         //We should add a column with 1's to the end of the feature vectors
00230 
00231         //If the rank of this Centered matrix with the ones column is 
00232         //less than the initial number of features for each sample,
00233         //Then we should find the Pseudo Inverse of this B matrice, and multiply
00234         //it with a two column labels matrix
00235         CenteredFeatures = Array::ArrayCreate<Array::Array2dScalarReal64>(W+1,H);
00236         SetVal(CenteredFeatures,1);
00237         SetPart(CenteredFeatures,Features,0,0,W,H,0,0);
00238 
00239 
00240         Targets         = Matrix::MatCreate<Array::Array2dScalarReal64>(H,2);
00241         FeatureAverages = Matrix::MatCreate<Array::Array2dScalarReal64>(1,W);
00242 
00243         for(int i=0;i<W;i++){
00244             FeatureAverages->SetValue(featureMeans.Elem(i),i,0);
00245         }
00246 
00247         SetPart(Targets,Labels,0,0,1,H,0,0);
00248         for(int i=0;i<H;i++){
00249             Targets->SetValue(Targets->Value(0,i),1,i);
00250             Targets->SetValue(-Targets->Value(0,i),0,i);
00251         }
00252         CenteredFeatureInverse=Matrix::MatPInv(CenteredFeatures);
00253 
00254             
00255         tmp = Matrix::MatMul(CenteredFeatureInverse,Targets);
00256         tmp2 = Matrix::MatCreate<Array::Array2dScalarReal64>(W,2);
00257 
00258         for(int i=0;i<W;i++){
00259             tmp2->SetValue(tmp->Value(0,i),0,i);
00260             tmp2->SetValue(tmp->Value(1,i),1,i);
00261         }
00262         tmp3 = Matrix::MatMul(FeatureAverages,tmp2);
00263 
00264         mOffset = Matrix::MatCreate<Array::Array2dScalarReal64>(1,2);
00265         mOffset->SetValue(tmp->Value(0,W)-tmp3->Value(0,0),0,0);
00266         mOffset->SetValue(tmp->Value(1,W)-tmp3->Value(1,0),1,0);
00267 
00268         mRotation = Matrix::MatCreate<Array::Array2dScalarReal64>(W,2);
00269         SetPart(mRotation,tmp,0,0,2,W,0,0);
00270 
00271         delete tmp;
00272         delete tmp2;
00273         delete tmp3;
00274 
00275         delete Targets;
00276         delete Labels;
00277         //delete Features; //will be released by the vector set
00278         delete FeatureAverages;
00279         delete CenteredFeatures;;
00280         delete CenteredFeatureInverse;
00281         CNormC();
00282         
00283     }

Here is the call graph for this function:


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