SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions
SGSparseVector< T > Class Template Reference

Detailed Description

template<class T>
class shogun::SGSparseVector< T >

template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is ordered by SGSparseVectorEntry.feat_index in non-decreasing order. This has to be assured by the user of the class.

Definition at line 39 of file SGSparseVector.h.

Inheritance diagram for SGSparseVector< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 SGSparseVector ()
 SGSparseVector (SGSparseVectorEntry< T > *feats, index_t num_entries, bool ref_counting=true)
 SGSparseVector (index_t num_entries, bool ref_counting=true)
 SGSparseVector (const SGSparseVector &orig)
virtual ~SGSparseVector ()
dense_dot (T alpha, T *vec, int32_t dim, T b)
template<typename ST >
dense_dot (SGVector< ST > vec)
sparse_dot (const SGSparseVector< T > &v)
SGSparseVector< T > get ()
int32_t get_num_dimensions ()
void sort_features (bool stable_pointer=false)
get_feature (int32_t index)
SGVector< T > get_dense (int32_t dimension)
SGVector< T > get_dense ()
SGSparseVector< T > clone () const
void load (CFile *loader)
void save (CFile *saver)
void display_vector (const char *name="vector", const char *prefix="")
template<>
void load (CFile *loader)
template<>
void save (CFile *saver)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
template<>
void display_vector (const char *name, const char *prefix)
int32_t ref_count ()

Static Public Member Functions

static T sparse_dot (const SGSparseVector< T > &a, const SGSparseVector< T > &b)

Public Attributes

index_t num_feat_entries
SGSparseVectorEntry< T > * features

Protected Member Functions

virtual void copy_data (const SGReferencedData &orig)
virtual void init_data ()
virtual void free_data ()
void copy_refcount (const SGReferencedData &orig)
int32_t ref ()
int32_t unref ()

Static Protected Member Functions

static int32_t cmp_dot_prod_symmetry_fast (index_t alen, index_t blen)
static T dot_prod_asymmetric (const SGSparseVector< T > &a, const SGSparseVector< T > &b)
static T dot_prod_symmetric (const SGSparseVector< T > &a, const SGSparseVector< T > &b)

Constructor & Destructor Documentation

default constructor

Definition at line 9 of file SGSparseVector.cpp.

SGSparseVector ( SGSparseVectorEntry< T > *  feats,
index_t  num_entries,
bool  ref_counting = true 
)

constructor for setting params

Parameters:
featsvector of SGSparseVectorEntry ordered by SGSparseVectorEntry.feat_index in non-decreasing order
num_entriesnumber of elements in feats vector
ref_countinguse reference counting

Definition at line 15 of file SGSparseVector.cpp.

SGSparseVector ( index_t  num_entries,
bool  ref_counting = true 
)

constructor to create new vector in memory

Definition at line 23 of file SGSparseVector.cpp.

SGSparseVector ( const SGSparseVector< T > &  orig)

copy constructor

Definition at line 31 of file SGSparseVector.cpp.

~SGSparseVector ( ) [virtual]

Definition at line 38 of file SGSparseVector.cpp.


Member Function Documentation

SGSparseVector< T > clone ( ) const

clone vector

Definition at line 269 of file SGSparseVector.cpp.

int32_t cmp_dot_prod_symmetry_fast ( index_t  alen,
index_t  blen 
) [static, protected]

helper function to compute dot product

determines whether symmetric (similar number of non-zero elements in both sparse vectors) or asymetric (logarithmically more elements in one vector) dot product computation routine shall be taken

Parameters:
alenlength of vector a
blenlength of vector b
Returns:
-1,0,1 if asymetric(b,a), symmetric(a,b) respectively asymmetric(a,b) shall be called

Definition at line 329 of file SGSparseVector.cpp.

void copy_data ( const SGReferencedData orig) [protected, virtual]

needs to be overridden to copy data

Implements SGReferencedData.

Definition at line 308 of file SGSparseVector.cpp.

void copy_refcount ( const SGReferencedData orig) [protected, inherited]

copy refcount

Definition at line 58 of file SGReferencedData.cpp.

T dense_dot ( alpha,
T *  vec,
int32_t  dim,
b 
)

compute the dot product between dense weights and a sparse feature vector alpha * sparse^T * w + b

possible with subset

Parameters:
alphascalar to multiply with
vecdense vector to compute dot product with
dimlength of the dense vector
bbias
Returns:
dot product between dense weights and a sparse feature vector

Definition at line 44 of file SGSparseVector.cpp.

T dense_dot ( SGVector< ST >  vec)

