SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
15 
16 using namespace shogun;
17 
20 {
21 }
22 
24 {
25 }
26 
28 bool CNormOne::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 CNormOne::load(FILE* f)
43 {
46  return false;
47 }
48 
50 bool CNormOne::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 norm=CMath::sqrt(CMath::dot(vec, vec, feature_matrix.num_rows));
68  SGVector<float64_t>::scale_vector(1.0/norm, 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 norm=CMath::sqrt(CMath::dot(vector.vector, vector.vector, vector.vlen));
79 
80  for (int32_t i=0; i<vector.vlen; i++)
81  normed_vec[i]=vector.vector[i]/norm;
82 
83  return SGVector<float64_t>(normed_vec,vector.vlen);
84 }
#define SG_RESET_LOCALE
Definition: SGIO.h:86
virtual SGMatrix< float64_t > apply_to_feature_matrix(CFeatures *features)
Definition: NormOne.cpp:60
virtual bool load(FILE *f)
initialize preprocessor from file
Definition: NormOne.cpp:42
index_t num_cols
Definition: SGMatrix.h:376
virtual bool save(FILE *f)
save preprocessor init-data to file
Definition: NormOne.cpp:50
virtual SGVector< float64_t > apply_to_feature_vector(SGVector< float64_t > vector)
Definition: NormOne.cpp:75
#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
virtual void cleanup()
cleanup
Definition: NormOne.cpp:37
virtual EFeatureClass get_feature_class() const =0
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
Definition: Math.h:627
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:68
static float32_t sqrt(float32_t x)
Definition: Math.h:459
virtual ~CNormOne()
Definition: NormOne.cpp:23
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation