source: trunk/yat/classifier/Kernel_SEV.cc @ 1706

Last change on this file since 1706 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

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