compute the dot product between dense weights and a sparse feature vector sparse^T * w

Parameters:
vecdense vector to compute dot product with
Returns:
dot product between dense weights and a sparse feature vector

Definition at line 63 of file SGSparseVector.cpp.

void display_vector ( const char *  name = "vector",
const char *  prefix = "" 
)

display vector

Parameters:
namevector name in output
prefixprepend on every entry
void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 395 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 404 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 413 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 422 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 431 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 440 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 449 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 458 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 467 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 476 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 485 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 494 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 503 of file SGSparseVector.cpp.

void display_vector ( const char *  name,
const char *  prefix 
)

Definition at line 512 of file SGSparseVector.cpp.

T dot_prod_asymmetric ( const SGSparseVector< T > &  a,
const SGSparseVector< T > &  b 
) [static, protected]

compute dot product between vectors a and b

particularly fast if len(a) << len(b)

Parameters:
avector a
bvector b
Returns:
dot product

Definition at line 342 of file SGSparseVector.cpp.

T dot_prod_symmetric ( const SGSparseVector< T > &  a,
const SGSparseVector< T > &  b 
) [static, protected]

compute dot product between vectors a and b

particularly fast if len(a) ~= len(b)

Parameters:
avector a
bvector b
Returns:
dot product

Definition at line 360 of file SGSparseVector.cpp.

void free_data ( ) [protected, virtual]

needs to be overridden to free data

Implements SGReferencedData.

Definition at line 322 of file SGSparseVector.cpp.

get the sparse vector (no copying is done here)

Returns:
the refcount increased vector

Definition at line 106 of file SGSparseVector.h.

SGVector< T > get_dense ( int32_t  dimension)

get dense representation of given size

Parameters:
dimensionof requested dense vector
Returns:
SGVector<T>

Definition at line 249 of file SGSparseVector.cpp.

SGVector< T > get_dense ( )

get shortet dense representation for sparse vector

Returns:
SGVector<T>

Definition at line 230 of file SGSparseVector.cpp.

T get_feature ( int32_t  index)

get feature value for index

Parameters:
index
Returns:
value

Definition at line 216 of file SGSparseVector.cpp.

int32_t get_num_dimensions ( )

get number of dimensions

Returns:
largest feature index

Definition at line 114 of file SGSparseVector.cpp.

void init_data ( ) [protected, virtual]

needs to be overridden to initialize empty data

Implements SGReferencedData.

Definition at line 315 of file SGSparseVector.cpp.

void load ( CFile loader)

load vector from file

Parameters:
loaderFile object via which to load data

Definition at line 276 of file SGSparseVector.cpp.

void load ( CFile loader)

Definition at line 296 of file SGSparseVector.cpp.

int32_t ref ( ) [protected, inherited]

increase reference counter

Returns:
reference count

Definition at line 67 of file SGReferencedData.cpp.

int32_t ref_count ( ) [inherited]

display reference counter

Returns:
reference count

Definition at line 44 of file SGReferencedData.cpp.

void save ( CFile saver)

save vector to file

Parameters:
saverFile object via which to save data

Definition at line 286 of file SGSparseVector.cpp.

void save ( CFile saver)

Definition at line 302 of file SGSparseVector.cpp.

void sort_features ( bool  stable_pointer = false)

sort features by indices (Setting stable_pointer=true to guarantee that pointer features does not change. On the other hand, stable_pointer=false can shrink the vector if possible.)

Parameters:
stable_pointer(default false) enforce stable pointer

Definition at line 132 of file SGSparseVector.cpp.

T sparse_dot ( const SGSparseVector< T > &  v)

compute the dot product between current sparse vector and a given sparse vector. sparse_a^T * sparse_b

Parameters:
vsparse vector
Returns:
dot product between the current sparse vector and v sparse vector

Definition at line 86 of file SGSparseVector.cpp.

T sparse_dot ( const SGSparseVector< T > &  a,
const SGSparseVector< T > &  b 
) [static]

compute the dot product between two sparse vectors. sparse_a^T * sparse_b

Parameters:
asparse vector
bsparse vector
Returns:
dot product between a and b

Definition at line 92 of file SGSparseVector.cpp.

int32_t unref ( ) [protected, inherited]

decrement reference counter and deallocate object if refcount is zero before or after decrementing it

Returns:
reference count

Definition at line 87 of file SGReferencedData.cpp.


Member Data Documentation

features

Definition at line 223 of file SGSparseVector.h.

number of feature entries

Definition at line 220 of file SGSparseVector.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation