SHOGUN  v3.2.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 
SGSparseVector.h
浏览该文件的文档.
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) 2013 Thoralf Klein
8  * Written (W) 2012 Fernando José Iglesias García
9  * Written (W) 2010,2012 Soeren Sonnenburg
10  * Copyright (C) 2010 Berlin Institute of Technology
11  * Copyright (C) 2012 Soeren Sonnenburg
12  */
13 
14 #ifndef __SGSPARSEVECTOR_H__
15 #define __SGSPARSEVECTOR_H__
16 
17 #include <shogun/lib/config.h>
18 #include <shogun/lib/DataType.h>
20 
21 namespace shogun
22 {
23  class CFile;
24 
26 template <class T> struct SGSparseVectorEntry
27 {
31  T entry;
32 };
33 
39 template <class T> class SGSparseVector : public SGReferencedData
40 {
41 public:
44 
51  SGSparseVector(SGSparseVectorEntry<T>* feats, index_t num_entries,
52  bool ref_counting=true);
53 
55  SGSparseVector(index_t num_entries, bool ref_counting=true);
56 
58  SGSparseVector(const SGSparseVector& orig);
59 
60  virtual ~SGSparseVector();
61 
73  T dense_dot(T alpha, T* vec, int32_t dim, T b);
74 
81  template<typename ST> T dense_dot(SGVector<ST> vec);
82 
90  T sparse_dot(const SGSparseVector<T>& v);
91 
99  static T sparse_dot(const SGSparseVector<T>& a, const SGSparseVector<T>& b);
100 
106  inline SGSparseVector<T> get()
107  {
108  return *this;
109  }
110 
116  int32_t get_num_dimensions();
117 
126  void sort_features(bool stable_pointer = false);
127 
134  T get_feature(int32_t index);
135 
142  SGVector<T> get_dense(int32_t dimension);
143 
150 
152  SGSparseVector<T> clone() const;
153 
158  void load(CFile* loader);
159 
164  void save(CFile* saver);
165 
166 
172  void display_vector(const char* name="vector",
173  const char* prefix="");
174 
175 protected:
176  virtual void copy_data(const SGReferencedData& orig);
177 
178  virtual void init_data();
179 
180  virtual void free_data();
181 
194  static int32_t cmp_dot_prod_symmetry_fast(index_t alen, index_t blen);
195 
205  static T dot_prod_asymmetric(const SGSparseVector<T>& a, const SGSparseVector<T>& b);
206 
216  static T dot_prod_symmetric(const SGSparseVector<T>& a, const SGSparseVector<T>& b);
217 
218 public:
221 
224 
225 };
226 
227 }
228 
229 #endif // __SGSPARSEVECTOR_H__
static T dot_prod_symmetric(const SGSparseVector< T > &a, const SGSparseVector< T > &b)
void sort_features(bool stable_pointer=false)
T sparse_dot(const SGSparseVector< T > &v)
int32_t index_t
Definition: common.h:60
virtual void copy_data(const SGReferencedData &orig)
void display_vector(const char *name="vector", const char *prefix="")
static int32_t cmp_dot_prod_symmetry_fast(index_t alen, index_t blen)
void save(CFile *saver)
shogun reference count managed data
A File access base class.
Definition: File.h:34
SGSparseVectorEntry< T > * features
T dense_dot(T alpha, T *vec, int32_t dim, T b)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
template class SGSparseVectorEntry
Definition: File.h:23
static T dot_prod_asymmetric(const SGSparseVector< T > &a, const SGSparseVector< T > &b)
T get_feature(int32_t index)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
SGVector< T > get_dense()
SGSparseVector< T > clone() const
void load(CFile *loader)

SHOGUN Machine Learning Toolbox - Documentation