# source:trunk/lib/svm/GaussianKernelFunction.cc@353

Last change on this file since 353 was 353, checked in by Peter, 17 years ago

removed function returning the whole matrix. It is not needed anymore and should not be there for simplistic reasons.

• Property svn:eol-style set to `native`
• Property svn:keywords set to `Author Date Id Revision`
File size: 945 bytes
Line
1// \$Id: GaussianKernelFunction.cc 353 2005-06-08 23:28:35Z peter \$
2
3#include <c++_tools/svm/GaussianKernelFunction.h>
4
5#include <c++_tools/svm/KernelFunction.h>
6#include <c++_tools/gslapi/matrix.h>
7#include <c++_tools/gslapi/vector.h>
8
9#include <math.h>
10
11namespace theplu {
12namespace svm {
13
14GaussianKernelFunction::GaussianKernelFunction(double sigma)
15  : KernelFunction(), sigma_(sigma)
16{
17}
18
19double GaussianKernelFunction::operator()(const gslapi::vector& a1,
20                                          const gslapi::vector& a2,
21                                          const gslapi::vector& w1,
22                                          const gslapi::vector& w2) const
23{
24  double distance = 0;
25  double normalization_factor = 0;
26  for (size_t i=0; i<a1.size(); i++) {
27    distance += w1(i) * w2(i) * (a1(i)-a2(i)) * (a1(i)-a2(i));
28    normalization_factor += w1(i) * w2(i);
29  }
30// to make it coherent with no weight case
31  normalization_factor /= a1.size();
32  return exp(distance/normalization_factor/pow(sigma_,2));
33}
34
35
36
37}} // of namespace svn and namespace theplu
Note: See TracBrowser for help on using the repository browser.