sparse-matrix

Allocate disk space for multiple file downloads in Java

拜拜、爱过 提交于 2019-12-10 11:36:18
问题 Is there any way of reliably "allocating" (reserving) hard disk space via "standard" Java (J2SE 5 or later)? Take for example the case of a multithreaded application, executing in a thread pool, where every thread downloads files. How can the application make sure that its download won't be interrupted as a result of disk space exhaustion? At least, if it knows beforehand the size of the file it is downloading, can it do some sort of "reservation", which would guarantee file download,

Parallel Cosine similarity of two large files with each other

混江龙づ霸主 提交于 2019-12-10 11:12:51
问题 I have two files: A and B A has 400,000 lines each having 50 float values B has 40,000 lines having 50 float values. For every line in B, I need to find corresponding lines in A which have >90% similarity (cosine). For linear search and computation, the code takes ginormous computing time. (40-50 hours) Reaching out to the community for suggestions on how to fasten the process (link of blogs/resources such as AWS/Cloud to be used to achieve it). Have been stuck with this for quite a while!

Use Redis to generate unique ID from a limited range

☆樱花仙子☆ 提交于 2019-12-10 10:55:28
问题 I have database items that, in addition to their primary key, need an index unique to the group in which the items belong. Let's call the property nbr , and the property that groups items together and defines the scope of unique nbr :s we'll call group . This nbr must be in the [1-N] range, and may be set when items are imported from an external source. Since all items must have a nbr , the task then becomes how to track which values are used, to enable picking a free nbr for new items that

How to create a diagonal sparse matrix in SciPy

不打扰是莪最后的温柔 提交于 2019-12-10 10:14:47
问题 I am trying to create a sparse matrix which has a 2D pattern run down the diagonal. This is probably easiest to explain with a quick example. Say my pattern is: [1,0,2,0,1]... I want to create a sparse matrix: [[2,0,1,0,0,0,0...0], [0,2,0,1,0,0,0...0], [1,0,2,0,1,0,0...0], [0,1,0,2,0,1,0...0], [0,0,1,0,2,0,1...0], [...]] The scipy.sparse.dia_matrix seems like a good candidate, however, I simply cannot figure out how to accomplish what I want from the documentation available. Thank you in

convert simple triplet matrix(slam) to sparse matrix(Matrix) in R

匆匆过客 提交于 2019-12-10 02:24:45
问题 Is there a built-in function in either slam package or Matrix package to convert a sparse matrix in simple triplet matrix form (from slam package) to a sparse matrix in dgTMatrix/dgCMatrix form (from Matrix package) ? And is there a built-in way to access non-zero entries from simple triplet matrix ? I'm working in R 回答1: Actually, there is a built-in way: simple_triplet_matrix_sparse <- sparseMatrix(i=simple_triplet_matrix_sparse$i, j=simple_triplet_matrix_sparse$j, x=simple_triplet_matrix

R: sparse matrix multiplication with data.table and quanteda package?

给你一囗甜甜゛ 提交于 2019-12-10 00:52:24
问题 I am trying to create a matrix mulptiplication with sparse matrix and with the package called quanteda, utilising data.table package, related to this thread here. So require(quanteda) mytext <- c("Let the big dogs hunt", "No holds barred", "My child is an honor student") myMatrix <-dfm(mytext, ignoredFeatures = stopwords("english"), stem = TRUE) #a data.table as.matrix(myMatrix) %*% transpose(as.matrix(myMatrix)) how can you get the matrix multiplication working here with quanteda package and

When writing an R package that uses the Matrix package, why do I have to specify Matrix::t() instead of just t()?

五迷三道 提交于 2019-12-09 18:06:04
问题 Consider the following simple functions defined in an R session: nathanvan@nathanvan-N61Jq:~$ R R version 3.0.1 (2013-05-16) -- "Good Sport" ... snip ... > make.a.Matrix <- function(data, nrow, ncol) { + require(Matrix) + return( Matrix(data, nrow=nrow, ncol=ncol)) + } > > transpose.a.Matrix <- function(data, nrow, ncol ) { + return(t( make.a.Matrix(data, nrow=nrow, ncol=ncol) )) + } > > make.a.Matrix(1:12, 3, 4) Loading required package: Matrix Loading required package: lattice 3 x 4 Matrix

Efficiently accumulating a collection of sparse scipy matrices

自古美人都是妖i 提交于 2019-12-09 18:00:39
问题 I've got a collection of O(N) NxN scipy.sparse.csr_matrix , and each sparse matrix has on the order of N elements set. I want to add all these matrices together to get a regular NxN numpy array. (N is on the order of 1000). The arrangement of non-zero elements within the matrices is such that the resulting sum certainly isn't sparse (virtually no zero elements left in fact). At the moment I'm just doing reduce(lambda x,y: x+y,[m.toarray() for m in my_sparse_matrices]) which works but is a bit

Matlab: First Non-zero element of each row or column

情到浓时终转凉″ 提交于 2019-12-09 16:26:38
问题 For example, A = [ -1 0 -2 0 0 2 8 0 1 0 0 0 3 0 -2 0 -3 2 0 0 1 2 0 0 -4]; how can I get a vector of the first nonzero elements of each row? 回答1: You can use max : >> [sel, c] = max( A ~=0, [], 2 ); Rows for which sel equalse zero - are all zeros and the corresponding column in c should be ignored. Result: >> [sel c]= max( A~=0, [], 2 ) sel = 1 1 1 1 1 c = 1 1 3 2 1 In order to find the first non-zero row index (for each column) you just need to apply max on the first dimension: >> [sel r] =

Scipy's sparse eigsh() for small eigenvalues

巧了我就是萌 提交于 2019-12-09 16:14:06
问题 I'm trying to write a spectral clustering algorithm using NumPy/SciPy for larger (but still tractable) systems, making use of SciPy's sparse linear algebra library. Unfortunately, I'm running into stability issues with eigsh(). Here's my code: import numpy as np import scipy.sparse import scipy.sparse.linalg as SLA import sklearn.utils.graph as graph W = self._sparse_rbf_kernel(self.X_, self.datashape) D = scipy.sparse.csc_matrix(np.diag(np.array(W.sum(axis = 0))[0])) L = graph.graph