sparse-matrix

How to iterate over non zero values in a sparse matrix with COLT?

走远了吗. 提交于 2019-12-24 12:08:18
问题 The code example on the COLT website shows: DoubleFactory2D factory; factory = DoubleFactory2D.sparse; DoubleMatrix2D matrix = factory.make(3,4); for (int row = matrix.rows(); --row >= 0;) { for (int column = matrix.columns(); --column >= 0;) { value = matrix.getQuick(row, column); } } but this does not take advantage of the sparsity of the matrix. I'd like to iterate over non zero values only. 来源: https://stackoverflow.com/questions/44655457/how-to-iterate-over-non-zero-values-in-a-sparse

Cache management for sparse matrix multiplication using OpenMP

你说的曾经没有我的故事 提交于 2019-12-24 11:53:27
问题 I am having issues with what I think is some false caching, I am only getting a small speedup when using the following code compared to not the unparalleled version. matrix1 and matrix2 are sparse matrices in a struct with (row, col, val) format. void pMultiply(struct SparseRow *matrix1, struct SparseRow *matrix2, int m1Rows, int m2Rows, struct SparseRow **result) { *result = malloc(1 * sizeof(struct SparseRow)); int resultNonZeroEntries = 0; #pragma omp parallel for atomic for(int i = 0; i <

How to do elementwise multiplication between a sparse and a dense tensors in tensorflow?

时光毁灭记忆、已成空白 提交于 2019-12-24 11:43:47
问题 Tensorflow has the implementation tf.sparse_tensor_dense_matmul of sparse to dense matrix multiplication, but does it have sparse to dense elementwise multiplication (the two tensors having the same shape)? I would like to avoid converting my sparse tensor to a dense one as it wouldn't fit in memory. 回答1: I don't believe there is a built-in function, but you can do this by hand relatively easily, at least if you don't intend to support broadcasting. If x and y are resp. your sparse and dense

How to order sparse matrix and store the result

家住魔仙堡 提交于 2019-12-24 11:12:05
问题 I have a big sparse matrix: > str(qtr_sim) Formal class 'dsCMatrix' [package "Matrix"] with 7 slots ..@ i : int [1:32395981] 0 1 2 3 4 5 6 7 8 1 ... ..@ p : int [1:28182] 0 1 2 3 4 5 6 7 8 9 ... ..@ Dim : int [1:2] 28181 28181 ..@ Dimnames:List of 2 .. ..$ : chr [1:28181] "1000191" "1000404" "1000457" "1000541" ... .. ..$ : chr [1:28181] "1000191" "1000404" "1000457" "1000541" ... ..@ x : num [1:32395981] 1 1 1 1 1 ... ..@ uplo : chr "U" ..@ factors : list() The matrix contains values of

hstack csr matrix with pandas array

眉间皱痕 提交于 2019-12-24 10:19:52
问题 I am doing an exercise on Amazon Reviews, Below is the code. Basically I am not able to add column (pandas array) to CSR Matrix which i got after applying BoW. Even though the number of rows in both matrices matches i am not able to get through. import sqlite3 import pandas as pd import numpy as np import nltk import string import matplotlib.pyplot as plt import seaborn as sns import scipy from sklearn.feature_extraction.text import TfidfTransformer from sklearn.feature_extraction.text import

Split up ngrams in (sparse) document-feature matrix

别等时光非礼了梦想. 提交于 2019-12-24 08:30:10
问题 This is a follow up question to this one. There, I asked if it's possible to split up ngram-features in a document-feature matrix (dfm-class from the quanteda-package) in such a way that e.g. bigrams result in two separate unigrams. For better understanding: I got the ngrams in the dfm from translating the features from German to English. Compounds ("Emissionsminderung") are quiet common in German but not in English ("emission reduction"). library(quanteda) eg.txt <- c('increase in_the great

Sparse precomputed Gram matrices in sklearn svm?

一曲冷凌霜 提交于 2019-12-24 08:14:32
问题 I'd like to pass a sparse precomputed Gram matrix to sklearn.svm.SVC.fit. Here's some working code: import numpy as np from sklearn import svm X = np.array([[0, 0], [1, 1]]) y = [0, 1] clf = svm.SVC(kernel='precomputed') gram = np.dot(X, X.T) clf.fit(gram, y) But if I have: from scipy.sparse import csr_matrix sparse_gram = csr_matrix(gram) clf.fit(sparse_gram, y) I get: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/sklearn

How can I accelerate a sparse matrix by dense vector product, currently implemented via scipy.sparse.csc_matrix.dot, using CUDA?

旧时模样 提交于 2019-12-24 07:38:52
问题 My ultimate goal is to accelerate the computation of a matrix-vector product in Python, potentially by using a CUDA-enabled GPU. The matrix A is about 15k x 15k and sparse (density ~ 0.05), and the vector x is 15k elements and dense, and I am computing Ax. I have to perform this computation many times, so making it as fast as possible would be ideal. My current non-GPU “optimization” is to represent A as a scipy.sparse.csc_matrix object, and then simply computing A.dot(x), but I was hoping to

Create Pandas DataFrame from (row, column, value) data

橙三吉。 提交于 2019-12-24 07:24:31
问题 I have a Pandas Dataframe with three columns: row, column, value. The row values are all integers below some N , and the column values are all integers below some M . The values are all positive integers. How do I efficiently create a Dataframe with N rows and M columns, with at index i, j the value val if (i, j , val) is a row in my original Dataframe, and some default value ( 0 ) otherwise? Furthermore, is it possible to create a sparse Dataframe immediately, since the data is already quite

Java N-Dimensional Sparse Matrix

混江龙づ霸主 提交于 2019-12-24 07:24:08
问题 I have a 4-dimensional huge sparse matrix and I need to know the best data structure to manage my information using Java. I read from this topic Sparse matrices / arrays in Java and it says that Tries is better than Hash Tables when matrix is so formatted. Unluckly the most authoritative answer talks about 2D-dimension matrices and I haven't found anything about N-dimensional ones. Thank you in advance for your reply 来源: https://stackoverflow.com/questions/29379577/java-n-dimensional-sparse