sparse-matrix

large-scale regression in R with a sparse feature matrix

你说的曾经没有我的故事 提交于 2019-11-28 05:07:10
I'd like to do large-scale regression (linear/logistic) in R with many (e.g. 100k) features, where each example is relatively sparse in the feature space---e.g., ~1k non-zero features per example. It seems like the SparseM package slm should do this, but I'm having difficulty converting from the sparseMatrix format to a slm -friendly format. I have a numeric vector of labels y and a sparseMatrix of features X \in {0,1}. When I try model <- slm(y ~ X) I get the following error: Error in model.frame.default(formula = y ~ X) : invalid type (S4) for variable 'X' presumably because slm wants a

How to get a big sparse matrix in R? (> 2^31-1)

◇◆丶佛笑我妖孽 提交于 2019-11-28 05:01:07
问题 I use some C++ code to take a text file from a database and create a dgcMatrix type sparse matrix from the Matrix package. For the first time, I'm trying to build a matrix that has more than 2^31-1 non-sparse members, which means that the index vector in the sparse matrix object must also be longer than that limit. Unfortunately, vectors seem to use 32-bit integer indices, as do NumericVectors in Rcpp. Short of writing an entire new data type from the ground up, does R provide any facility

cryptic scipy “could not convert integer scalar” error

独自空忆成欢 提交于 2019-11-28 04:24:54
问题 I am constructing a sparse vector using a scipy.sparse.csr_matrix like so: csr_matrix((values, (np.zeros(len(indices)), indices)), shape = (1, max_index)) This works fine for most of my data, but occasionally I get a ValueError: could not convert integer scalar . This reproduces the problem: In [145]: inds Out[145]: array([ 827969148, 996833913, 1968345558, 898183169, 1811744124, 2101454109, 133039182, 898183170, 919293479, 133039089]) In [146]: vals Out[146]: array([ 1., 1., 1., 1., 1., 2.,

How expensive is it to compute the eigenvalues of a matrix?

空扰寡人 提交于 2019-11-28 04:22:23
How expensive is it to compute the eigenvalues of a matrix? What is the complexity of the best algorithms? How long might it take in practice if I have a 1000 x 1000 matrix? I assume it helps if the matrix is sparse? Are there any cases where the eigenvalue computation would not terminate? In R , I can compute the eigenvalues as in the following toy example: m<-matrix( c(13,2, 5,4), ncol=2, nrow=2 ) eigen(m, only.values=1) $values [1] 14 3 Does anyone know what algorithm it uses? Are there any other (open-source) packages that compute the eigenvalue? Most of the algorithms for eigen value

Use coo_matrix in TensorFlow

こ雲淡風輕ζ 提交于 2019-11-28 02:18:52
问题 I'm doing a Matrix Factorization in TensorFlow, I want to use coo_matrix from Spicy.sparse cause it uses less memory and it makes it easy to put all my data into my matrix for training data. Is it possible to use coo_matrix to initialize a variable in tensorflow? Or do I have to create a session and feed the data I got into tensorflow using sess.run() with feed_dict. I hope that you understand my question and my problem otherwise comment and i will try to fix it. 回答1: The closest thing

Set row of csr_matrix

拜拜、爱过 提交于 2019-11-28 02:10:02
问题 I have a sparse csr_matrix, and I want to change the values of a single row to different values. I can't find an easy and efficient implementation however. This is what it has to do: A = csr_matrix([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) new_row = np.array([-1, -1, -1]) print(set_row_csr(A, 2, new_row).todense()) >>> [[ 0, 1, 0], [ 1, 0, 1], [-1, -1, -1]] This is my current implementation of set_row_csr : def set_row_csr(A, row_idx, new_row): A[row_idx, :] = new_row return A But this gives me a

Sparse Matrix from a dense one Tensorflow

拜拜、爱过 提交于 2019-11-27 23:57:01
I am creating a convolutional sparse autoencoder and I need to convert a 4D matrix full of values (whose shape is [samples, N, N, D] ) into a sparse matrix. For each sample, I have D NxN feature maps. I want to convert each NxN feature map to a sparse matrix, with the maximum value mapped to 1 and all the others to 0. I do not want to do this at run time but during the Graph declaration (because I need to use the resulting sparse matrix as an input to other graph operations), but I do not understand how to get the indices to build the sparse matrix. You can use tf.where and tf.gather_nd to do

Converting Tensor to a SparseTensor for ctc_loss [duplicate]

南楼画角 提交于 2019-11-27 23:08:35
问题 This question already has answers here : Sparse Matrix from a dense one Tensorflow (2 answers) Closed last year . Is there a way to convert a dense tensor into a sparse tensor? Apparently, Tensorflow's Estimator.fit doesn't accept SparseTensors as labels. One reason I would like to pass SparseTensors into Tensorflow's Estimator.fit is to be able to use tensorflow ctc_loss. Here's the code: import dataset_utils import tensorflow as tf import numpy as np from tensorflow.contrib import grid_rnn,

Scipy.sparse.csr_matrix: How to get top ten values and indices?

谁说胖子不能爱 提交于 2019-11-27 22:57:47
I have a large csr_matrix and I am interested in the top ten values and their indices each row. But I did not find a decent way to manipulate the matrix. Here is my current solution and the main idea is to process them row by row: row = csr_matrix.getrow(row_number).toarray()[0].ravel() top_ten_indicies = row.argsort()[-10:] top_ten_values = row[row.argsort()[-10:]] By doing this, the advantages of csr_matrix is not fully used. It's more like a brute force solution. hpaulj I don't see what the advantages of csr format are in this case. Sure, all the nonzero values are collected in one .data

SVD for sparse matrix in R

社会主义新天地 提交于 2019-11-27 22:22:29
I've got a sparse Matrix in R that's apparently too big for me to run as.matrix() on (though it's not super-huge either). The as.matrix() call in question is inside the svd() function, so I'm wondering if anyone knows a different implementation of SVD that doesn't require first converting to a dense matrix. The irlba package has a very fast SVD implementation for sparse matrices. You can do a very impressive bit of sparse SVD in R using random projection as described in http://arxiv.org/abs/0909.4061 Here is some sample code: # computes first k singular values of A with corresponding singular