source: trunk/yat/classifier/DataLookupWeighted1D.cc @ 890

Last change on this file since 890 was 890, checked in by Markus Ringnér, 14 years ago

Refs #245 #246 #247

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