source: trunk/test/ttest_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 Id
File size: 1.9 KB
Line 
1// $Id: ttest_test.cc 865 2007-09-10 19:41:04Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of the yat library, http://trac.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "yat/classifier/Target.h"
25#include "yat/statistics/tTest.h"
26#include "yat/statistics/utility.h"
27#include "yat/utility/vector.h"
28
29#include <cmath>
30#include <fstream>
31#include <iostream>
32
33
34using namespace theplu::yat;
35
36int main(const int argc,const char* argv[])
37{ 
38  std::ostream* error;
39  if (argc>1 && argv[1]==std::string("-v"))
40    error = &std::cerr;
41  else {
42    error = new std::ofstream("/dev/null");
43    if (argc>1)
44      std::cout << "ttest_test -v : for printing extra information\n";
45  }
46  bool ok = true;
47
48  *error << "testing ttest" << std::endl;
49  utility::vector value(31);
50  std::vector<std::string> label(31,"positive");
51  for (size_t i=0; i<16; i++) 
52    label[i] = "negative";
53  classifier::Target target(label);
54  target.set_binary(0,false);
55  target.set_binary(1,true);
56  for (size_t i=0; i<value.size(); i++) 
57    value(i)=i;
58  statistics::tTest test;
59  statistics::add(test, value, target);
60  double p = test.p_value_one_sided();
61  double p2 = test.p_value();
62  if (p2 != 2*p) {
63    ok = false;
64    *error << "Two-sided P-value should equal 2 * one-sided P-value.\n";
65  }
66
67  if (ok)
68    return 0;
69  return -1;
70}
Note: See TracBrowser for help on using the repository browser.