source: trunk/test/vector_distance_test.cc @ 889

Last change on this file since 889 was 889, checked in by Markus Ringnér, 16 years ago

Refs #245. A new structure to calculate distances between vectors that is based on iterators and traits patterns. Will replace the old inherited Distance structure. Support for iterators to weighted containers is not yet added

File size: 1.2 KB
Line 
1// $Id$
2
3#include "yat/statistics/euclidean_vector_distance.h"
4#include "yat/statistics/pearson_vector_distance.h"
5#include "yat/utility/vector.h"
6
7#include <cassert>
8#include <fstream>
9#include <iostream>
10
11
12using namespace theplu::yat;
13
14int main(const int argc,const char* argv[])
15
16{ 
17  std::ostream* error;
18  if (argc>1 && argv[1]==std::string("-v"))
19    error = &std::cerr;
20  else {
21    error = new std::ofstream("/dev/null");
22    if (argc>1)
23      std::cout << "vector_distance_test -v : for printing extra information\n";
24  }
25  *error << "testing distance" << std::endl;
26  bool ok = true;
27
28  utility::vector a(3,1);
29  a(1) = 2;
30  utility::vector b(3,0);
31  b(2) = 1;
32
33  *error << "testing Euclidean vector_distance" << std::endl;
34  double dist=statistics::vector_distance(a.begin(),a.end(),b.begin(),
35                                          statistics::euclidean_vector_distance_tag());
36
37  *error << "Dist: " << dist << std::endl;
38
39
40  *error << "testing Pearson vector_distance" << std::endl;
41  dist=statistics::vector_distance(a.begin(),a.end(),b.begin(),
42                                          statistics::pearson_vector_distance_tag()); 
43  *error << "Dist: " << dist << std::endl;
44
45
46  if (error!=&std::cerr)
47    delete error;
48
49  if (ok=true) 
50    return 0;
51  return -1;
52}
53
54
55
Note: See TracBrowser for help on using the repository browser.