SparseLinearClassifier.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-2008 Soeren Sonnenburg
00008  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _SPARSELINEARCLASSIFIER_H__
00012 #define _SPARSELINEARCLASSIFIER_H__
00013 
00014 #include "lib/common.h"
00015 #include "features/SparseFeatures.h"
00016 #include "classifier/Classifier.h"
00017 
00019 class CSparseLinearClassifier : public CClassifier
00020 {
00021     public:
00023         CSparseLinearClassifier();
00024         virtual ~CSparseLinearClassifier();
00025 
00031         virtual CLabels* classify(CLabels* output=NULL);
00032 
00034         virtual inline DREAL classify_example(INT vec_idx)
00035         {
00036             return features->dense_dot(1.0, vec_idx, w, w_dim, bias);
00037         }
00038 
00044         inline void get_w(DREAL** dst_w, INT* dst_dims)
00045         {
00046             ASSERT(dst_w && dst_dims);
00047             ASSERT(w && w_dim>0);
00048             *dst_dims=w_dim;
00049             *dst_w=(DREAL*) malloc(sizeof(DREAL) * (*dst_dims));
00050             ASSERT(*dst_w);
00051             memcpy(*dst_w, w, sizeof(DREAL) * (*dst_dims));
00052         }
00053 
00059         inline void set_w(DREAL* src_w, INT src_w_dim)
00060         {
00061             w=src_w;
00062             w_dim=src_w_dim;
00063         }
00064 
00069         inline void set_bias(DREAL b)
00070         {
00071             bias=b;
00072         }
00073 
00078         inline DREAL get_bias()
00079         {
00080             return bias;
00081         }
00082 
00087         inline void set_features(CSparseFeatures<DREAL>* feat)
00088         {
00089             SG_UNREF(features);
00090             SG_REF(feat);
00091             features=feat;
00092         }
00093 
00098         inline CSparseFeatures<DREAL>* get_features() { SG_REF(features); return features; }
00099 
00100     protected:
00102         INT w_dim;
00104         DREAL* w;
00106         DREAL bias;
00108         CSparseFeatures<DREAL>* features;
00109 };
00110 #endif

SHOGUN Machine Learning Toolbox - Documentation