SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
SparseEuclideanDistance.cpp
浏览该文件的文档.
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 
44  sq_lhs=SG_MALLOC(float64_t, lhs->get_num_vectors());
45  sq_lhs=((CSparseFeatures<float64_t>*) lhs)->compute_squared(sq_lhs);
46 
47  if (lhs==rhs)
48  sq_rhs=sq_lhs;
49  else
50  {
51  sq_rhs=SG_MALLOC(float64_t, rhs->get_num_vectors());
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 }
template class SparseDistance
virtual int32_t get_num_vectors() const =0
virtual bool init(CFeatures *l, CFeatures *r)
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CFeatures * lhs
feature vectors to occur on the left hand side
Definition: Distance.h:343
The class Features is the base class of all feature objects.
Definition: Features.h:68
CFeatures * rhs
feature vectors to occur on the right hand side
Definition: Distance.h:345
static float32_t sqrt(float32_t x)
Definition: Math.h:459

SHOGUN 机器学习工具包 - 项目文档