source: trunk/yat/classifier/Kernel_SEV.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
File size: 2.6 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2012 Peter Johansson
6
7  This file is part of the yat library, http://dev.thep.lu.se/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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include <config.h>
24
25#include "Kernel_SEV.h"
26#include "DataLookup1D.h"
27#include "DataLookupWeighted1D.h"
28#include "Kernel.h"
29#include "KernelFunction.h"
30#include "MatrixLookup.h"
31#include "yat/utility/Matrix.h"
32
33namespace theplu {
34namespace yat {
35namespace classifier { 
36
37
38  Kernel_SEV::Kernel_SEV(const MatrixLookup& data, const KernelFunction& kf,
39                         const bool own)
40    : Kernel(data,kf, own)
41  {
42    build_kernel();
43  }
44
45
46  Kernel_SEV::Kernel_SEV(const MatrixLookupWeighted& data, 
47                         const KernelFunction& kf, const bool own)
48    : Kernel(data,kf, own)
49  {
50    kernel_matrix_.resize(data.columns(),data.columns());
51    for (size_t i=0; i<kernel_matrix_.rows(); i++) 
52      for (size_t j=i; j<kernel_matrix_.columns(); j++)
53        kernel_matrix_(i,j) = kernel_matrix_(j,i) =
54          (*kf_)(DataLookupWeighted1D(data,i,false),
55                 DataLookupWeighted1D(data,j,false));
56  }
57
58
59  Kernel_SEV::Kernel_SEV(const Kernel_SEV& other, 
60                         const std::vector<size_t>& index)
61    : Kernel(other, index)
62  {
63    build_kernel();
64  }
65
66
67  void Kernel_SEV::build_kernel(void)
68  {
69    kernel_matrix_.resize(size(),size());
70    for (size_t i=0; i<kernel_matrix_.rows(); i++) 
71      for (size_t j=i; j<kernel_matrix_.columns(); j++)
72        kernel_matrix_(i,j) = kernel_matrix_(j,i) =
73          (*kf_)(DataLookup1D(*ml_,i,false),
74                 DataLookup1D(*ml_,j,false));
75  }
76
77
78  double Kernel_SEV::operator()(const size_t row,const size_t column) const
79  { 
80    return kernel_matrix_(row,column); 
81  }
82 
83
84  const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookup& data, 
85                                            const bool own) const
86  {
87    return new Kernel_SEV(data, *kf_, own);
88  }
89
90
91  const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookupWeighted& data, 
92                            const bool own) const
93  {
94    return new Kernel_SEV(data, *kf_, own);
95  }
96
97
98}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.