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

Equals.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Training_Equals_h
00002 #define Impala_Core_Training_Equals_h
00003 
00004 #include "Link/Svm/LinkSvm.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Training
00011 {
00012 
00015 const double cPrecision = 0.000001;
00016 
00020 bool Equals(const svm_parameter* p1, const svm_parameter* p2)
00021 {
00022     if(p1->svm_type != p2->svm_type)
00023         return false;
00024     if(p1->kernel_type != p2->kernel_type)
00025         return false;
00026     if(abs(p1->C - p2->C) > cPrecision)
00027         return false;
00028     if(abs(p1->gamma - p2->gamma) > cPrecision)
00029         return false;
00030     if(p1->probability != p2->probability)
00031         return false;
00032     if(p1->nr_weight != p2->nr_weight)
00033         return false;
00034     for(int i=0 ; i<p1->nr_weight ; ++i)
00035     {
00036         if(p1->weight_label[i] != p2->weight_label[i])
00037             return false;
00038         if(p1->weight[i] != p2->weight[i])
00039             return false;
00040     }
00041     return true;
00042 }
00043 
00044 bool EqualsForModel(const svm_parameter* p1, const svm_parameter* p2)
00045 {
00046     if(p1->svm_type != p2->svm_type)
00047         return false;
00048     if(p1->kernel_type != p2->kernel_type)
00049         return false;
00050     if(abs(p1->gamma - p2->gamma) > cPrecision)
00051         return false;
00052     return true;
00053 }
00054 
00055 bool Equals(const svm_node* sv1, const svm_node* sv2)
00056 {
00057     for(int j=0 ; sv1[j].index != -1 && sv2[j].index != -1 ; ++j)
00058     {
00059         if(sv1[j].index != sv2[j].index)
00060             return false;
00061         if(abs(sv1[j].value - sv2[j].value) > cPrecision)
00062             return false;
00063     }
00064     return true;
00065 }
00066 
00067 bool Equals(const svm_problem* p1, const svm_problem* p2)
00068 {
00069     if(p1->l != p2->l)
00070         return false;
00071     for(int i=0 ; i<p1->l ; ++i)
00072     {
00073         if(p1->y[i] != p2->y[i])
00074             return false;
00075         if(!Equals(p1->x[i], p2->x[i]))
00076             return false;
00077     }
00078     return true;
00079 }
00080 
00081 bool Equals(const svm_model* m1, const svm_model* m2)
00082 {
00083     if(!EqualsForModel(&m1->param, &m2->param))
00084         return false;
00085     if(m1->nr_class != m2->nr_class)
00086         return false;
00087     for(int i=0 ; i<m1->nr_class ; ++i)
00088     {
00089         if(m1->label[i] != m2->label[i])
00090             return false;
00091     }
00092     if(m1->l != m2->l)
00093         return false;
00094     for(int i=0 ; i<m1->l ; ++i)
00095     {
00096         if(!Equals(m1->SV[i], m2->SV[i]))
00097             return false;
00098     }
00099     return true;
00100 }
00101 
00102 }//namespace
00103 }//namespace
00104 }//namespace
00105 
00106 #endif Impala_Core_Training_Equals_h

Generated on Fri Mar 19 09:30:46 2010 for ImpalaSrc by  doxygen 1.5.1