SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SumOne.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) 2012 Sergey Lisitsyn
8  * Copyright (C) 2012 Sergey Lisitsyn
9  */
10 
15 
16 using namespace shogun;
17 
20 {
21 }
22 
24 {
25 }
26 
28 bool CSumOne::init(CFeatures* features)
29 {
30  ASSERT(features->get_feature_class()==C_DENSE);
31  ASSERT(features->get_feature_type()==F_DREAL);
32 
33  return true;
34 }
35 
38 {
39 }
40 
42 bool CSumOne::load(FILE* f)
43 {
46  return false;
47 }
48 
50 bool CSumOne::save(FILE* f)
51 {
54  return false;
55 }
56 
61 {
62  SGMatrix<float64_t> feature_matrix=((CDenseFeatures<float64_t>*)features)->get_feature_matrix();
63 
64  for (int32_t i=0; i<feature_matrix.num_cols; i++)
65  {
66  float64_t* vec= &(feature_matrix.matrix[i*feature_matrix.num_rows]);
67  float64_t sum = SGVector<float64_t>::sum(vec,feature_matrix.num_rows);
68  SGVector<float64_t>::scale_vector(1.0/sum, vec, feature_matrix.num_rows);
69  }
70  return feature_matrix;
71 }
72 
76 {
77  float64_t* normed_vec = SG_MALLOC(float64_t, vector.vlen);
78  float64_t sum = SGVector<float64_t>::sum(vector.vector, vector.vlen);
79 
80  for (int32_t i=0; i<vector.vlen; i++)
81  normed_vec[i]=vector.vector[i]/sum;
82 
83  return SGVector<float64_t>(normed_vec,vector.vlen);
84 }

SHOGUN Machine Learning Toolbox - Documentation