source: trunk/yat/classifier/DataLookupWeighted1D.cc

Last change on this file was 2919, checked in by Peter, 9 years ago

update copyright years

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