source: branches/0.4-stable/test/crossvalidation_test.cc @ 1743

Last change on this file since 1743 was 1743, checked in by Peter, 12 years ago

updating copyright statements

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