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 Soeren Sonnenburg 00008 * Copyright (C) 2010 Berlin Institute of Technology 00009 */ 00010 00011 #ifndef _SCATTERKERNELNORMALIZER_H___ 00012 #define _SCATTERKERNELNORMALIZER_H___ 00013 00014 #include "kernel/KernelNormalizer.h" 00015 #include "kernel/IdentityKernelNormalizer.h" 00016 #include "kernel/Kernel.h" 00017 00018 namespace shogun 00019 { 00020 class CScatterKernelNormalizer: public CKernelNormalizer 00021 { 00022 00023 public: 00024 00027 CScatterKernelNormalizer(float64_t const_diag, float64_t const_offdiag, 00028 CLabels* labels, CKernelNormalizer* normalizer=NULL) 00029 { 00030 m_const_diag=const_diag; 00031 m_const_offdiag=const_offdiag; 00032 00033 SG_REF(labels); 00034 m_labels=labels; 00035 00036 if (normalizer==NULL) 00037 normalizer=new CIdentityKernelNormalizer(); 00038 SG_REF(normalizer); 00039 m_normalizer=normalizer; 00040 } 00041 00043 virtual ~CScatterKernelNormalizer() 00044 { 00045 SG_UNREF(m_labels); 00046 SG_UNREF(m_normalizer); 00047 } 00048 00051 virtual bool init(CKernel* k) 00052 { 00053 m_normalizer->init(k); 00054 return true; 00055 } 00056 00062 inline virtual float64_t normalize(float64_t value, int32_t idx_lhs, 00063 int32_t idx_rhs) 00064 { 00065 value=m_normalizer->normalize(value, idx_lhs, idx_rhs); 00066 00067 float64_t c=m_const_offdiag; 00068 if (m_labels->get_label(idx_lhs) == m_labels->get_label(idx_rhs)) 00069 c=m_const_diag; 00070 00071 return value*c; 00072 } 00073 00078 inline 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 inline 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 00095 inline virtual const char* get_name() const 00096 { 00097 return "ScatterKernelNormalizer"; 00098 } 00099 00100 protected: 00101 00103 float64_t m_const_diag; 00105 float64_t m_const_offdiag; 00106 00108 CLabels* m_labels; 00109 00111 CKernelNormalizer* m_normalizer; 00112 }; 00113 } 00114 #endif 00115