source: trunk/test/nbc_test.cc @ 813

Last change on this file since 813 was 813, checked in by Peter, 16 years ago

Predict in NBC. Fixes #57

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: nbc_test.cc 813 2007-03-16 19:30:02Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of the yat library, http://lev.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/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.