source: trunk/test/crossvalidation_test.cc @ 2119

Last change on this file since 2119 was 2119, checked in by Peter, 14 years ago

converted files to utf-8. fixes #577

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1// $Id: crossvalidation_test.cc 2119 2009-12-12 23:11:43Z peter $
2
3/*
4  Copyright (C) 2004, 2005 Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
6  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "yat/classifier/CrossValidationSampler.h"
25#include "yat/classifier/MatrixLookup.h"
26#include "yat/classifier/Target.h"
27#include "yat/utility/matrix.h"
28
29#include <cassert>
30#include <cstdlib>
31#include <fstream>
32#include <iostream>
33#include <string>
34#include <vector>
35
36// forward declaration
37void class_count_test(const std::vector<size_t>&, std::ostream*, bool&);
38void sample_count_test(const std::vector<size_t>&, std::ostream*, bool&);
39
40
41int main(const int argc,const char* argv[])
42{ 
43  using namespace theplu::yat;
44 
45  std::ostream* error;
46  if (argc>1 && argv[1]==std::string("-v"))
47    error = &std::cerr;
48  else {
49    error = new std::ofstream("/dev/null");
50    if (argc>1)
51      std::cout << "crossvalidation_test -v : for printing extra information\n";
52  }
53  *error << "testing crosssplitter" << std::endl;
54  bool ok = true;
55
56  if (error!=&std::cerr)
57    delete error;
58 
59  if (ok)
60    return 0;
61  return -1;
62}
63
64
65void class_count_test(const std::vector<size_t>& class_count, 
66                      std::ostream* error, bool& ok) 
67{
68  for (size_t i=0; i<class_count.size(); i++)
69    if (class_count[i]==0){
70      ok = false;
71      *error << "ERROR: class " << i << " was not in set." 
72             << " Expected at least one sample from each class." 
73             << std::endl;
74    }
75}
76
77void sample_count_test(const std::vector<size_t>& sample_count, 
78                       std::ostream* error, bool& ok) 
79{
80  for (size_t i=0; i<sample_count.size(); i++){
81    if (sample_count[i]!=1){
82      ok = false;
83      *error << "ERROR: sample " << i << " was in a group " << sample_count[i] 
84             << " times." << " Expected to be 1 time" << std::endl;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.