matrix-multiplication

numerically stable way to multiply log probability matrices in numpy

青春壹個敷衍的年華 提交于 2019-12-20 10:18:41
问题 I need to take the matrix product of two NumPy matrices (or other 2d arrays) containing log probabilities. The naive way np.log(np.dot(np.exp(a), np.exp(b))) is not preferred for obvious reasons. Using from scipy.misc import logsumexp res = np.zeros((a.shape[0], b.shape[1])) for n in range(b.shape[1]): # broadcast b[:,n] over rows of a, sum columns res[:, n] = logsumexp(a + b[:, n].T, axis=1) works but runs about 100 times slower than np.log(np.dot(np.exp(a), np.exp(b))) Using logsumexp((tile

Can I stably invert a Vandermonde matrix with many small values in R?

爱⌒轻易说出口 提交于 2019-12-20 07:55:11
问题 updated on this question: I have closed this question and I will post a new question focus on R package Rmpfr. To conclude this question and to help others, I will post my codes of the inverse of a Vandermonde Matrix from its explicit inverse formula. The generation terms are the x's in [here]1. I am not a skilled programmer. Therefore I don't expect my codes to be the most efficient one. I post the codes here because it is better than nothing. library(gtools) #input is the generation vector

MPI Matrix Multiplication with scatter gather

梦想与她 提交于 2019-12-20 05:59:36
问题 I'm trying to do matrix multiplication using MPI in C and we have to do a version that sequential and one parallel version. My parallel version is not giving the correct answers and I'm not sure why. I think I'm not sending the right communications to the processes but I can't be sure. The professor just went over the different send/receive/gather etc messages, but didn't really get into much detail... I've seen a lot of different examples but none complete and none using scatter/gather. If

Multiplying 3D matrix with 2D matrix

大城市里の小女人 提交于 2019-12-20 04:27:06
问题 I have two matrices to multiply. One is weight matrix - W whose size is 900x2x2 . Another is input matrix-I whose size is 2x2 . Now I want to perform summation over c = WI which will be 900x1 matrix, but when I perform the operation it multiplies and gives me 900x2x2 matrix again. Q 2) (related) So I made both of them 2D and multiplied 900x4 * 4x1 but that gives me an error saying ValueError:operands could not be broadcast together with shapes (900,4) (4,1) 回答1: It seems you are trying to

How to use image and weight matrix to create adversarial images in TensorFlow?

核能气质少年 提交于 2019-12-19 11:34:28
问题 In the Breaking Linear Classifiers on ImageNet blog post, the author presented a very simple example on how to modify an image to fool a classifier. The technique given is pretty simple: xad = x + 0.5w where x is the 1d vector and w is the 1d weight. This is all good and clear. However, I am trying to implement this with the MNIST dataset and got stuck, with no idea how to turn this simple idea into actual results. I'd like to know how to use the known w matrix to modify a given x matrix (or

Matrix multiplication time complexity in MATLAB

梦想的初衷 提交于 2019-12-19 06:51:34
问题 Does anyone know which algorithm MATLAB uses for matrix multiplication and what is its time complexity? 回答1: For completeness -- as mentioned in this thread, Matlab uses the DGEMM (Double GEneral Matrix Multiplication) routine from BLAS (Basic Linear Algebra Subprograms). Note that there is not one single implementation of BLAS - it is tuned for particular processor architectures. Therefore you cannot be absolutely certain which algorithm is being used on your machine without finding out

Matrix multiplication time complexity in MATLAB

ぐ巨炮叔叔 提交于 2019-12-19 06:51:10
问题 Does anyone know which algorithm MATLAB uses for matrix multiplication and what is its time complexity? 回答1: For completeness -- as mentioned in this thread, Matlab uses the DGEMM (Double GEneral Matrix Multiplication) routine from BLAS (Basic Linear Algebra Subprograms). Note that there is not one single implementation of BLAS - it is tuned for particular processor architectures. Therefore you cannot be absolutely certain which algorithm is being used on your machine without finding out

Element-wise matrix multiplication in NumPy

不羁岁月 提交于 2019-12-19 02:28:11
问题 I'm making my first real foray into Python and NumPy to do some image processing. I have an image loaded as a 3 dimensional NumPy Array, where axis 0 represents image bands, while axes 1 and 2 represent columns and rows of pixels. From this, I need to take the 3x1 matrix representing each pixel and perform a few operations which result in another 3x1 matrix, which will be used to build a results image. My first approach (simplified and with random data) looks like this: import numpy as np

Matlab matrix multiplication speed

不想你离开。 提交于 2019-12-19 02:27:46
问题 I was wondering how can matlab multiply two matrices so fast. When multiplying two NxN matrices, N^3 multiplications are performed. Even with the Strassen Algorithm it takes N^2.8 multiplications, which is still a large number. I was running the following test program: a = rand(2160); b = rand(2160); tic;a*b;toc 2160 was used because 2160^3=~10^10 ( a*b should be about 10^10 multiplications) I got: Elapsed time is 1.164289 seconds. (I'm running on 2.4Ghz notebook and no threading occurs)

Matlab matrix multiplication speed

牧云@^-^@ 提交于 2019-12-19 02:27:08
问题 I was wondering how can matlab multiply two matrices so fast. When multiplying two NxN matrices, N^3 multiplications are performed. Even with the Strassen Algorithm it takes N^2.8 multiplications, which is still a large number. I was running the following test program: a = rand(2160); b = rand(2160); tic;a*b;toc 2160 was used because 2160^3=~10^10 ( a*b should be about 10^10 multiplications) I got: Elapsed time is 1.164289 seconds. (I'm running on 2.4Ghz notebook and no threading occurs)