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

Last change on this file since 779 was 779, checked in by Peter, 15 years ago

Refs #101

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1// $Id: DataLookupWeighted1D.cc 779 2007-03-05 18:58:30Z peter $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
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  double DataLookupWeighted1D::data(const size_t i) const
69  {
70    return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i);
71  }
72
73
74  size_t DataLookupWeighted1D::size(void) const
75  {
76    return column_vector_ ? matrix_->rows() : matrix_->columns();
77  }
78
79
80  double sum_weight(const DataLookupWeighted1D& x)
81  {
82    double r=0;
83    for (size_t i=0; i<x.size(); ++i)
84      r += x.weight(i);
85    return r;
86  }
87
88
89  double DataLookupWeighted1D::weight(const size_t i) const
90  {
91    return column_vector_? matrix_->weight(i,index_) : matrix_->weight(index_,i);
92  }
93
94
95  double DataLookupWeighted1D::operator()(const size_t i) const
96  {
97    return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i);
98  }
99
100
101  double DataLookupWeighted1D::operator[](const size_t i) const
102  {
103    return this->operator()(i);
104  }
105
106}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.