source: trunk/test/crossvalidation_test.cc @ 865

Last change on this file since 865 was 865, checked in by Peter, 16 years ago

changing URL to http://trac.thep.lu.se/trac/yat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1// $Id: crossvalidation_test.cc 865 2007-09-10 19:41:04Z peter $
2
3/*
4  Copyright (C) 2004, 2005 Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
6  Copyright (C) 2007 Peter Johansson
7
8  This file is part of the yat library, http://trac.thep.lu.se/trac/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "yat/classifier/CrossValidationSampler.h"
27#include "yat/classifier/MatrixLookup.h"
28#include "yat/classifier/Target.h"
29#include "yat/utility/matrix.h"
30
31#include <cassert>
32#include <cstdlib>
33#include <fstream>
34#include <iostream>
35#include <string>
36#include <vector>
37
38// forward declaration
39void class_count_test(const std::vector<size_t>&, std::ostream*, bool&);
40void sample_count_test(const std::vector<size_t>&, std::ostream*, bool&);
41
42
43int main(const int argc,const char* argv[])
44{ 
45  using namespace theplu::yat;
46 
47  std::ostream* error;
48  if (argc>1 && argv[1]==std::string("-v"))
49    error = &std::cerr;
50  else {
51    error = new std::ofstream("/dev/null");
52    if (argc>1)
53      std::cout << "crossvalidation_test -v : for printing extra information\n";
54  }
55  *error << "testing crosssplitter" << std::endl;
56  bool ok = true;
57
58  if (error!=&std::cerr)
59    delete error;
60 
61  if (ok)
62    return 0;
63  return -1;
64}
65
66
67void class_count_test(const std::vector<size_t>& class_count, 
68                      std::ostream* error, bool& ok) 
69{
70  for (size_t i=0; i<class_count.size(); i++)
71    if (class_count[i]==0){
72      ok = false;
73      *error << "ERROR: class " << i << " was not in set." 
74             << " Expected at least one sample from each class." 
75             << std::endl;
76    }
77}
78
79void sample_count_test(const std::vector<size_t>& sample_count, 
80                       std::ostream* error, bool& ok) 
81{
82  for (size_t i=0; i<sample_count.size(); i++){
83    if (sample_count[i]!=1){
84      ok = false;
85      *error << "ERROR: sample " << i << " was in a group " << sample_count[i] 
86             << " times." << " Expected to be 1 time" << std::endl;
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.