source: trunk/test/nbc_test.cc @ 1121

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

fixes #308

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: nbc_test.cc 1121 2008-02-22 15:29:56Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of the yat library, http://trac.thep.lu.se/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/MatrixLookup.h"
25#include "yat/classifier/MatrixLookupWeighted.h"
26#include "yat/classifier/NBC.h"
27#include "yat/classifier/Target.h"
28#include "yat/utility/Matrix.h"
29
30#include <cassert>
31#include <fstream>
32#include <iostream>
33#include <string>
34
35using namespace theplu::yat;
36
37int main(const int argc,const char* argv[])
38{ 
39
40  std::ostream* error;
41  if (argc>1 && argv[1]==std::string("-v"))
42    error = &std::cerr;
43  else {
44    error = new std::ofstream("/dev/null");
45    if (argc>1)
46      *error << "nbc_test -v : for printing extra information\n";
47  }
48  *error << "testing ncc" << std::endl;
49  bool ok = true;
50
51  std::ifstream is("data/nm_data_centralized.txt");
52  utility::Matrix data_core(is);
53  is.close();
54  classifier::MatrixLookup data(data_core);
55
56  is.open("data/nm_target_bin.txt");
57  classifier::Target target(is);
58  is.close();
59
60  *error << "Constructing NBC" << std::endl;
61  classifier::NBC nbc(data,target);
62  *error << "Training NBC" << std::endl;
63  nbc.train();
64  utility::Matrix res;
65  *error << "Predicting" << std::endl;
66  nbc.predict(data, res);
67
68
69  if(ok)
70    *error << "OK" << std::endl;
71  else
72    *error << "test failed" << std::endl;
73
74  if (error!=&std::cerr)
75    delete error;
76
77  if(ok) 
78    return 0;
79  return -1;
80 
81}
Note: See TracBrowser for help on using the repository browser.