KernelMachine.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-2009 Soeren Sonnenburg
00008  * Written (W) 2011-2012 Heiko Strathmann
00009  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _KERNEL_MACHINE_H__
00013 #define _KERNEL_MACHINE_H__
00014 
00015 #include <shogun/lib/common.h>
00016 #include <shogun/io/SGIO.h>
00017 #include <shogun/kernel/Kernel.h>
00018 #include <shogun/kernel/CustomKernel.h>
00019 #include <shogun/labels/Labels.h>
00020 #include <shogun/machine/Machine.h>
00021 
00022 #include <stdio.h>
00023 
00024 namespace shogun
00025 {
00026 class CMachine;
00027 class CLabels;
00028 class CKernel;
00029 
00050 class CKernelMachine : public CMachine
00051 {
00052     public:
00054         CKernelMachine();
00055 
00064         CKernelMachine(CKernel* k, const SGVector<float64_t> alphas, const SGVector<int32_t> svs, float64_t b);
00065 
00069         CKernelMachine(CKernelMachine* machine);
00070 
00072         virtual ~CKernelMachine();
00073 
00079         virtual const char* get_name() const { return "KernelMachine"; }
00080 
00085         void set_kernel(CKernel* k);
00086 
00091         CKernel* get_kernel();
00092 
00097         void set_batch_computation_enabled(bool enable);
00098 
00103         bool get_batch_computation_enabled();
00104 
00109         void set_linadd_enabled(bool enable);
00110 
00115         bool get_linadd_enabled();
00116 
00121         void set_bias_enabled(bool enable_bias);
00122 
00127         bool get_bias_enabled();
00128 
00133         float64_t get_bias();
00134 
00139         void set_bias(float64_t bias);
00140 
00146         int32_t get_support_vector(int32_t idx);
00147 
00153         float64_t get_alpha(int32_t idx);
00154 
00161         bool set_support_vector(int32_t idx, int32_t val);
00162 
00169         bool set_alpha(int32_t idx, float64_t val);
00170 
00175         int32_t get_num_support_vectors();
00176 
00181         void set_alphas(SGVector<float64_t> alphas);
00182 
00187         void set_support_vectors(SGVector<int32_t> svs);
00188 
00190         SGVector<int32_t> get_support_vectors();
00191 
00193         SGVector<float64_t> get_alphas();
00194 
00199         bool create_new_model(int32_t num);
00200 
00205         bool init_kernel_optimization();
00206 
00213         virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
00214         
00221         virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
00222 
00228         virtual float64_t apply_one(int32_t num);
00229 
00235         static void* apply_helper(void* p);
00236 
00243         virtual bool train_locked(SGVector<index_t> indices);
00244 
00251         virtual CBinaryLabels* apply_locked_binary(SGVector<index_t> indices);
00252 
00259         virtual CRegressionLabels* apply_locked_regression(
00260                 SGVector<index_t> indices);
00261 
00268         virtual SGVector<float64_t> apply_locked_get_output(
00269                 SGVector<index_t> indices);
00270 
00279         virtual void data_lock(CLabels* labs, CFeatures* features=NULL);
00280 
00282         virtual void data_unlock();
00283 
00285         virtual bool supports_locking() const { return true; }
00286 
00288         virtual CMachine* clone()
00289         {
00290             return new CKernelMachine(this);
00291         }
00292 
00293     protected:
00294 
00300         SGVector<float64_t> apply_get_outputs(CFeatures* data);
00301 
00308         virtual void store_model_features();
00309 
00310     private:
00312         void init();
00313 
00314     protected:
00316         CKernel* kernel;
00317 
00319         CCustomKernel* m_custom_kernel;
00320 
00322         CKernel* m_kernel_backup;
00323 
00325         bool use_batch_computation;
00326 
00328         bool use_linadd;
00329 
00331         bool use_bias;
00332 
00334         float64_t m_bias;
00335 
00337         SGVector<float64_t> m_alpha;
00338 
00340         SGVector<int32_t> m_svs;
00341 };
00342 }
00343 #endif /* _KERNEL_MACHINE_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation