AvgDiagKernelNormalizer.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) 2009 Soeren Sonnenburg
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _AVGDIAGKERNELNORMALIZER_H___
00012 #define _AVGDIAGKERNELNORMALIZER_H___
00013 
00014 #include "kernel/KernelNormalizer.h"
00015 namespace shogun
00016 {
00031 class CAvgDiagKernelNormalizer : public CKernelNormalizer
00032 {
00033     public:
00039         CAvgDiagKernelNormalizer(float64_t c=0.0) : CKernelNormalizer()
00040         {
00041             scale=c;
00042 
00043             m_parameters->add(&scale, "scale",
00044                               "Scale quotient by which kernel is scaled.");
00045         }
00046 
00048         virtual ~CAvgDiagKernelNormalizer()
00049         {
00050         }
00051 
00054         virtual bool init(CKernel* k)
00055         {
00056             if (scale<=0)
00057             {
00058                 ASSERT(k);
00059                 int32_t num=k->get_num_vec_lhs();
00060                 ASSERT(num>0);
00061 
00062                 CFeatures* old_lhs=k->lhs;
00063                 CFeatures* old_rhs=k->rhs;
00064                 k->lhs=old_lhs;
00065                 k->rhs=old_lhs;
00066 
00067                 float64_t sum=0;
00068                 for (int32_t i=0; i<num; i++)
00069                     sum+=k->compute(i, i);
00070 
00071                 scale=sum/num;
00072                 k->lhs=old_lhs;
00073                 k->rhs=old_rhs;
00074             }
00075 
00076             return true;
00077         }
00078 
00084         inline virtual float64_t normalize(
00085             float64_t value, int32_t idx_lhs, int32_t idx_rhs)
00086         {
00087             return value/scale;
00088         }
00089 
00094         inline virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
00095         {
00096             return value/sqrt(scale);
00097         }
00098 
00103         inline virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
00104         {
00105             return value/sqrt(scale);
00106         }
00107 
00109         inline virtual const char* get_name() const { return "AvgDiagKernelNormalizer"; }
00110 
00111     protected:
00113         float64_t scale;
00114 };
00115 }
00116 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation