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) 2010 Christian Widmer 00008 * Copyright (C) 2010 Max-Planck-Society 00009 */ 00010 00011 #ifndef _MULTITASKKERNELMKLNORMALIZER_H___ 00012 #define _MULTITASKKERNELMKLNORMALIZER_H___ 00013 00014 #include <shogun/kernel/KernelNormalizer.h> 00015 #include <shogun/kernel/MultitaskKernelMklNormalizer.h> 00016 #include <shogun/kernel/Kernel.h> 00017 #include <algorithm> 00018 #include <string> 00019 00020 namespace shogun 00021 { 00022 00023 00027 class CMultitaskKernelMklNormalizer: public CKernelNormalizer 00028 { 00029 00030 public: 00031 00034 CMultitaskKernelMklNormalizer() : CKernelNormalizer(), scale(1.0) 00035 { 00036 m_type = N_MULTITASK; 00037 } 00038 00039 00042 virtual bool init(CKernel* k) 00043 { 00044 00045 //same as first-element normalizer 00046 CFeatures* old_lhs=k->lhs; 00047 CFeatures* old_rhs=k->rhs; 00048 k->lhs=old_lhs; 00049 k->rhs=old_lhs; 00050 00051 if (std::string(k->get_name()) == "WeightedDegree") { 00052 SG_INFO("using first-element normalization\n"); 00053 scale=k->compute(0, 0); 00054 } else { 00055 SG_INFO("no inner normalization for non-WDK kernel\n"); 00056 scale=1.0; 00057 } 00058 00059 00060 k->lhs=old_lhs; 00061 k->rhs=old_rhs; 00062 00063 ASSERT(k); 00064 int32_t num_lhs = k->get_num_vec_lhs(); 00065 int32_t num_rhs = k->get_num_vec_rhs(); 00066 ASSERT(num_lhs>0); 00067 ASSERT(num_rhs>0); 00068 00069 00070 return true; 00071 } 00072 00073 00074 00079 inline virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs) 00080 { 00081 SG_ERROR("normalize_lhs not implemented"); 00082 return 0; 00083 } 00084 00089 inline virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs) 00090 { 00091 SG_ERROR("normalize_rhs not implemented"); 00092 return 0; 00093 } 00094 00095 public: 00096 00097 00101 virtual float64_t get_beta(int32_t idx) = 0; 00102 00107 virtual void set_beta(int32_t idx, float64_t weight) = 0; 00108 00109 00113 virtual int32_t get_num_betas() = 0; 00114 00115 00117 inline virtual const char* get_name() const 00118 { 00119 return "MultitaskKernelMklNormalizer"; 00120 } 00121 00122 protected: 00123 00124 00126 float64_t scale; 00127 00128 }; 00129 } 00130 #endif