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 CLogPlusOne::CLogPlusOne()
00018 : CSimplePreProc<float64_t>("LogPlusOne", "LG+1")
00019 {
00020 }
00021 
00022 
00023 CLogPlusOne::~CLogPlusOne()
00024 {
00025 }
00026 
00028 bool CLogPlusOne::init(CFeatures* f)
00029 {
00030     ASSERT(f->get_feature_class()==C_SIMPLE);
00031     ASSERT(f->get_feature_type()==F_DREAL);
00032 
00033     return true;
00034 }
00035 
00037 void CLogPlusOne::cleanup()
00038 {
00039 }
00040 
00042 bool CLogPlusOne::load(FILE* f)
00043 {
00044     return false;
00045 }
00046 
00048 bool CLogPlusOne::save(FILE* f)
00049 {
00050     return false;
00051 }
00052 
00056 float64_t* CLogPlusOne::apply_to_feature_matrix(CFeatures* f)
00057 {
00058     int32_t i,j;
00059     int32_t num_vec;
00060     int32_t num_feat;
00061     float64_t* matrix=((CSimpleFeatures<float64_t>*) f)->get_feature_matrix(num_feat, num_vec);
00062 
00063     for (i=0; i<num_vec; i++)
00064     {
00065         float64_t* vec=&matrix[i*num_feat];
00066 
00067         for (j=0; j<num_feat; j++)
00068             vec[j]=log(vec[j]+1);
00069     }
00070     return matrix;
00071 }
00072 
00075 float64_t* CLogPlusOne::apply_to_feature_vector(float64_t* f, int32_t& len)
00076 {
00077     float64_t* vec=new float64_t[len];
00078     int32_t i=0;
00079 
00080     for (i=0; i<len; i++)
00081         vec[i]=log(f[i]+1);
00082 
00083     return vec;
00084 }
00085 
00087 bool CLogPlusOne::load_init_data(FILE* src)
00088 {
00089     return true;
00090 }
00091 
00093 bool CLogPlusOne::save_init_data(FILE* dst)
00094 {
00095     return true;
00096 }

SHOGUN Machine Learning Toolbox - Documentation