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

Last change on this file since 1580 was 1552, checked in by Peter, 13 years ago

using DataWeight? rather than std::pair<double, double>

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