SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 }
#define SG_RESET_LOCALE
Definition: SGIO.h:86
virtual SGVector< float64_t > apply_to_feature_vector(SGVector< float64_t > vector)
Definition: SumOne.cpp:75
virtual bool load(FILE *f)
initialize preprocessor from file
Definition: SumOne.cpp:42
virtual bool save(FILE *f)
save preprocessor init-data to file
Definition: SumOne.cpp:50
index_t num_cols
Definition: SGMatrix.h:376
#define SG_SET_LOCALE_C
Definition: SGIO.h:85
index_t num_rows
Definition: SGMatrix.h:374
static void scale_vector(T alpha, T *vec, int32_t len)
Scale vector inplace.
Definition: SGVector.cpp:820
index_t vlen
Definition: SGVector.h:492
#define ASSERT(x)
Definition: SGIO.h:201
Template class DensePreprocessor, base class for preprocessors (cf. CPreprocessor) that apply to CDen...
double float64_t
Definition: common.h:50
static T sum(T *vec, int32_t len)
Return sum(vec)
Definition: SGVector.h:352
virtual EFeatureClass get_feature_class() const =0
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual ~CSumOne()
Definition: SumOne.cpp:23
virtual void cleanup()
cleanup
Definition: SumOne.cpp:37
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual SGMatrix< float64_t > apply_to_feature_matrix(CFeatures *features)
Definition: SumOne.cpp:60
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation