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 Soeren Sonnenburg
00008  * Copyright (C) 2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _FIRSTELEMENTKERNELNORMALIZER_H___
00012 #define _FIRSTELEMENTKERNELNORMALIZER_H___
00013 
00014 #include "kernel/KernelNormalizer.h"
00015 
00026 class CFirstElementKernelNormalizer : public CKernelNormalizer
00027 {
00028     public:
00031         CFirstElementKernelNormalizer()
00032         {
00033         }
00034 
00036         virtual ~CFirstElementKernelNormalizer()
00037         {
00038         }
00039 
00042         virtual bool init(CKernel* k)
00043         {
00044             CFeatures* old_lhs=k->lhs;
00045             CFeatures* old_rhs=k->rhs;
00046             k->lhs=old_lhs;
00047             k->rhs=old_lhs;
00048 
00049             scale=k->compute(0, 0);
00050 
00051             k->lhs=old_lhs;
00052             k->rhs=old_rhs;
00053 
00054             return true;
00055         }
00056 
00062         inline virtual float64_t normalize(
00063             float64_t value, int32_t idx_lhs, int32_t idx_rhs)
00064         {
00065             return value/scale;
00066         }
00067 
00072         inline virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
00073         {
00074             return value/sqrt(scale);
00075         }
00076 
00081         inline virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
00082         {
00083             return value/sqrt(scale);
00084         }
00085 
00086     protected:
00088         float64_t scale;
00089 };
00090 
00091 #endif

SHOGUN Machine Learning Toolbox - Documentation