L2Distance.cpp

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

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