SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LogPlusOne.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
16 
17 using namespace shogun;
18 
21 {
22 }
23 
24 
26 {
27 }
28 
30 bool CLogPlusOne::init(CFeatures* features)
31 {
32  ASSERT(features->get_feature_class()==C_SIMPLE);
33  ASSERT(features->get_feature_type()==F_DREAL);
34 
35  return true;
36 }
37 
40 {
41 }
42 
44 bool CLogPlusOne::load(FILE* f)
45 {
48  return false;
49 }
50 
52 bool CLogPlusOne::save(FILE* f)
53 {
56  return false;
57 }
58 
63 {
64  SGMatrix<float64_t> feature_matrix =
65  ((CSimpleFeatures<float64_t>*)features)->get_feature_matrix();
66 
67  for (int32_t i=0; i<feature_matrix.num_cols; i++)
68  {
69  for (int32_t j=0; j<feature_matrix.num_rows; j++)
70  feature_matrix.matrix[i*feature_matrix.num_rows+j] =
71  CMath::log(feature_matrix.matrix[i*feature_matrix.num_rows+j]+1.0);
72  }
73  return feature_matrix;
74 }
75 
79 {
80  float64_t* log_vec = SG_MALLOC(float64_t, vector.vlen);
81 
82  for (int32_t i=0; i<vector.vlen; i++)
83  log_vec[i]=CMath::log(vector.vector[i]+1.0);
84 
85  return SGVector<float64_t>(log_vec,vector.vlen);
86 }

SHOGUN Machine Learning Toolbox - Documentation