Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "lib/common.h"
00012 #include "kernel/HistogramIntersectionKernel.h"
00013 #include "features/Features.h"
00014 #include "features/SimpleFeatures.h"
00015 #include "lib/io.h"
00016
00017 using namespace shogun;
00018
00019 CHistogramIntersectionKernel::CHistogramIntersectionKernel(void)
00020 : CDotKernel(0)
00021 {
00022 SG_UNSTABLE("CHistogramIntersectionKernel::"
00023 "CHistogramIntersectionKernel(void)", "\n");
00024 }
00025
00026 CHistogramIntersectionKernel::CHistogramIntersectionKernel(int32_t size)
00027 : CDotKernel(size)
00028 {
00029 }
00030
00031 CHistogramIntersectionKernel::CHistogramIntersectionKernel(
00032 CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r, int32_t size)
00033 : CDotKernel(size)
00034 {
00035 init(l,r);
00036 }
00037
00038 CHistogramIntersectionKernel::~CHistogramIntersectionKernel()
00039 {
00040 cleanup();
00041 }
00042
00043 bool CHistogramIntersectionKernel::init(CFeatures* l, CFeatures* r)
00044 {
00045 bool result=CDotKernel::init(l,r);
00046 init_normalizer();
00047 return result;
00048 }
00049
00050 float64_t CHistogramIntersectionKernel::compute(int32_t idx_a, int32_t idx_b)
00051 {
00052 int32_t alen, blen;
00053 bool afree, bfree;
00054
00055 float64_t* avec=
00056 ((CSimpleFeatures<float64_t>*) lhs)->get_feature_vector(idx_a, alen, afree);
00057 float64_t* bvec=
00058 ((CSimpleFeatures<float64_t>*) rhs)->get_feature_vector(idx_b, blen, bfree);
00059 ASSERT(alen==blen);
00060
00061 float64_t result=0;
00062 for (int32_t i=0; i<alen; i++)
00063 result += (avec[i] < bvec[i]) ? avec[i] : bvec[i];
00064
00065 ((CSimpleFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
00066 ((CSimpleFeatures<float64_t>*) rhs)->free_feature_vector(bvec, idx_b, bfree);
00067
00068 return result;
00069 }