yat/classifier/Kernel_SEV.cc

Code
Comments
Other
Rev Date Author Line
306 03 May 05 peter 1 // $Id$
306 03 May 05 peter 2
675 10 Oct 06 jari 3 /*
2119 12 Dec 09 peter 4   Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 5   Copyright (C) 2012 Peter Johansson
306 03 May 05 peter 6
1437 25 Aug 08 peter 7   This file is part of the yat library, http://dev.thep.lu.se/yat
306 03 May 05 peter 8
675 10 Oct 06 jari 9   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 10   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 11   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 12   License, or (at your option) any later version.
675 10 Oct 06 jari 13
675 10 Oct 06 jari 14   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 17   General Public License for more details.
675 10 Oct 06 jari 18
675 10 Oct 06 jari 19   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 20   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 21 */
675 10 Oct 06 jari 22
2881 18 Nov 12 peter 23 #include <config.h>
2881 18 Nov 12 peter 24
680 11 Oct 06 jari 25 #include "Kernel_SEV.h"
680 11 Oct 06 jari 26 #include "DataLookup1D.h"
680 11 Oct 06 jari 27 #include "DataLookupWeighted1D.h"
680 11 Oct 06 jari 28 #include "Kernel.h"
680 11 Oct 06 jari 29 #include "KernelFunction.h"
680 11 Oct 06 jari 30 #include "MatrixLookup.h"
1121 22 Feb 08 peter 31 #include "yat/utility/Matrix.h"
675 10 Oct 06 jari 32
306 03 May 05 peter 33 namespace theplu {
680 11 Oct 06 jari 34 namespace yat {
4200 19 Aug 22 peter 35 namespace classifier {
306 03 May 05 peter 36
420 02 Dec 05 jari 37
658 25 Sep 06 peter 38   Kernel_SEV::Kernel_SEV(const MatrixLookup& data, const KernelFunction& kf,
658 25 Sep 06 peter 39                          const bool own)
658 25 Sep 06 peter 40     : Kernel(data,kf, own)
523 23 Feb 06 peter 41   {
548 06 Mar 06 peter 42     build_kernel();
523 23 Feb 06 peter 43   }
539 05 Mar 06 peter 44
628 05 Sep 06 peter 45
4200 19 Aug 22 peter 46   Kernel_SEV::Kernel_SEV(const MatrixLookupWeighted& data,
658 25 Sep 06 peter 47                          const KernelFunction& kf, const bool own)
658 25 Sep 06 peter 48     : Kernel(data,kf, own)
628 05 Sep 06 peter 49   {
1163 26 Feb 08 peter 50     kernel_matrix_.resize(data.columns(),data.columns());
4200 19 Aug 22 peter 51     for (size_t i=0; i<kernel_matrix_.rows(); i++)
628 05 Sep 06 peter 52       for (size_t j=i; j<kernel_matrix_.columns(); j++)
628 05 Sep 06 peter 53         kernel_matrix_(i,j) = kernel_matrix_(j,i) =
628 05 Sep 06 peter 54           (*kf_)(DataLookupWeighted1D(data,i,false),
628 05 Sep 06 peter 55                  DataLookupWeighted1D(data,j,false));
628 05 Sep 06 peter 56   }
628 05 Sep 06 peter 57
628 05 Sep 06 peter 58
4200 19 Aug 22 peter 59   Kernel_SEV::Kernel_SEV(const Kernel_SEV& other,
545 06 Mar 06 peter 60                          const std::vector<size_t>& index)
545 06 Mar 06 peter 61     : Kernel(other, index)
545 06 Mar 06 peter 62   {
548 06 Mar 06 peter 63     build_kernel();
545 06 Mar 06 peter 64   }
539 05 Mar 06 peter 65
548 06 Mar 06 peter 66
548 06 Mar 06 peter 67   void Kernel_SEV::build_kernel(void)
548 06 Mar 06 peter 68   {
1163 26 Feb 08 peter 69     kernel_matrix_.resize(size(),size());
4200 19 Aug 22 peter 70     for (size_t i=0; i<kernel_matrix_.rows(); i++)
548 06 Mar 06 peter 71       for (size_t j=i; j<kernel_matrix_.columns(); j++)
548 06 Mar 06 peter 72         kernel_matrix_(i,j) = kernel_matrix_(j,i) =
1163 26 Feb 08 peter 73           (*kf_)(DataLookup1D(*ml_,i,false),
1163 26 Feb 08 peter 74                  DataLookup1D(*ml_,j,false));
548 06 Mar 06 peter 75   }
548 06 Mar 06 peter 76
548 06 Mar 06 peter 77
658 25 Sep 06 peter 78   double Kernel_SEV::operator()(const size_t row,const size_t column) const
4200 19 Aug 22 peter 79   {
4200 19 Aug 22 peter 80     return kernel_matrix_(row,column);
658 25 Sep 06 peter 81   }
658 25 Sep 06 peter 82
4200 19 Aug 22 peter 83
4200 19 Aug 22 peter 84   const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookup& data,
658 25 Sep 06 peter 85                                             const bool own) const
658 25 Sep 06 peter 86   {
658 25 Sep 06 peter 87     return new Kernel_SEV(data, *kf_, own);
658 25 Sep 06 peter 88   }
658 25 Sep 06 peter 89
658 25 Sep 06 peter 90
4200 19 Aug 22 peter 91   const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookupWeighted& data,
658 25 Sep 06 peter 92                             const bool own) const
658 25 Sep 06 peter 93   {
658 25 Sep 06 peter 94     return new Kernel_SEV(data, *kf_, own);
658 25 Sep 06 peter 95   }
658 25 Sep 06 peter 96
658 25 Sep 06 peter 97
680 11 Oct 06 jari 98 }}} // of namespace classifier, yat, and theplu