FirstElementKernelNormalizer.h

Go to the documentation of this file.
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 "kernel/KernelNormalizer.h"
00015 
00016 namespace shogun
00017 {
00028 class CFirstElementKernelNormalizer : public CKernelNormalizer
00029 {
00030     public:
00033         CFirstElementKernelNormalizer() : scale(1.0)
00034         {
00035         }
00036 
00038         virtual ~CFirstElementKernelNormalizer()
00039         {
00040         }
00041 
00044         virtual bool init(CKernel* k)
00045         {
00046             CFeatures* old_lhs=k->lhs;
00047             CFeatures* old_rhs=k->rhs;
00048             k->lhs=old_lhs;
00049             k->rhs=old_lhs;
00050 
00051             scale=k->compute(0, 0);
00052 
00053             k->lhs=old_lhs;
00054             k->rhs=old_rhs;
00055 
00056             return true;
00057         }
00058 
00064         inline virtual float64_t normalize(
00065             float64_t value, int32_t idx_lhs, int32_t idx_rhs)
00066         {
00067             return value/scale;
00068         }
00069 
00074         inline virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
00075         {
00076             return value/sqrt(scale);
00077         }
00078 
00083         inline virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
00084         {
00085             return value/sqrt(scale);
00086         }
00087 
00089         inline virtual const char* get_name() const { return "FirstElementKernelNormalizer"; }
00090 
00091     protected:
00093         float64_t scale;
00094 };
00095 }
00096 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation