LinearClassifier.cpp

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  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #include "classifier/LinearClassifier.h"
00012 
00013 using namespace shogun;
00014 
00015 CLinearClassifier::CLinearClassifier()
00016 : CClassifier(), w_dim(0), w(NULL), bias(0), features(NULL)
00017 {
00018 }
00019 
00020 CLinearClassifier::~CLinearClassifier()
00021 {
00022     delete[] w;
00023     SG_UNREF(features);
00024 }
00025 
00026 bool CLinearClassifier::load(FILE* srcfile)
00027 {
00028     return false;
00029 }
00030 
00031 bool CLinearClassifier::save(FILE* dstfile)
00032 {
00033     return false;
00034 }
00035 
00036 CLabels* CLinearClassifier::classify()
00037 {
00038     if (features)
00039     {
00040         int32_t num=features->get_num_vectors();
00041         ASSERT(num>0);
00042         ASSERT(w_dim==features->get_dim_feature_space());
00043 
00044         float64_t* out=new float64_t[num];
00045         features->dense_dot_range(out, 0, num, NULL, w, w_dim, bias);
00046 
00047         CLabels* output=new CLabels(num);
00048         output->set_labels(out, num);
00049 
00050         delete[] out;
00051 
00052         return output;
00053     }
00054 
00055     return NULL;
00056 }
00057 
00058 CLabels* CLinearClassifier::classify(CFeatures* data)
00059 {
00060     if (!data)
00061         SG_ERROR("No features specified\n");
00062     if (!data->has_property(FP_DOT))
00063         SG_ERROR("Specified features are not of type CDotFeatures\n");
00064     set_features((CDotFeatures*) data);
00065     return classify();
00066 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation