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, Peter Johansson |
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 |
#ifndef _thep_lu_se_wenni_weight_ |
69 |
11 Feb 06 |
jari |
24 |
#define _thep_lu_se_wenni_weight_ |
69 |
11 Feb 06 |
jari |
25 |
|
69 |
11 Feb 06 |
jari |
26 |
#include <c++_tools/gslapi/matrix.h> |
69 |
11 Feb 06 |
jari |
27 |
|
69 |
11 Feb 06 |
jari |
28 |
namespace theplu { |
69 |
11 Feb 06 |
jari |
29 |
namespace wenni { |
69 |
11 Feb 06 |
jari |
30 |
namespace weight { |
69 |
11 Feb 06 |
jari |
31 |
|
69 |
11 Feb 06 |
jari |
32 |
/// |
69 |
11 Feb 06 |
jari |
/// The snr is defined using the foreground, background, and |
69 |
11 Feb 06 |
jari |
/// standard deviation of the background as \f$ (fg-bg)/bgstd \f$ if |
69 |
11 Feb 06 |
jari |
/// \a fg is larger than \a bg, 0 otherwise. |
69 |
11 Feb 06 |
jari |
36 |
/// |
69 |
11 Feb 06 |
jari |
37 |
inline double get_snr(const double fg, const double bg, const double bgstd) |
69 |
11 Feb 06 |
jari |
38 |
{ return ((fg>bg) ? (fg-bg)/bgstd : 0.0); } |
69 |
11 Feb 06 |
jari |
39 |
|
69 |
11 Feb 06 |
jari |
40 |
/// |
73 |
14 Feb 06 |
jari |
/// @return A non-zero weight if \a snr is a non-zero positive |
73 |
14 Feb 06 |
jari |
/// number, zero otherwise. |
69 |
11 Feb 06 |
jari |
43 |
/// |
73 |
14 Feb 06 |
jari |
44 |
inline const double weight_SNR(const double snr, const double beta=0.6) |
74 |
15 Feb 06 |
jari |
45 |
{ return (snr>0) ? 1.0/(1.0+beta*beta/snr/snr) : 0.0;} |
69 |
11 Feb 06 |
jari |
46 |
|
69 |
11 Feb 06 |
jari |
47 |
/// |
73 |
14 Feb 06 |
jari |
/// @return The weight matrix from a \a snr matrix. Indivividual |
73 |
14 Feb 06 |
jari |
/// weight elements are computed with function weight_SNR(const |
73 |
14 Feb 06 |
jari |
/// double snr, const double beta=0.6). |
69 |
11 Feb 06 |
jari |
51 |
/// |
69 |
11 Feb 06 |
jari |
52 |
inline gslapi::matrix weight_SNR(const theplu::gslapi::matrix& snr, |
73 |
14 Feb 06 |
jari |
53 |
const double beta=0.6) |
69 |
11 Feb 06 |
jari |
54 |
{ |
69 |
11 Feb 06 |
jari |
55 |
gslapi::matrix w(snr.rows(), snr.columns()); |
69 |
11 Feb 06 |
jari |
56 |
for (size_t i=0; i<w.rows(); i++) |
69 |
11 Feb 06 |
jari |
57 |
for (size_t j=0; j<w.columns(); j++) |
73 |
14 Feb 06 |
jari |
58 |
w(i,j)=weight_SNR(snr(i,j),beta); |
69 |
11 Feb 06 |
jari |
59 |
return w; |
69 |
11 Feb 06 |
jari |
60 |
} |
69 |
11 Feb 06 |
jari |
61 |
|
69 |
11 Feb 06 |
jari |
62 |
/// |
73 |
14 Feb 06 |
jari |
/// @return A non-zero weight if \a snr1 and \a snr2 are both |
73 |
14 Feb 06 |
jari |
/// non-zero positive numbers, zero otherwise. |
69 |
11 Feb 06 |
jari |
65 |
/// |
69 |
11 Feb 06 |
jari |
66 |
inline double weight_SNR2(const double snr1, const double snr2, |
73 |
14 Feb 06 |
jari |
67 |
const double beta=0.6) |
73 |
14 Feb 06 |
jari |
68 |
{ return (((snr1>0) && (snr2>0)) ? |
73 |
14 Feb 06 |
jari |
69 |
1.0/(1+beta*beta/snr1/snr1+beta*beta/snr2/snr2) : 0.0); } |
69 |
11 Feb 06 |
jari |
70 |
|
69 |
11 Feb 06 |
jari |
71 |
}}} // of namespace weight, wenni, and theplu |
69 |
11 Feb 06 |
jari |
72 |
|
69 |
11 Feb 06 |
jari |
73 |
#endif |
69 |
11 Feb 06 |
jari |
74 |
|