622 |
05 Sep 06 |
peter |
// $Id$ |
622 |
05 Sep 06 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson, Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
622 |
05 Sep 06 |
peter |
8 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
10 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
15 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
20 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
23 |
*/ |
675 |
10 Oct 06 |
jari |
24 |
|
2881 |
18 Nov 12 |
peter |
25 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
26 |
|
680 |
11 Oct 06 |
jari |
27 |
#include "DataLookupWeighted1D.h" |
680 |
11 Oct 06 |
jari |
28 |
#include "MatrixLookupWeighted.h" |
675 |
10 Oct 06 |
jari |
29 |
|
622 |
05 Sep 06 |
peter |
30 |
#include <cassert> |
622 |
05 Sep 06 |
peter |
31 |
#include <iostream> |
622 |
05 Sep 06 |
peter |
32 |
#include <iomanip> |
622 |
05 Sep 06 |
peter |
33 |
|
622 |
05 Sep 06 |
peter |
34 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
35 |
namespace yat { |
622 |
05 Sep 06 |
peter |
36 |
namespace classifier { |
622 |
05 Sep 06 |
peter |
37 |
|
4200 |
19 Aug 22 |
peter |
38 |
DataLookupWeighted1D::DataLookupWeighted1D(const MatrixLookupWeighted& m, |
4200 |
19 Aug 22 |
peter |
39 |
const size_t i, |
622 |
05 Sep 06 |
peter |
40 |
const bool row_vector) |
622 |
05 Sep 06 |
peter |
41 |
: column_vector_(!row_vector), index_(i), matrix_(&m), owner_(false) |
622 |
05 Sep 06 |
peter |
42 |
{ |
622 |
05 Sep 06 |
peter |
43 |
assert( !column_vector_ || i<m.columns()); |
622 |
05 Sep 06 |
peter |
44 |
assert( column_vector_ || i<m.rows()); |
622 |
05 Sep 06 |
peter |
45 |
} |
622 |
05 Sep 06 |
peter |
46 |
|
4200 |
19 Aug 22 |
peter |
47 |
|
4200 |
19 Aug 22 |
peter |
48 |
DataLookupWeighted1D::DataLookupWeighted1D(const size_t size, |
622 |
05 Sep 06 |
peter |
49 |
const double value, |
622 |
05 Sep 06 |
peter |
50 |
const double weight) |
622 |
05 Sep 06 |
peter |
51 |
: column_vector_(false), index_(0), owner_(true) |
622 |
05 Sep 06 |
peter |
52 |
{ |
622 |
05 Sep 06 |
peter |
53 |
matrix_ = new MatrixLookupWeighted(1,size,value,weight); |
622 |
05 Sep 06 |
peter |
54 |
} |
622 |
05 Sep 06 |
peter |
55 |
|
4200 |
19 Aug 22 |
peter |
56 |
|
622 |
05 Sep 06 |
peter |
57 |
DataLookupWeighted1D::DataLookupWeighted1D(const DataLookupWeighted1D& other) |
622 |
05 Sep 06 |
peter |
58 |
: column_vector_(other.column_vector_), index_(other.index_), |
622 |
05 Sep 06 |
peter |
59 |
matrix_(other.matrix_), owner_(false) |
622 |
05 Sep 06 |
peter |
60 |
{ |
622 |
05 Sep 06 |
peter |
61 |
} |
622 |
05 Sep 06 |
peter |
62 |
|
720 |
26 Dec 06 |
jari |
63 |
|
622 |
05 Sep 06 |
peter |
64 |
DataLookupWeighted1D::~DataLookupWeighted1D() |
622 |
05 Sep 06 |
peter |
65 |
{ |
622 |
05 Sep 06 |
peter |
66 |
if (owner_) |
622 |
05 Sep 06 |
peter |
67 |
delete matrix_; |
622 |
05 Sep 06 |
peter |
68 |
} |
622 |
05 Sep 06 |
peter |
69 |
|
622 |
05 Sep 06 |
peter |
70 |
|
890 |
25 Sep 07 |
markus |
71 |
DataLookupWeighted1D::const_iterator DataLookupWeighted1D::begin(void) const |
890 |
25 Sep 07 |
markus |
72 |
{ |
1088 |
14 Feb 08 |
peter |
73 |
if (column_vector_) |
1526 |
24 Sep 08 |
peter |
74 |
return matrix_->begin_column(index_); |
1526 |
24 Sep 08 |
peter |
75 |
return matrix_->begin_row(index_); |
890 |
25 Sep 07 |
markus |
76 |
} |
890 |
25 Sep 07 |
markus |
77 |
|
890 |
25 Sep 07 |
markus |
78 |
|
720 |
26 Dec 06 |
jari |
79 |
double DataLookupWeighted1D::data(const size_t i) const |
720 |
26 Dec 06 |
jari |
80 |
{ |
720 |
26 Dec 06 |
jari |
81 |
return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i); |
720 |
26 Dec 06 |
jari |
82 |
} |
720 |
26 Dec 06 |
jari |
83 |
|
720 |
26 Dec 06 |
jari |
84 |
|
890 |
25 Sep 07 |
markus |
85 |
DataLookupWeighted1D::const_iterator DataLookupWeighted1D::end(void) const |
890 |
25 Sep 07 |
markus |
86 |
{ |
1088 |
14 Feb 08 |
peter |
87 |
if (column_vector_) |
1526 |
24 Sep 08 |
peter |
88 |
return matrix_->end_column(index_); |
1526 |
24 Sep 08 |
peter |
89 |
return matrix_->end_row(index_); |
890 |
25 Sep 07 |
markus |
90 |
} |
890 |
25 Sep 07 |
markus |
91 |
|
890 |
25 Sep 07 |
markus |
92 |
|
890 |
25 Sep 07 |
markus |
93 |
|
720 |
26 Dec 06 |
jari |
94 |
size_t DataLookupWeighted1D::size(void) const |
720 |
26 Dec 06 |
jari |
95 |
{ |
720 |
26 Dec 06 |
jari |
96 |
return column_vector_ ? matrix_->rows() : matrix_->columns(); |
720 |
26 Dec 06 |
jari |
97 |
} |
720 |
26 Dec 06 |
jari |
98 |
|
720 |
26 Dec 06 |
jari |
99 |
|
779 |
05 Mar 07 |
peter |
100 |
double sum_weight(const DataLookupWeighted1D& x) |
779 |
05 Mar 07 |
peter |
101 |
{ |
779 |
05 Mar 07 |
peter |
102 |
double r=0; |
779 |
05 Mar 07 |
peter |
103 |
for (size_t i=0; i<x.size(); ++i) |
779 |
05 Mar 07 |
peter |
104 |
r += x.weight(i); |
779 |
05 Mar 07 |
peter |
105 |
return r; |
779 |
05 Mar 07 |
peter |
106 |
} |
779 |
05 Mar 07 |
peter |
107 |
|
779 |
05 Mar 07 |
peter |
108 |
|
720 |
26 Dec 06 |
jari |
109 |
double DataLookupWeighted1D::weight(const size_t i) const |
720 |
26 Dec 06 |
jari |
110 |
{ |
720 |
26 Dec 06 |
jari |
111 |
return column_vector_? matrix_->weight(i,index_) : matrix_->weight(index_,i); |
720 |
26 Dec 06 |
jari |
112 |
} |
720 |
26 Dec 06 |
jari |
113 |
|
720 |
26 Dec 06 |
jari |
114 |
|
1552 |
06 Oct 08 |
peter |
115 |
DataLookupWeighted1D::const_reference |
1552 |
06 Oct 08 |
peter |
116 |
DataLookupWeighted1D::operator()(const size_t i) const |
720 |
26 Dec 06 |
jari |
117 |
{ |
720 |
26 Dec 06 |
jari |
118 |
return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); |
720 |
26 Dec 06 |
jari |
119 |
} |
720 |
26 Dec 06 |
jari |
120 |
|
720 |
26 Dec 06 |
jari |
121 |
|
680 |
11 Oct 06 |
jari |
122 |
}}} // of namespace classifier, yat, and theplu |