SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SparseEuclideanDistance.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) 2007-2009 Soeren Sonnenburg
8  * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #include <shogun/lib/common.h>
12 #include <shogun/io/SGIO.h>
16 
17 using namespace shogun;
18 
21 {
22  init();
23 }
24 
28 {
29  init();
30  init(l, r);
31 }
32 
34 {
35  cleanup();
36 }
37 
38 bool CSparseEuclideanDistance::init(CFeatures* l, CFeatures* r)
39 {
41 
42  cleanup();
43 
45  sq_lhs=((CSparseFeatures<float64_t>*) lhs)->compute_squared(sq_lhs);
46 
47  if (lhs==rhs)
48  sq_rhs=sq_lhs;
49  else
50  {
52  sq_rhs=((CSparseFeatures<float64_t>*) rhs)->compute_squared(sq_rhs);
53  }
54 
55  return true;
56 }
57 
59 {
60  if (sq_lhs != sq_rhs)
61  SG_FREE(sq_rhs);
62  sq_rhs = NULL;
63 
64  SG_FREE(sq_lhs);
65  sq_lhs = NULL;
66 }
67 
68 float64_t CSparseEuclideanDistance::compute(int32_t idx_a, int32_t idx_b)
69 {
70  float64_t result=((CSparseFeatures<float64_t>*) lhs)->compute_squared_norm(
73 
74  return CMath::sqrt(result);
75 }
76 
77 void CSparseEuclideanDistance::init()
78 {
79  sq_lhs=NULL;
80  sq_rhs=NULL;
81 }

SHOGUN Machine Learning Toolbox - Documentation