source: trunk/se/lu/thep/wenni/bin/NNIFileConverter/NNIFileConverter.cc @ 95

Last change on this file since 95 was 95, checked in by Jari Häkkinen, 17 years ago

Added copyright statement to files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: NNIFileConverter.cc 95 2006-04-05 13:21:18Z jari $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen
5
6  This file is part of WeNNI,
7  http://lev.thep.lu.se/trac/baseplugins/wiki/WeNNI
8
9  WeNNI is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  WeNNI is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17  License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "Parameter.h"
26#include "weight.h"
27
28#include <cmath>
29#include <fstream>
30
31#include <c++_tools/gslapi/matrix.h>
32
33
34int main(const int argc,const char* argv[]) 
35{
36  theplu::wenni::nnifileconverter::Parameter option(argc,argv);
37  std::ifstream is(option.fg1().c_str());
38  theplu::gslapi::matrix fg1(is);
39  is.close();
40  is.open(option.bgstd1().c_str());
41  theplu::gslapi::matrix bgstd1(is);
42  is.close();
43  is.open(option.fg2().c_str());
44  theplu::gslapi::matrix fg2(is);
45  is.close();
46  is.open(option.bgstd2().c_str());
47  theplu::gslapi::matrix bgstd2(is);
48  is.close();
49
50  theplu::gslapi::matrix bg1;
51  theplu::gslapi::matrix bg2;
52  if (option.datatype()==std::string("raw")) {
53    is.open(option.bg1().c_str());
54    bg1=theplu::gslapi::matrix(is);
55    is.close();
56    is.open(option.bg2().c_str());
57    bg2=theplu::gslapi::matrix(is);
58    is.close();
59  }
60  else
61    bg1=bg2=theplu::gslapi::matrix(fg1.rows(),fg1.columns(),0.0);
62
63  // Calculating log2ratio
64  theplu::gslapi::matrix log2ratio(fg1.rows(),fg1.columns(),0.0);
65  double log2=log(2);
66  for (size_t i=0; i<log2ratio.rows(); i++) 
67    for (size_t j=0; j<log2ratio.columns(); j++)
68      if (fg1(i,j)>bg1(i,j) && fg2(i,j)>bg2(i,j))
69        log2ratio(i,j)=log( (fg1(i,j)-bg1(i,j)) / (fg2(i,j)-bg2(i,j)) ) / log2;
70
71  // calculating weights
72  theplu::gslapi::matrix weight(fg1.rows(),fg1.columns());
73  for (size_t i=0; i<weight.rows(); i++)
74    for (size_t j=0; j<weight.columns(); j++) {
75      using namespace theplu::wenni::weight;
76      weight(i,j)=weight_SNR2(get_snr(fg1(i,j),bg1(i,j),bgstd1(i,j)),
77                              get_snr(fg2(i,j),bg2(i,j),bgstd2(i,j)),
78                              option.beta());
79    }
80
81  std::ofstream os(option.logratio().c_str());
82  os << log2ratio;
83  os.close();
84  os.open(option.weight().c_str());
85  os << weight;
86  os.close();
87
88  return 0;
89}
Note: See TracBrowser for help on using the repository browser.