File Exchange

image thumbnail

Log Probability Density Function (PDF)

version (4.01 KB) by Mo Chen
numerically stable pdf of popular distributions in log scale.


Updated 13 Mar 2016

View License

Directly computing pdf of distributions often leads to numerical underflow, especially when dealing with high dimensional data. Therefore, the pdf functions provided by Matlab is not very useful for real world problems.
This pack provides numerical stable pdf of popular distributions in log scale, which can be used as building blocks for probabilistic modeling.

Currently this package is now a part of the PRML toolbox (

Cite As

Mo Chen (2021). Log Probability Density Function (PDF) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Matt Falcy

Correcting a typo:

The calculated log-scale density does not always match calculations using R's dnorm().

For example,
logGauss(7,8,10) = -2.120231079701695
Whereas in R, dnorm(7,8,10,log=TRUE) = -3.226524

Yet logGauss and dnorm can return identical values
logGauss(2,1,1) = dnorm(2,1,1,log=TRUE) = -1.418938533204673

I further note that logGauss does not have the same functionality as MATLAB's normpdf(x,mu,sigma). If you have vector x and vector mu, but scalar sigma, then you need to create a matrix for sigma. It might look like this diag(repmat(sigma,[length(x),1])). This is not necessary with normpdf(x,mu,sigma).

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Pattern Recognition and Machine Learning Toolbox

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!