LinearKernel.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) 1999-2010 Soeren Sonnenburg
00008  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  * Copyright (C) 2010 Berlin Institute of Technology
00010  */
00011 
00012 #ifndef _LINEARKERNEL_H___
00013 #define _LINEARKERNEL_H___
00014 
00015 #include "lib/common.h"
00016 #include "kernel/DotKernel.h"
00017 #include "features/DotFeatures.h"
00018 
00019 namespace shogun
00020 {
00021     class CDotFeatures;
00022 
00031 class CLinearKernel: public CDotKernel
00032 {
00033     public:
00036         CLinearKernel();
00037 
00043         CLinearKernel(CDotFeatures* l, CDotFeatures* r);
00044 
00045         virtual ~CLinearKernel();
00046 
00053         virtual bool init(CFeatures* l, CFeatures* r);
00054 
00056         virtual void cleanup();
00057 
00062         virtual EKernelType get_kernel_type() { return K_LINEAR; }
00063 
00068         virtual const char* get_name() const { return "Linear"; }
00069 
00078         virtual bool init_optimization(
00079             int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas);
00080 
00085         virtual bool delete_optimization();
00086 
00092         virtual float64_t compute_optimized(int32_t idx);
00093 
00095         virtual void clear_normal();
00096 
00102         virtual void add_to_normal(int32_t idx, float64_t weight);
00103 
00109         inline const float64_t* get_normal(int32_t& len)
00110         {
00111             if (lhs && normal)
00112             {
00113                 len = ((CDotFeatures*) lhs)->get_dim_feature_space();
00114                 return normal;
00115             }
00116             else
00117             {
00118                 len = 0;
00119                 return NULL;
00120             }
00121         }
00122 
00128         inline void get_w(float64_t** dst_w, int32_t* dst_dims)
00129         {
00130             ASSERT(lhs && normal);
00131             int32_t len = ((CDotFeatures*) lhs)->get_dim_feature_space();
00132             ASSERT(dst_w && dst_dims);
00133             *dst_dims=len;
00134             *dst_w=(float64_t*) malloc(sizeof(float64_t)*(*dst_dims));
00135             ASSERT(*dst_w);
00136             memcpy(*dst_w, normal, sizeof(float64_t) * (*dst_dims));
00137         }
00138 
00144         inline void set_w(float64_t* src_w, int32_t src_w_dim)
00145         {
00146             ASSERT(lhs && src_w_dim==((CDotFeatures*) lhs)->get_dim_feature_space());
00147             clear_normal();
00148             memcpy(normal, src_w, sizeof(float64_t) * src_w_dim);
00149         }
00150 
00151     protected:
00153         float64_t* normal;
00155         int32_t normal_length;
00156 };
00157 }
00158 #endif /* _LINEARKERNEL_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation