|
SHOGUN
4.1.0
|
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 29 of file base/Parameter.h.

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 () |
| T | dense_dot (T alpha, T *vec, int32_t dim, T b) |
| template<typename ST > | |
| T | dense_dot (SGVector< ST > vec) |
| T | sparse_dot (const SGSparseVector< T > &v) |
| SGSparseVector< T > | get () |
| int32_t | get_num_dimensions () |
| void | sort_features (bool stable_pointer=false) |
| bool | is_sorted () const |
| T | 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 | add_to_dense (T alpha, T *vec, int32_t dim, bool abs_val=false) |
| 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 T | dot_prod_expensive_unsorted (const SGSparseVector< T > &a, const SGSparseVector< T > &b) |
| SGSparseVector | ( | ) |
default constructor
Definition at line 23 of file SGSparseVector.cpp.
| SGSparseVector | ( | SGSparseVectorEntry< T > * | feats, |
| index_t | num_entries, | ||
| bool | ref_counting = true |
||
| ) |
constructor for setting params
| feats | vector of SGSparseVectorEntry ordered by SGSparseVectorEntry.feat_index in non-decreasing order |
| num_entries | number of elements in feats vector |
| ref_counting | use reference counting |
Definition at line 29 of file SGSparseVector.cpp.
| SGSparseVector | ( | index_t | num_entries, |
| bool | ref_counting = true |
||
| ) |
constructor to create new vector in memory
Definition at line 37 of file SGSparseVector.cpp.
| SGSparseVector | ( | const SGSparseVector< T > & | orig | ) |
copy constructor
Definition at line 45 of file SGSparseVector.cpp.
|
virtual |
Definition at line 52 of file SGSparseVector.cpp.
| void add_to_dense | ( | T | alpha, |
| T * | vec, | ||
| int32_t | dim, | ||
| bool | abs_val = false |
||
| ) |
add a sparse feature vector onto a dense one dense += alpha*sparse
| alpha | scalar to multiply with |
| vec | dense vector |
| dim | length of the dense vector |
| abs_val | if true, do dense+=alpha*abs(sparse) |
Definition at line 78 of file SGSparseVector.cpp.
| SGSparseVector< T > clone | ( | ) | const |
clone vector
Definition at line 354 of file SGSparseVector.cpp.
|
protectedvirtual |
needs to be overridden to copy data
Implements SGReferencedData.
Definition at line 393 of file SGSparseVector.cpp.
|
protectedinherited |
copy refcount
Definition at line 55 of file SGReferencedData.cpp.
| T dense_dot | ( | T | alpha, |
| T * | vec, | ||
| int32_t | dim, | ||
| T | b | ||
| ) |
compute the dot product between dense weights and a sparse feature vector alpha * sparse^T * w + b
possible with subset
| alpha | scalar to multiply with |
| vec | dense vector to compute dot product with |
| dim | length of the dense vector |
| b | bias |
Definition at line 58 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
| vec | dense vector to compute dot product with |
Definition at line 100 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name = "vector", |
| const char * | prefix = "" |
||
| ) |
display vector
| name | vector name in output |
| prefix | prepend on every entry |
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 438 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 451 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 464 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 477 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 490 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 516 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 529 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 542 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 555 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 568 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 581 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 594 of file SGSparseVector.cpp.
| void display_vector | ( | const char * | name, |
| const char * | prefix | ||
| ) |
Definition at line 607 of file SGSparseVector.cpp.
|
staticprotected |
helper function to compute dot product for unsorted sparse vectors
You should not use this at all, since computational complexity is in O(n^2)
| a | vector a |
| b | vector b |
Definition at line 414 of file SGSparseVector.cpp.
|
protectedvirtual |
needs to be overridden to free data
Implements SGReferencedData.
Definition at line 407 of file SGSparseVector.cpp.
| SGSparseVector<T> get | ( | ) |
get the sparse vector (no copying is done here)
Definition at line 107 of file SGSparseVector.h.
| SGVector< T > get_dense | ( | int32_t | dimension | ) |
get dense representation of given size
| dimension | of requested dense vector |
Definition at line 334 of file SGSparseVector.cpp.
| SGVector< T > get_dense | ( | ) |
get shortet dense representation for sparse vector
Definition at line 315 of file SGSparseVector.cpp.
| T get_feature | ( | int32_t | index | ) |
get feature value for index
| index |
Definition at line 298 of file SGSparseVector.cpp.
| int32_t get_num_dimensions | ( | ) |
get number of dimensions
Definition at line 167 of file SGSparseVector.cpp.
|
protectedvirtual |
needs to be overridden to initialize empty data
Implements SGReferencedData.
Definition at line 400 of file SGSparseVector.cpp.
| bool is_sorted | ( | ) | const |
Utility function to tell if feature indices are sorted
Definition at line 279 of file SGSparseVector.cpp.
| void load | ( | CFile * | loader | ) |
load vector from file
| loader | File object via which to load data |
Definition at line 361 of file SGSparseVector.cpp.
| void load | ( | CFile * | loader | ) |
Definition at line 381 of file SGSparseVector.cpp.
|
protectedinherited |
increase reference counter
Definition at line 64 of file SGReferencedData.cpp.
|
inherited |
display reference counter
Definition at line 41 of file SGReferencedData.cpp.
| void save | ( | CFile * | saver | ) |
save vector to file
| saver | File object via which to save data |
Definition at line 371 of file SGSparseVector.cpp.
| void save | ( | CFile * | saver | ) |
Definition at line 387 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.)
| stable_pointer | (default false) enforce stable pointer |
Definition at line 188 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
| v | sparse vector |
Definition at line 123 of file SGSparseVector.cpp.
|
static |
compute the dot product between two sparse vectors. sparse_a^T * sparse_b
| a | sparse vector |
| b | sparse vector |
Definition at line 129 of file SGSparseVector.cpp.
|
protectedinherited |
decrement reference counter and deallocate object if refcount is zero before or after decrementing it
Definition at line 84 of file SGReferencedData.cpp.
| SGSparseVectorEntry<T>* features |
features
Definition at line 215 of file SGSparseVector.h.
| index_t num_feat_entries |
number of feature entries
Definition at line 212 of file SGSparseVector.h.