#include <L2Distance.h>
Inheritance diagram for damina::L2Distance:


Public Member Functions | |
| virtual double | calculateDistance (struct svm_node *, struct svm_node *) |
| Computes the L2 Distance between two points (poits are in libsvm format). | |
| L2Distance () | |
| Constructor. | |
| virtual | ~L2Distance () |
| Destructor. | |
Definition at line 13 of file L2Distance.h.
| damina::L2Distance::L2Distance | ( | ) |
| damina::L2Distance::~L2Distance | ( | ) | [virtual] |
| double damina::L2Distance::calculateDistance | ( | struct svm_node * | x, | |
| struct svm_node * | y | |||
| ) | [virtual] |
Computes the L2 Distance between two points (poits are in libsvm format).
| px | The first point | |
| py | The second point |
Implements damina::EuclideanDistance.
Definition at line 26 of file L2Distance.cpp.
00026 { 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 }
1.5.2