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) 2008-2009 Soeren Sonnenburg 00008 * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _FIRSTELEMENTKERNELNORMALIZER_H___ 00012 #define _FIRSTELEMENTKERNELNORMALIZER_H___ 00013 00014 #include <shogun/kernel/normalizer/KernelNormalizer.h> 00015 00016 namespace shogun 00017 { 00028 class CFirstElementKernelNormalizer : public CKernelNormalizer 00029 { 00030 public: 00033 CFirstElementKernelNormalizer() : CKernelNormalizer(), scale(1.0) 00034 { 00035 SG_ADD(&scale, "scale", "Scale quotient by which kernel is scaled.", 00036 MS_AVAILABLE); 00037 } 00038 00040 virtual ~CFirstElementKernelNormalizer() 00041 { 00042 } 00043 00046 virtual bool init(CKernel* k) 00047 { 00048 CFeatures* old_lhs=k->lhs; 00049 CFeatures* old_rhs=k->rhs; 00050 k->lhs=old_lhs; 00051 k->rhs=old_lhs; 00052 00053 scale=k->compute(0, 0); 00054 00055 k->lhs=old_lhs; 00056 k->rhs=old_rhs; 00057 00058 return true; 00059 } 00060 00066 virtual float64_t normalize( 00067 float64_t value, int32_t idx_lhs, int32_t idx_rhs) 00068 { 00069 return value/scale; 00070 } 00071 00076 virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs) 00077 { 00078 return value/sqrt(scale); 00079 } 00080 00085 virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs) 00086 { 00087 return value/sqrt(scale); 00088 } 00089 00091 virtual const char* get_name() const { return "FirstElementKernelNormalizer"; } 00092 00093 protected: 00095 float64_t scale; 00096 }; 00097 } 00098 #endif