How to get probability density functions (PDF) for an $N \times D$ matrix?

529 Views Asked by At

Suppose we have an N x D matrix, as follows:

import numpy as np
X1 = np.matrix('1 2 3; 4 5 6;  0 0 -1, 0 0 -2')

I found an online example to compute pdf for each row of X1 as follows:

from scipy import stats
PDFs = stats.norm.pdf(X1, loc=0.0, scale=1.0)

Above line of code gives a matrix of same size as X1, i.e., N x D. It appears that above line of code has computed pdf for each point of each sample row. However, I am not sure what it did and if it even makes any sense.

This is another online example which find probability mass function (PMF) for a single sample row list (I have an N x D data matrix):

tries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # 0 to 10
X2 = stats.binom.pmf(tries, 10, 0.5)
S = np.sum(X2, axis = 0)

I am looking for a way to find pdfs for each sample row of N x D data matrix so that output pdfs will be of the same size N x D. However, I am not sure if it will make any sense as a right representation of original data matrix? I could compute KDE, on the data, but that would give me an N x 1 densities (i.e., equal to the number of sample size of evaluation matrix).

Does the output of $PDFs = stats.norm.pdf(X1, loc=0.0, scale=1.0)$ represent evaluated densities (pdfs) on each sample row? I am looking for a way to compute N x D matrix of densities. In KDE one first computes kde on some train dataset so that bandwidth can be optimized, and after that one can evaluate kde on any test dataset; the output is an N x 1 array of densities. So I tried to evaluate densities by applying above scipy function which actually gave me a N x D matrix, but I am not sure what is it. Does it represent actual data?