L1Distance.cpp

Go to the documentation of this file.
00001 #include "L1Distance.h"
00002 
00003 namespace damina
00004 {
00008         L1Distance::L1Distance() {
00009                 
00010         }
00011 
00015         L1Distance::~L1Distance() {
00016         
00017         }
00018 
00026         double L1Distance::calculateDistance(struct svm_node *px, struct svm_node *py) {
00027                         double sum = 0;
00028                         while(px->index != -1 && py->index != -1)
00029                         {
00030                                 if(px->index == py->index)
00031                                 {
00032                                         sum += fabs(px->value - py->value);
00033                                         ++px;
00034                                         ++py;
00035                                 }
00036                                 else
00037                                 {
00038                                         if(px->index > py->index)
00039                                         {
00040                                                 sum += fabs(py->value);
00041                                                 ++py;
00042                                         }
00043                                         else
00044                                         {
00045                                                 sum += fabs(px->value);
00046                                                 ++px;
00047                                         }
00048                                 }
00049                         
00050                         }
00051                         while(px->index != -1)
00052                         {
00053                                 sum += fabs(px->value);
00054                                 ++px;
00055                         }
00056                         while (py->index != -1)
00057                         {
00058                                 sum += fabs (py->value);
00059                                 ++py;
00060                         }
00061                         return sum;
00062         }
00063 
00064 }

Generated on Mon Sep 24 22:26:48 2007 for SVClustering by  doxygen 1.5.2