116 |
19 Jul 04 |
peter |
// $Id$ |
116 |
19 Jul 04 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2004, 2005 Peter Johansson |
2121 |
13 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
116 |
19 Jul 04 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
11 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
16 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
21 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
24 |
*/ |
675 |
10 Oct 06 |
jari |
25 |
|
2881 |
18 Nov 12 |
peter |
26 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
27 |
|
675 |
10 Oct 06 |
jari |
28 |
#include "yat/classifier/CrossValidationSampler.h" |
675 |
10 Oct 06 |
jari |
29 |
#include "yat/classifier/MatrixLookup.h" |
675 |
10 Oct 06 |
jari |
30 |
#include "yat/classifier/Target.h" |
675 |
10 Oct 06 |
jari |
31 |
#include "yat/utility/matrix.h" |
675 |
10 Oct 06 |
jari |
32 |
|
781 |
05 Mar 07 |
peter |
33 |
#include <cassert> |
116 |
19 Jul 04 |
peter |
34 |
#include <cstdlib> |
463 |
16 Dec 05 |
peter |
35 |
#include <fstream> |
116 |
19 Jul 04 |
peter |
36 |
#include <iostream> |
509 |
18 Feb 06 |
peter |
37 |
#include <string> |
463 |
16 Dec 05 |
peter |
38 |
#include <vector> |
116 |
19 Jul 04 |
peter |
39 |
|
551 |
07 Mar 06 |
markus |
// forward declaration |
551 |
07 Mar 06 |
markus |
41 |
void class_count_test(const std::vector<size_t>&, std::ostream*, bool&); |
551 |
07 Mar 06 |
markus |
42 |
void sample_count_test(const std::vector<size_t>&, std::ostream*, bool&); |
551 |
07 Mar 06 |
markus |
43 |
|
551 |
07 Mar 06 |
markus |
44 |
|
463 |
16 Dec 05 |
peter |
45 |
int main(const int argc,const char* argv[]) |
4200 |
19 Aug 22 |
peter |
46 |
{ |
680 |
11 Oct 06 |
jari |
47 |
using namespace theplu::yat; |
4200 |
19 Aug 22 |
peter |
48 |
|
463 |
16 Dec 05 |
peter |
49 |
std::ostream* error; |
463 |
16 Dec 05 |
peter |
50 |
if (argc>1 && argv[1]==std::string("-v")) |
463 |
16 Dec 05 |
peter |
51 |
error = &std::cerr; |
463 |
16 Dec 05 |
peter |
52 |
else { |
463 |
16 Dec 05 |
peter |
53 |
error = new std::ofstream("/dev/null"); |
463 |
16 Dec 05 |
peter |
54 |
if (argc>1) |
463 |
16 Dec 05 |
peter |
55 |
std::cout << "crossvalidation_test -v : for printing extra information\n"; |
463 |
16 Dec 05 |
peter |
56 |
} |
482 |
02 Jan 06 |
peter |
57 |
*error << "testing crosssplitter" << std::endl; |
463 |
16 Dec 05 |
peter |
58 |
bool ok = true; |
301 |
30 Apr 05 |
peter |
59 |
|
463 |
16 Dec 05 |
peter |
60 |
if (error!=&std::cerr) |
463 |
16 Dec 05 |
peter |
61 |
delete error; |
4200 |
19 Aug 22 |
peter |
62 |
|
482 |
02 Jan 06 |
peter |
63 |
if (ok) |
482 |
02 Jan 06 |
peter |
64 |
return 0; |
482 |
02 Jan 06 |
peter |
65 |
return -1; |
116 |
19 Jul 04 |
peter |
66 |
} |
551 |
07 Mar 06 |
markus |
67 |
|
551 |
07 Mar 06 |
markus |
68 |
|
4200 |
19 Aug 22 |
peter |
69 |
void class_count_test(const std::vector<size_t>& class_count, |
4200 |
19 Aug 22 |
peter |
70 |
std::ostream* error, bool& ok) |
551 |
07 Mar 06 |
markus |
71 |
{ |
551 |
07 Mar 06 |
markus |
72 |
for (size_t i=0; i<class_count.size(); i++) |
551 |
07 Mar 06 |
markus |
73 |
if (class_count[i]==0){ |
551 |
07 Mar 06 |
markus |
74 |
ok = false; |
4200 |
19 Aug 22 |
peter |
75 |
*error << "ERROR: class " << i << " was not in set." |
4200 |
19 Aug 22 |
peter |
76 |
<< " Expected at least one sample from each class." |
551 |
07 Mar 06 |
markus |
77 |
<< std::endl; |
551 |
07 Mar 06 |
markus |
78 |
} |
551 |
07 Mar 06 |
markus |
79 |
} |
551 |
07 Mar 06 |
markus |
80 |
|
4200 |
19 Aug 22 |
peter |
81 |
void sample_count_test(const std::vector<size_t>& sample_count, |
4200 |
19 Aug 22 |
peter |
82 |
std::ostream* error, bool& ok) |
551 |
07 Mar 06 |
markus |
83 |
{ |
551 |
07 Mar 06 |
markus |
84 |
for (size_t i=0; i<sample_count.size(); i++){ |
551 |
07 Mar 06 |
markus |
85 |
if (sample_count[i]!=1){ |
551 |
07 Mar 06 |
markus |
86 |
ok = false; |
4200 |
19 Aug 22 |
peter |
87 |
*error << "ERROR: sample " << i << " was in a group " << sample_count[i] |
551 |
07 Mar 06 |
markus |
88 |
<< " times." << " Expected to be 1 time" << std::endl; |
551 |
07 Mar 06 |
markus |
89 |
} |
551 |
07 Mar 06 |
markus |
90 |
} |
551 |
07 Mar 06 |
markus |
91 |
} |