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

SHOGUN Machine Learning Toolbox - Documentation