69 |
11 Feb 06 |
jari |
// $Id$ |
69 |
11 Feb 06 |
jari |
2 |
|
95 |
05 Apr 06 |
jari |
3 |
/* |
95 |
05 Apr 06 |
jari |
Copyright (C) 2005, 2006 Jari Häkkinen |
95 |
05 Apr 06 |
jari |
5 |
|
95 |
05 Apr 06 |
jari |
This file is part of WeNNI, |
825 |
26 Nov 08 |
jari |
http://baseplugins.thep.lu.se/wiki/se.lu.thep.WeNNI |
95 |
05 Apr 06 |
jari |
8 |
|
95 |
05 Apr 06 |
jari |
WeNNI is free software; you can redistribute it and/or modify it |
95 |
05 Apr 06 |
jari |
under the terms of the GNU General Public License as published by |
824 |
26 Nov 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
95 |
05 Apr 06 |
jari |
(at your option) any later version. |
95 |
05 Apr 06 |
jari |
13 |
|
95 |
05 Apr 06 |
jari |
WeNNI is distributed in the hope that it will be useful, but WITHOUT |
95 |
05 Apr 06 |
jari |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
95 |
05 Apr 06 |
jari |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
95 |
05 Apr 06 |
jari |
License for more details. |
95 |
05 Apr 06 |
jari |
18 |
|
95 |
05 Apr 06 |
jari |
You should have received a copy of the GNU General Public License |
824 |
26 Nov 08 |
jari |
along with WeNNI. If not, see <http://www.gnu.org/licenses/>. |
95 |
05 Apr 06 |
jari |
21 |
*/ |
95 |
05 Apr 06 |
jari |
22 |
|
69 |
11 Feb 06 |
jari |
23 |
#include "nni.h" |
69 |
11 Feb 06 |
jari |
24 |
|
69 |
11 Feb 06 |
jari |
25 |
#include <iostream> |
69 |
11 Feb 06 |
jari |
26 |
#include <fstream> |
69 |
11 Feb 06 |
jari |
27 |
|
69 |
11 Feb 06 |
jari |
28 |
#include <c++_tools/utility/kNNI.h> |
69 |
11 Feb 06 |
jari |
29 |
#include <c++_tools/utility/WeNNI.h> |
69 |
11 Feb 06 |
jari |
30 |
|
69 |
11 Feb 06 |
jari |
31 |
#include "Parameter.h" |
69 |
11 Feb 06 |
jari |
32 |
#include "weight.h" |
69 |
11 Feb 06 |
jari |
33 |
|
69 |
11 Feb 06 |
jari |
34 |
void make_weights_binary(theplu::gslapi::matrix& weight,double cutoff); |
69 |
11 Feb 06 |
jari |
35 |
|
69 |
11 Feb 06 |
jari |
36 |
int main(const int argc,const char* argv[]) |
69 |
11 Feb 06 |
jari |
37 |
{ |
69 |
11 Feb 06 |
jari |
38 |
using namespace theplu; |
69 |
11 Feb 06 |
jari |
39 |
wenni::Parameter option(argc,argv); |
69 |
11 Feb 06 |
jari |
40 |
|
69 |
11 Feb 06 |
jari |
41 |
std::ifstream data_stream(option.data_file().c_str()); |
69 |
11 Feb 06 |
jari |
42 |
std::ifstream weight_stream(option.weight_file().c_str()); |
69 |
11 Feb 06 |
jari |
43 |
gslapi::matrix data(data_stream); |
69 |
11 Feb 06 |
jari |
44 |
gslapi::matrix weight(weight_stream); |
69 |
11 Feb 06 |
jari |
45 |
data_stream.close(); |
69 |
11 Feb 06 |
jari |
46 |
weight_stream.close(); |
69 |
11 Feb 06 |
jari |
47 |
|
69 |
11 Feb 06 |
jari |
48 |
if (option.weight_is_snr()) |
69 |
11 Feb 06 |
jari |
49 |
weight=wenni::weight::weight_SNR(weight,option.beta()); |
69 |
11 Feb 06 |
jari |
50 |
|
69 |
11 Feb 06 |
jari |
51 |
utility::NNI* nni=NULL; |
69 |
11 Feb 06 |
jari |
52 |
switch (option.nni_algorithm()) { |
69 |
11 Feb 06 |
jari |
53 |
case wenni::kNNI: |
69 |
11 Feb 06 |
jari |
54 |
make_weights_binary(weight,option.weight_cutoff()); |
69 |
11 Feb 06 |
jari |
55 |
nni=new utility::kNNI(data,weight,option.neighbours()); |
69 |
11 Feb 06 |
jari |
56 |
break; |
69 |
11 Feb 06 |
jari |
57 |
case wenni::WeNNI: |
69 |
11 Feb 06 |
jari |
58 |
nni=new utility::WeNNI(data,weight,option.neighbours()); |
69 |
11 Feb 06 |
jari |
59 |
break; |
69 |
11 Feb 06 |
jari |
60 |
} |
69 |
11 Feb 06 |
jari |
61 |
nni->estimate(); |
69 |
11 Feb 06 |
jari |
62 |
std::cout << nni->imputed_data() << '\n'; |
69 |
11 Feb 06 |
jari |
63 |
|
69 |
11 Feb 06 |
jari |
64 |
delete nni; |
69 |
11 Feb 06 |
jari |
65 |
|
69 |
11 Feb 06 |
jari |
66 |
exit(0); // normal exit |
69 |
11 Feb 06 |
jari |
67 |
} |
69 |
11 Feb 06 |
jari |
68 |
|
69 |
11 Feb 06 |
jari |
69 |
void make_weights_binary(theplu::gslapi::matrix& weight,double cutoff) |
69 |
11 Feb 06 |
jari |
70 |
{ |
69 |
11 Feb 06 |
jari |
71 |
for (size_t i=0; i<weight.rows(); ++i) |
69 |
11 Feb 06 |
jari |
72 |
for (size_t j=0; j<weight.columns(); ++j) |
69 |
11 Feb 06 |
jari |
73 |
weight(i,j)=(weight(i,j)>cutoff ? 1 : 0); |
69 |
11 Feb 06 |
jari |
74 |
} |