LogPlusOne.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 "preproc/LogPlusOne.h"
00012 #include "preproc/SimplePreProc.h"
00013 #include "features/Features.h"
00014 #include "features/SimpleFeatures.h"
00015 #include "lib/Mathematics.h"
00016 
00017 using namespace shogun;
00018 
00019 CLogPlusOne::CLogPlusOne()
00020 : CSimplePreProc<float64_t>("LogPlusOne", "LG+1")
00021 {
00022 }
00023 
00024 
00025 CLogPlusOne::~CLogPlusOne()
00026 {
00027 }
00028 
00030 bool CLogPlusOne::init(CFeatures* f)
00031 {
00032     ASSERT(f->get_feature_class()==C_SIMPLE);
00033     ASSERT(f->get_feature_type()==F_DREAL);
00034 
00035     return true;
00036 }
00037 
00039 void CLogPlusOne::cleanup()
00040 {
00041 }
00042 
00044 bool CLogPlusOne::load(FILE* f)
00045 {
00046     SG_SET_LOCALE_C;
00047     SG_RESET_LOCALE;
00048     return false;
00049 }
00050 
00052 bool CLogPlusOne::save(FILE* f)
00053 {
00054     SG_SET_LOCALE_C;
00055     SG_RESET_LOCALE;
00056     return false;
00057 }
00058 
00062 float64_t* CLogPlusOne::apply_to_feature_matrix(CFeatures* f)
00063 {
00064     int32_t i,j;
00065     int32_t num_vec;
00066     int32_t num_feat;
00067     float64_t* matrix=((CSimpleFeatures<float64_t>*) f)->get_feature_matrix(num_feat, num_vec);
00068 
00069     for (i=0; i<num_vec; i++)
00070     {
00071         float64_t* vec=&matrix[i*num_feat];
00072 
00073         for (j=0; j<num_feat; j++)
00074             vec[j]=log(vec[j]+1);
00075     }
00076     return matrix;
00077 }
00078 
00081 float64_t* CLogPlusOne::apply_to_feature_vector(float64_t* f, int32_t& len)
00082 {
00083     float64_t* vec=new float64_t[len];
00084     int32_t i=0;
00085 
00086     for (i=0; i<len; i++)
00087         vec[i]=log(f[i]+1);
00088 
00089     return vec;
00090 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation