SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2011 Zi Yuan 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/kernel/BesselKernel.h> 00012 #include <shogun/mathematics/Math.h> 00013 #include <math.h> 00014 00015 using namespace shogun; 00016 00017 CBesselKernel::CBesselKernel():CDistanceKernel(),order(0.0),degree(0) 00018 { 00019 init(); 00020 } 00021 00022 CBesselKernel::CBesselKernel(int32_t size, float64_t v, float64_t w, 00023 int32_t n, CDistance* dist) : 00024 CDistanceKernel(size,w,dist), order(v), degree(n) 00025 { 00026 ASSERT(distance); 00027 SG_REF(distance); 00028 init(); 00029 } 00030 00031 CBesselKernel::CBesselKernel(CFeatures* l, CFeatures* r, float64_t v, 00032 float64_t w, int32_t n, CDistance* dist, int32_t size) : 00033 CDistanceKernel(size,w,dist), order(v), degree(n) 00034 { 00035 init(); 00036 ASSERT(distance); 00037 SG_REF(distance); 00038 init(l,r); 00039 } 00040 00041 CBesselKernel::~CBesselKernel() 00042 { 00043 cleanup(); 00044 SG_UNREF(distance); 00045 } 00046 00047 void CBesselKernel::cleanup() 00048 { 00049 } 00050 00051 bool CBesselKernel::init(CFeatures* l, CFeatures* r) 00052 { 00053 ASSERT(distance); 00054 CDistanceKernel::init(l,r); 00055 distance->init(l,r); 00056 return init_normalizer(); 00057 } 00058 00059 void CBesselKernel::init() 00060 { 00061 SG_ADD(&order, "order", "Kernel order.", MS_AVAILABLE); 00062 SG_ADD(&width, "width", "Kernel width.", MS_AVAILABLE); 00063 SG_ADD(°ree, "degree", "Kernel degree.", MS_AVAILABLE); 00064 SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.", 00065 MS_AVAILABLE); 00066 } 00067 00068 float64_t CBesselKernel::compute(int32_t idx_a, int32_t idx_b) 00069 { 00070 float64_t dist = distance->distance(idx_a, idx_b); 00071 return jn(order,dist/width)/CMath::pow(dist,-degree*order); 00072 }