18 index_t num_vec,
bool ref_counting) :
51 template <>
template <>
57 "Dimension mismatch! %d vs %d\n",
64 template <>
template <>
70 "Dimension mismatch! %d vs %d\n",
77 template <>
template <>
83 "Dimension mismatch! %d vs %d\n",
104 SG_SERROR(
"SGSparseMatrix::load():: Not supported for complex128_t");
117 if (do_sort_features)
139 SG_SERROR(
"SGSparseMatrix::save():: Not supported for complex128_t");
146 int32_t num=labels.
vlen;
202 int32_t* index=SG_CALLOC(int32_t, num_features);
211 int32_t vidx=sv.
features[i].feat_index;
213 sfm[vidx].features[index[vidx]].feat_index=fidx;
214 sfm[vidx].features[index[vidx]].entry=sv.
features[i].entry;
238 REQUIRE(num_vec>0,
"Matrix should have > 0 vectors!\n");
240 SG_SINFO(
"converting dense feature matrix to sparse one\n")
241 int32_t* num_feat_entries=SG_MALLOC(
int, num_vec);
244 int64_t num_total_entries=0;
247 for (int32_t i=0; i<num_vec; i++)
249 num_feat_entries[i]=0;
250 for (int32_t j=0; j<num_feat; j++)
252 if (src[i*((int64_t) num_feat) + j] != static_cast<T>(0))
253 num_feat_entries[i]++;
261 for (int32_t i=0; i< num_vec; i++)
264 int32_t sparse_feat_idx=0;
266 for (int32_t j=0; j< num_feat; j++)
268 int64_t pos= i*num_feat + j;
270 if (src[pos] != static_cast<T>(0))
280 SG_SINFO(
"sparse feature matrix has %ld entries (full matrix had %ld, sparsity %2.2f%%)\n",
281 num_total_entries, int64_t(num_feat)*num_vec, (100.0*num_total_entries)/(int64_t(num_feat)*num_vec));
282 SG_FREE(num_feat_entries);
template class SGSparseMatrix
virtual void set_sparse_matrix(const SGSparseVector< bool > *matrix, int32_t num_feat, int32_t num_vec)
void save_with_labels(CLibSVMFile *saver, SGVector< float64_t > labels)
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
virtual void set_sparse_matrix(const SGSparseVector< bool > *matrix, int32_t num_feat, int32_t num_vec)
index_t num_vectors
total number of vectors
virtual void copy_data(const SGReferencedData &orig)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
virtual ~SGSparseMatrix()
shogun reference count managed data
const SGVector< T > operator*(SGVector< T > v) const
A File access base class.
index_t num_features
total number of features
void from_dense(SGMatrix< T > full)
all of classes and functions are contained in the shogun namespace
read sparse real valued features in svm light format e.g. -1 1:10.0 2:100.2 1000:1.3 with -1 == (optional) label and dim 1 - value 10.0 dim 2 - value 100.2 dim 1000 - value 1.3
SGSparseMatrix< T > get_transposed()
SGVector< float64_t > load_with_labels(CLibSVMFile *libsvm_file, bool do_sort_features=true)
virtual void get_sparse_matrix(SGSparseVector< bool > *&matrix, int32_t &num_feat, int32_t &num_vec)
virtual void get_sparse_matrix(SGSparseVector< bool > *&matrix, int32_t &num_feat, int32_t &num_vec)
SGSparseVectorEntry< T > * features