Why does ksdensity return density value of 0?
2 次查看(过去 30 天)
显示 更早的评论
I'm using ksdensity function to estimate the densities of my data, but I have a problem.
[f,xi] = ksdensity(data,pts,'Support','unbounded')
I used the support for desnity as unbound, which allows the density to extend over the whole real line. (as described in the documentation)
I was expecting to get value as small as possible, but it doesn't return values smaller than 1e-19.
It seems like the smallest floating point-number Matlab can give is 2.2251e-308.
f = realmin;
% f = 2.2251e-308
I'm curious as to why this is the case.
回答(1 个)
Sandeep
2023-12-21
Hi Naomi Gray,
It is my understanding that you are using 'ksdensity' function to estimate density for a univariate or bivariate data and you are facing difficulties in achieving lower density values.
The behavior you're observing is due to the numerical limitations of floating-point arithmetic in MATLAB, as well as the inherent properties of the 'ksdensity' function.
It is important to understand that while MATLAB's smallest positive normalized floating-point number is indeed approximately 2.2251e-308, the results from functions like ksdensity are affected by both the algorithm's numerical stability and precision limits.
The ksdensity function uses kernel smoothing to estimate the probability density function of a random variable. The 'Support' is specified as 'unbounded' by default, allows the density estimation to extend over the entire real line.
In practice, the density values at the tails of the distribution are expected to be very small, and due to the limitations of floating-point representation, they may reach a point where they are effectively considered zero. The value of 1e-19 that you're observing is likely a practical lower bound for the density estimates given the data and bandwidth used in the kernel density estimation.
I hope it helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!