SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
CPolyFeatures Class Reference

Detailed Description

implement DotFeatures for the polynomial kernel

see DotFeatures for further discription

Definition at line 25 of file PolyFeatures.h.

Inheritance diagram for CPolyFeatures:
Inheritance graph
[legend]

Public Member Functions

 CPolyFeatures ()
 CPolyFeatures (CSimpleFeatures< float64_t > *feat, int32_t degree, bool normalize)
virtual ~CPolyFeatures ()
 CPolyFeatures (const CPolyFeatures &orig)
virtual int32_t get_dim_feature_space () const
virtual int32_t get_nnz_features_for_vector (int32_t num)
virtual EFeatureType get_feature_type ()
virtual EFeatureClass get_feature_class ()
virtual int32_t get_num_vectors () const
virtual float64_t dot (int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
virtual int32_t get_size ()
CFeaturesduplicate () const
virtual const char * get_name () const
float64_t dense_dot (int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
void add_to_dense_vec (float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val)
virtual void * get_feature_iterator (int32_t vector_index)
virtual bool get_next_feature (int32_t &index, float64_t &value, void *iterator)
virtual void free_feature_iterator (void *iterator)
- Public Member Functions inherited from CDotFeatures
 CDotFeatures (int32_t size=0)
 CDotFeatures (const CDotFeatures &orig)
 CDotFeatures (CFile *loader)
virtual ~CDotFeatures ()
virtual void dense_dot_range (float64_t *output, int32_t start, int32_t stop, float64_t *alphas, float64_t *vec, int32_t dim, float64_t b)
virtual void dense_dot_range_subset (int32_t *sub_index, int32_t num, float64_t *output, float64_t *alphas, float64_t *vec, int32_t dim, float64_t b)
float64_t get_combined_feature_weight ()
void set_combined_feature_weight (float64_t nw)
SGMatrix< float64_tget_computed_dot_feature_matrix ()
SGVector< float64_tget_computed_dot_feature_vector (int32_t num)
void benchmark_add_to_dense_vector (int32_t repeats=5)
void benchmark_dense_dot_range (int32_t repeats=5)
virtual SGVector< float64_tget_mean ()
virtual SGMatrix< float64_tget_cov ()
- Public Member Functions inherited from CFeatures
 CFeatures (int32_t size=0)
 CFeatures (const CFeatures &orig)
 CFeatures (CFile *loader)
virtual ~CFeatures ()
virtual int32_t add_preprocessor (CPreprocessor *p)
 set preprocessor
virtual CPreprocessordel_preprocessor (int32_t num)
 del current preprocessor
CPreprocessorget_preprocessor (int32_t num)
 get current preprocessor
void set_preprocessed (int32_t num)
bool is_preprocessed (int32_t num)
int32_t get_num_preprocessed ()
 get whether specified preprocessor (or all if num=1) was/were already applied
int32_t get_num_preprocessors () const
void clean_preprocessors ()
int32_t get_cache_size ()
virtual bool reshape (int32_t num_features, int32_t num_vectors)
void list_feature_obj ()
virtual void load (CFile *loader)
virtual void save (CFile *writer)
bool check_feature_compatibility (CFeatures *f)
bool has_property (EFeatureProperty p)
void set_property (EFeatureProperty p)
void unset_property (EFeatureProperty p)
virtual void set_subset (CSubset *subset)
virtual void remove_subset ()
virtual void subset_changed_post ()
index_t subset_idx_conversion (index_t idx) const
bool has_subset () const
virtual CFeaturescopy_subset (SGVector< index_t > indices)
- Public Member Functions inherited from CSGObject
 CSGObject ()
 CSGObject (const CSGObject &orig)
virtual ~CSGObject ()
virtual bool is_generic (EPrimitiveType *generic) const
template<class T >
void set_generic ()
void unset_generic ()
virtual void print_serializable (const char *prefix="")
virtual bool save_serializable (CSerializableFile *file, const char *prefix="")
virtual bool load_serializable (CSerializableFile *file, const char *prefix="")
void set_global_io (SGIO *io)
SGIOget_global_io ()
void set_global_parallel (Parallel *parallel)
Parallelget_global_parallel ()
void set_global_version (Version *version)
Versionget_global_version ()
SGVector< char * > get_modelsel_names ()
char * get_modsel_param_descr (const char *param_name)
index_t get_modsel_param_index (const char *param_name)

Protected Member Functions

void store_normalization_values ()
void store_multi_index ()
void enumerate_multi_index (const int32_t feat_idx, uint16_t **index, uint16_t *exponents, const int32_t degree)
void store_multinomial_coefficients ()
int32_t bico2 (int32_t n, int32_t k)
int32_t bico (int32_t n, int32_t k)
int32_t calc_feature_space_dimensions (int32_t N, int32_t D)
int32_t multinomialcoef (int32_t *exps, int32_t len)
float64_t gammln (float64_t xx)
float64_t factln (int32_t n)
- Protected Member Functions inherited from CDotFeatures
void display_progress (int32_t start, int32_t stop, int32_t v)

Protected Attributes

CSimpleFeatures< float64_t > * m_feat
int32_t m_degree
bool m_normalize
int32_t m_input_dimensions
int32_t m_output_dimensions
uint16_t * m_multi_index
float64_tm_multinomial_coefficients
float32_tm_normalization_values
- Protected Attributes inherited from CDotFeatures
float64_t combined_weight
 feature weighting in combined dot features
- Protected Attributes inherited from CFeatures
CSubsetm_subset

Additional Inherited Members

- Static Public Member Functions inherited from CDotFeatures
static void * dense_dot_range_helper (void *p)
- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters

Constructor & Destructor Documentation

default constructor

Definition at line 5 of file PolyFeatures.cpp.

CPolyFeatures ( CSimpleFeatures< float64_t > *  feat,
int32_t  degree,
bool  normalize 
)

constructor

Parameters
featreal features
degreedegree of the polynomial kernel
normalizenormalize kernel

Definition at line 18 of file PolyFeatures.cpp.

~CPolyFeatures ( )
virtual

Definition at line 40 of file PolyFeatures.cpp.

CPolyFeatures ( const CPolyFeatures orig)

copy constructor

not implemented!

Parameters
origoriginal PolyFeature

Definition at line 48 of file PolyFeatures.cpp.

Member Function Documentation

void add_to_dense_vec ( float64_t  alpha,
int32_t  vec_idx1,
float64_t vec2,
int32_t  vec2_len,
bool  abs_val 
)
virtual

compute alpha*x+vec2

Parameters
alphaalpha
vec_idx1index of first vector x
vec2vec2
vec2_lenlength of vec2
abs_valif true add the absolute value

Implements CDotFeatures.

Definition at line 171 of file PolyFeatures.cpp.

int32_t bico ( int32_t  n,
int32_t  k 
)
protected

efficient implementation for the binomial coefficient function for larger values of k

Definition at line 371 of file PolyFeatures.cpp.

int32_t bico2 ( int32_t  n,
int32_t  k 
)
protected

simple recursive implementation of binomial coefficient which is very efficient if k is small, otherwise it calls a more sophisticated implementation

Definition at line 292 of file PolyFeatures.cpp.

int32_t calc_feature_space_dimensions ( int32_t  N,
int32_t  D 
)
protected

recursion to calculate the dimensions of the feature space: A(N, D)= sum_d=0^D A(N-1, d) A(1, D)==1 A(N, 0)==1 where N is the dimensionality of the input space and D is the degree

Definition at line 317 of file PolyFeatures.cpp.

float64_t dense_dot ( int32_t  vec_idx1,
const float64_t vec2,
int32_t  vec2_len 
)
virtual

compute dot product of vector with index arg1 with an given second vector

Parameters
vec_idx1index of first vector
vec2second vector
vec2_lenlength of second vector

Implements CDotFeatures.

Definition at line 143 of file PolyFeatures.cpp.

float64_t dot ( int32_t  vec_idx1,
CDotFeatures df,
int32_t  vec_idx2 
)
virtual

compute dot product between vector1 and vector2, appointed by their indices

Parameters
vec_idx1index of first vector
dfDotFeatures (of same kind) to compute dot product with
vec_idx2index of second vector

Implements CDotFeatures.

Definition at line 107 of file PolyFeatures.cpp.

CFeatures * duplicate ( ) const
virtual

duplicate feature object

Returns
feature object

Implements CFeatures.

Definition at line 376 of file PolyFeatures.cpp.

void enumerate_multi_index ( const int32_t  feat_idx,
uint16_t **  index,
uint16_t *  exponents,
const int32_t  degree 
)
protected

recursive function enumerating all multi-indices that sum up to the degree of the polynomial kernel

Definition at line 236 of file PolyFeatures.cpp.

float64_t factln ( int32_t  n)
protected

implementation of the ln(x!) function

Definition at line 361 of file PolyFeatures.cpp.

void free_feature_iterator ( void *  iterator)
virtual

clean up iterator call this function with the iterator returned by get_first_feature

Parameters
iteratoras returned by get_first_feature

Implements CDotFeatures.

Definition at line 100 of file PolyFeatures.cpp.

float64_t gammln ( float64_t  xx)
protected

efficient implementation of the ln(gamma(x)) function

Definition at line 345 of file PolyFeatures.cpp.

int32_t get_dim_feature_space ( ) const
virtual

get dimensions of feature space

Returns
dimensions of feature space

Implements CDotFeatures.

Definition at line 54 of file PolyFeatures.cpp.

EFeatureClass get_feature_class ( )
virtual

get feature class

Returns
feature class

Implements CFeatures.

Definition at line 69 of file PolyFeatures.cpp.

void * get_feature_iterator ( int32_t  vector_index)
virtual

iterate over the non-zero features

call get_feature_iterator first, followed by get_next_feature and free_feature_iterator to cleanup

Parameters
vector_indexthe index of the vector over whose components to iterate over
Returns
feature iterator (to be passed to get_next_feature)

Implements CDotFeatures.

Definition at line 88 of file PolyFeatures.cpp.

EFeatureType get_feature_type ( )
virtual

get feature type

Returns
feature type

Implements CFeatures.

Definition at line 64 of file PolyFeatures.cpp.

virtual const char* get_name ( ) const
virtual
Returns
name of class

Implements CSGObject.

Definition at line 105 of file PolyFeatures.h.

bool get_next_feature ( int32_t &  index,
float64_t value,
void *  iterator 
)
virtual

iterate over the non-zero features

call this function with the iterator returned by get_first_feature and call free_feature_iterator to cleanup

Parameters
indexis returned by reference (-1 when not available)
valueis returned by reference
iteratoras returned by get_first_feature
Returns
true if a new non-zero feature got returned

Implements CDotFeatures.

Definition at line 94 of file PolyFeatures.cpp.

int32_t get_nnz_features_for_vector ( int32_t  num)
virtual

get number of non-zero features in vector

Parameters
numindex of vector
Returns
number of non-zero features in vector

Implements CDotFeatures.

Definition at line 59 of file PolyFeatures.cpp.

int32_t get_num_vectors ( ) const
virtual

get number of vectors

Returns
number of vectors

Implements CFeatures.

Definition at line 74 of file PolyFeatures.cpp.

int32_t get_size ( )
virtual
Returns
size

Implements CFeatures.

Definition at line 83 of file PolyFeatures.cpp.

int32_t multinomialcoef ( int32_t *  exps,
int32_t  len 
)
protected

calculate the multinomial coefficient

Definition at line 331 of file PolyFeatures.cpp.

void store_multi_index ( )
protected

caller function for the recursive function enumerate_multi_index

Definition at line 220 of file PolyFeatures.cpp.

void store_multinomial_coefficients ( )
protected

function calculating the multinomial coefficients for all multi indices

Definition at line 264 of file PolyFeatures.cpp.

void store_normalization_values ( )
protected

store the norm of each training example

Definition at line 201 of file PolyFeatures.cpp.

Member Data Documentation

int32_t m_degree
protected

degree of the polynomial kernel

Definition at line 223 of file PolyFeatures.h.

CSimpleFeatures<float64_t>* m_feat
protected

features in original space

Definition at line 221 of file PolyFeatures.h.

int32_t m_input_dimensions
protected

dimensions of the input space

Definition at line 227 of file PolyFeatures.h.

uint16_t* m_multi_index
protected

flattened matrix of all multi indices that sum do the degree of the polynomial kernel

Definition at line 232 of file PolyFeatures.h.

float64_t* m_multinomial_coefficients
protected

multinomial coefficients for all multi-indices

Definition at line 234 of file PolyFeatures.h.

float32_t* m_normalization_values
protected

store norm of each training example

Definition at line 236 of file PolyFeatures.h.

bool m_normalize
protected

normalize

Definition at line 225 of file PolyFeatures.h.

int32_t m_output_dimensions
protected

dimensions of the feature space of the polynomial kernel

Definition at line 229 of file PolyFeatures.h.


The documentation for this class was generated from the following files:

SHOGUN Machine Learning Toolbox - Documentation