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     return false;
00047 }
00048 
00050 bool CLogPlusOne::save(FILE* f)
00051 {
00052     return false;
00053 }
00054 
00058 float64_t* CLogPlusOne::apply_to_feature_matrix(CFeatures* f)
00059 {
00060     int32_t i,j;
00061     int32_t num_vec;
00062     int32_t num_feat;
00063     float64_t* matrix=((CSimpleFeatures<float64_t>*) f)->get_feature_matrix(num_feat, num_vec);
00064 
00065     for (i=0; i<num_vec; i++)
00066     {
00067         float64_t* vec=&matrix[i*num_feat];
00068 
00069         for (j=0; j<num_feat; j++)
00070             vec[j]=log(vec[j]+1);
00071     }
00072     return matrix;
00073 }
00074 
00077 float64_t* CLogPlusOne::apply_to_feature_vector(float64_t* f, int32_t& len)
00078 {
00079     float64_t* vec=new float64_t[len];
00080     int32_t i=0;
00081 
00082     for (i=0; i<len; i++)
00083         vec[i]=log(f[i]+1);
00084 
00085     return vec;
00086 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation