SHOGUN  6.1.3
NormOne.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 
25 {
26 }
27 
29 bool CNormOne::init(CFeatures* features)
30 {
31  ASSERT(features->get_feature_class()==C_DENSE)
32  ASSERT(features->get_feature_type()==F_DREAL)
33 
34  return true;
35 }
36 
39 {
40 }
41 
43 bool CNormOne::load(FILE* f)
44 {
47  return false;
48 }
49 
51 bool CNormOne::save(FILE* f)
52 {
55  return false;
56 }
57 
62 {
63  SGMatrix<float64_t> feature_matrix=((CDenseFeatures<float64_t>*)features)->get_feature_matrix();
64 
65  for (int32_t i=0; i<feature_matrix.num_cols; i++)
66  {
67  SGVector<float64_t> vec(&(feature_matrix.matrix[i*feature_matrix.num_rows]), feature_matrix.num_rows, false);
69  SGVector<float64_t>::scale_vector(1.0/norm, vec, feature_matrix.num_rows);
70  }
71  return feature_matrix;
72 }
73 
77 {
78  float64_t* normed_vec = SG_MALLOC(float64_t, vector.vlen);
79  float64_t norm=CMath::sqrt(linalg::dot(vector, vector));
80 
81  for (int32_t i=0; i<vector.vlen; i++)
82  normed_vec[i]=vector.vector[i]/norm;
83 
84  return SGVector<float64_t>(normed_vec,vector.vlen);
85 }
#define SG_RESET_LOCALE
Definition: SGIO.h:85
virtual SGMatrix< float64_t > apply_to_feature_matrix(CFeatures *features)
Definition: NormOne.cpp:61
virtual bool load(FILE *f)
initialize preprocessor from file
Definition: NormOne.cpp:43
static T sqrt(T x)
Definition: Math.h:428
T dot(const SGVector< T > &a, const SGVector< T > &b)
virtual bool save(FILE *f)
save preprocessor init-data to file
Definition: NormOne.cpp:51
virtual SGVector< float64_t > apply_to_feature_vector(SGVector< float64_t > vector)
Definition: NormOne.cpp:76
#define SG_SET_LOCALE_C
Definition: SGIO.h:84
#define ASSERT(x)
Definition: SGIO.h:176
Template class DensePreprocessor, base class for preprocessors (cf. CPreprocessor) that apply to CDen...
T norm(const SGVector< T > &a)
double float64_t
Definition: common.h:60
virtual void cleanup()
cleanup
Definition: NormOne.cpp:38
index_t num_rows
Definition: SGMatrix.h:495
virtual EFeatureClass get_feature_class() const =0
index_t num_cols
Definition: SGMatrix.h:497
static void scale_vector(T alpha, T *vec, int32_t len)
Scale vector inplace.
Definition: SGVector.cpp:877
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:69
virtual ~CNormOne()
Definition: NormOne.cpp:24
virtual EFeatureType get_feature_type() const =0
index_t vlen
Definition: SGVector.h:571

SHOGUN Machine Learning Toolbox - Documentation