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

Last change on this file since 831 was 831, checked in by Peter, 14 years ago

Refs #185.

  • 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 831 2007-03-27 13:22:09Z peter $
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://lev.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  double DataLookupWeighted1D::data(const size_t i) const
70  {
71    return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i);
72  }
73
74
75  size_t DataLookupWeighted1D::size(void) const
76  {
77    return column_vector_ ? matrix_->rows() : matrix_->columns();
78  }
79
80
81  double sum_weight(const DataLookupWeighted1D& x)
82  {
83    double r=0;
84    for (size_t i=0; i<x.size(); ++i)
85      r += x.weight(i);
86    return r;
87  }
88
89
90  double DataLookupWeighted1D::weight(const size_t i) const
91  {
92    return column_vector_? matrix_->weight(i,index_) : matrix_->weight(index_,i);
93  }
94
95
96  double DataLookupWeighted1D::operator()(const size_t i) const
97  {
98    return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i);
99  }
100
101
102  double DataLookupWeighted1D::operator[](const size_t i) const
103  {
104    return this->operator()(i);
105  }
106
107}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.