sparse-matrix

Representing Sparse Data in PostgreSQL

人走茶凉 提交于 2019-12-03 05:04:33
问题 What's the best way to represent a sparse data matrix in PostgreSQL? The two obvious methods I see are: Store data in a single a table with a separate column for every conceivable feature (potentially millions), but with a default value of NULL for unused features. This is conceptually very simple, but I know that with most RDMS implementations, that this is typically very inefficient, since the NULL values ususually takes up some space. However, I read an article (can't find its link

Python: how do you store a sparse matrix using python?

不羁岁月 提交于 2019-12-03 03:13:34
I have got an output using sparse matrix in python, i need to store this sparse matrix in my hard disk, how can i do it? if i should create a database then how should i do?? this is my code: import nltk import cPickle import numpy from scipy.sparse import lil_matrix from nltk.corpus import wordnet as wn from nltk.corpus import brown f = open('spmatrix.pkl','wb') def markov(L): count=0 c=len(text1) for i in range(0,c-2): h=L.index(text1[i]) k=L.index(text1[i+1]) mat[h,k]=mat[h,k]+1//matrix cPickle.dump(mat,f,-1) text = [w for g in brown.categories() for w in brown.words(categories=g)] text1

Scipy sparse matrices - purpose and usage of different implementations

时间秒杀一切 提交于 2019-12-03 02:19:53
问题 Scipy has many different types of sparse matrices available. What are the most important differences between these types, and what is the difference in their intended usage? I'm developing a code in python based on a sample code 1 in Matlab. One section of the code utilizes sparse matrices - which seem to have a single (annoying) type in Matlab, and I'm trying to figure out which type I should use 2 in python. 1: This is for a class. Most people are doing the project in Matlab, but I like to

Fortran 90/95 library for sparse matrices?

拜拜、爱过 提交于 2019-12-03 02:06:15
I am looking for a library for dealing with sparse matrices in fortran 90/95. I only need very basic operations like matrix-vector multiplication. What do you suggest I use? I have searched around and an extension(?) to BLAS called "sparse blas", documented in chapter 3 of the blast technical forum specification: http://www.netlib.org/blas/blast-forum/ , seems ideal. According to that document, there should be a fortran 95 interface to the library. However, I haven't been able to find an actual implementation of this specification anywhere that I was able to download. I am kind of getting the

another Game of Life question (infinite grid)?

放肆的年华 提交于 2019-12-03 01:55:50
I have been playing around with Conway's Game of life and recently discovered some amazingly fast implementations such as Hashlife and Golly. (download Golly here - http://golly.sourceforge.net/ ) One thing that I cant get my head around is how do coders implement the infinite grid? We can't keep an infinite array of anything, if you run golly and get a few gliders to fly off past the edges, wait for a few mins and zoom right out, you will see the gliders still there out in space running away, so how in gods name is this concept of infinity dealt with programmatically? Is there a well

Optimising Python dictionary access code

拥有回忆 提交于 2019-12-03 01:08:16
问题 Question: I've profiled my Python program to death, and there is one function that is slowing everything down. It uses Python dictionaries heavily, so I may not have used them in the best way. If I can't get it running faster, I will have to re-write it in C++, so is there anyone who can help me optimise it in Python? I hope I've given the right sort of explanation, and that you can make some sense of my code! Thanks in advance for any help. My code: This is the offending function, profiled

slicing sparse (scipy) matrix

被刻印的时光 ゝ 提交于 2019-12-02 19:38:28
I would appreciate any help, to understand following behavior when slicing a lil_matrix (A) from the scipy.sparse package. Actually, I would like to extract a submatrix based on an arbitrary index list for both rows and columns. When I used this two lines of code: x1 = A[list 1,:] x2 = x1[:,list 2] Everything was fine and I could extract the right submatrix. When I tried to do this in one line, it failed (The returning matrix was empty) x=A[list 1,list 2] Why is this so? Overall, I have used a similar command in matlab and there it works. So, why not use the first, since it works? It seems to

How to use tf.nn.embedding_lookup_sparse in TensorFlow?

别来无恙 提交于 2019-12-02 18:39:20
We have tried using tf.nn.embedding_lookup and it works. But it needs dense input data and now we need tf.nn.embedding_lookup_sparse for sparse input. I have written the following code but get some errors. import tensorflow as tf import numpy as np example1 = tf.SparseTensor(indices=[[4], [7]], values=[1, 1], shape=[10]) example2 = tf.SparseTensor(indices=[[3], [6], [9]], values=[1, 1, 1], shape=[10]) vocabulary_size = 10 embedding_size = 1 var = np.array([0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0]) #embeddings = tf.Variable(tf.ones([vocabulary_size, embedding_size])) embeddings =

R convert matrix or data frame to sparseMatrix

时间秒杀一切 提交于 2019-12-02 17:30:24
I have a regular matrix (non-sparse) that I would like to convert to a sparseMatrix (using the Matrix package). Is there a function to do this or do I need to do a bunch of loops? ex. > regMat <- matrix(0, nrow=10, ncol=10) > regMat[3,5] <- round(runif(1),2)*100 > regMat[2,8] <- round(runif(1),2)*100 > regMat[8,4] <- round(runif(1),2)*100 > regMat[1,6] <- round(runif(1),2)*100 > regMat[7,4] <- round(runif(1),2)*100 > regMat [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 49 0 0 0 0 [2,] 0 0 0 0 0 0 0 93 0 0 [3,] 0 0 0 0 20 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0

Using sparse matrices with Keras and Tensorflow

安稳与你 提交于 2019-12-02 17:14:17
My data can be viewed as a matrix of 10B entries (100M x 100), which is very sparse (< 1/100 * 1/100 of entries are non-zero). I would like to feed the data into into a Keras Neural Network model which I have made, using a Tensorflow backend. My first thought was to expand the data to be dense, that is, write out all 10B entries into a series of CSVs, with most entries zero. However, this is quickly overwhelming my resources (even doing the ETL overwhelmed pandas and is causing postgres to struggle). So I need to use true sparse matrices. How can I do that with Keras (and Tensorflow)? While