SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AttenuatedEuclidianDistance.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Miguel Angel Bautista
8  * Copyright (C) 2011 Berlin Institute of Technology and Max Planck Society
9  */
10 
11 #include <shogun/lib/common.h>
12 #include <shogun/io/SGIO.h>
16 
17 using namespace shogun;
18 
20 {
21  init();
22 }
23 
25 : CRealDistance()
26 {
27  init();
28  init(l, r);
29 }
30 
32 {
33  cleanup();
34 }
35 
36 bool CAttenuatedEuclidianDistance::init(CFeatures* l, CFeatures* r)
37 {
38  CRealDistance::init(l, r);
39  return true;
40 }
41 
43 {
44 }
45 
46 float64_t CAttenuatedEuclidianDistance::compute(int32_t idx_a, int32_t idx_b)
47 {
48  int32_t alen, blen;
49  bool afree, bfree;
50  float64_t result=0;
51 
53  get_feature_vector(idx_a, alen, afree);
55  get_feature_vector(idx_b, blen, bfree);
56  ASSERT(alen==blen);
57 
58  for (int32_t i=0; i<alen; i++)
59  result+=(CMath::abs(avec[i])*CMath::abs(bvec[i]))*CMath::pow(avec[i] - bvec[i],2);
60 
61  ((CSimpleFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
62  ((CSimpleFeatures<float64_t>*) rhs)->free_feature_vector(bvec, idx_b, bfree);
63 
64  if (disable_sqrt)
65  return result;
66 
67  return CMath::sqrt(result);
68 }
69 
70 void CAttenuatedEuclidianDistance::init()
71 {
72  disable_sqrt=false;
73 
74  m_parameters->add(&disable_sqrt, "disable_sqrt", "If sqrt shall not be applied.");
75 }

SHOGUN Machine Learning Toolbox - Documentation