11
$\begingroup$

Short version: What's the most computationally efficient method of estimating the mode of a multidimensional data set, sampled from a continuous distribution?

Long version: I've got a data set that I need to estimate the mode of. The mode does not coincide with the mean or median. A sample is shown below, this is a 2D example, but an N-D solution would be better: enter image description here

Currently, my method is

  1. Calculate kernel density estimate on a grid equal to the desired resolution of the mode
  2. Look for the greatest calculated point

Obviously, this calculates the KDE at a lot of non-plausible points, which is especially bad if there are a lot of data points of high dimensions or I expect good resolution on the mode.

An alternate would be to use a simulated annealing, genetic algorithm, etc to find the global peak in the KDE.

The question is whether there's a smarter method of performing this calculation?

$\endgroup$
  • $\begingroup$ I don't know the answer but In think this is a great question. It is hard for me to think of better approaches than the ones you have mentioned. i do think there are differences between the approach to univariate kernel estimation compared to multivariate. This book by David Scott might be helpful regarding the multivariate kernel approach, though I am not sure he discusses peak hunting. amazon.com/… $\endgroup$ – Michael Chernick Aug 3 '12 at 17:52
5
$\begingroup$

The method that would fit the bill for what you want to do is the mean-shift algorithm. Essentially, mean-shift relies on moving along the direction of the gradient, which is estimated non-parametrically with the "shadow", $K'$ of a given kernel $K$. To wit, if the density $f(x)$ is estimated by $K$, then $\nabla f(x)$ is estimated by $K'$. Details of estimating the gradient of a kernel density are described this paper, which also happened to introduce the mean-shift algorithm.

A very detailed exposition on the algorithm is also given in this blog entry.

$\endgroup$
  • 3
    $\begingroup$ Nice references, Larry Wasserman also recently had a shorter post describing the technique in less detail, The Amazing Mean Shift Algorithm. $\endgroup$ – Andy W Aug 3 '12 at 20:20
  • 1
    $\begingroup$ @AndyW Good call! Larry Wasserman's post (and his blog in general) is great. Going through the comments, I found this illustrative reference on mean-shift, mediod-shift and a variant, QuickShift. $\endgroup$ – Sameer Aug 3 '12 at 20:44
  • 2
    $\begingroup$ Thanks. Can't say whether that one is the fastest, but it certainly finds the local maximum. Here are some plots of the trajectory and learning rate on some synthetic data. $\endgroup$ – tkw954 Aug 3 '12 at 22:54
8
$\begingroup$

If your main interest is 2-Dimensional problems, I would say that the kernel density estimation is a good choice because it has nice asymptotical properties (note that I am not saying that it is the best). See for example

Parzen, E. (1962). On estimation of a probability density function and mode. Annals of Mathematical Statistics 33: 1065–1076.

de Valpine, P. (2004). Monte Carlo state space likelihoods by weighted posterior kernel density estimation. Journal of the American Statistical Association 99: 523-536.

For higher dimensions (4+) this method is really slow due to the well-known difficulty in estimating the optimal bandwidth matrix, see.

Now, the problem with the command ks in the package KDE is, as you mentioned, that it evaluates the density in a specific grid which can be very limiting. This issue can be solved if you use the package KDE for estimating the bandwidth matrix, using for example Hscv, implement the Kernel density estimator and then optimise this function using the command optim. This is shown below using simulated data and a Gaussian kernel in R.

rm(list=ls())

# Required packages
library(mvtnorm)
library(ks)

# simulated data
set.seed(1)
dat = rmvnorm(1000,c(0,0),diag(2))

# Bandwidth matrix
H.scv=Hlscv(dat)

# [Implementation of the KDE](http://en.wikipedia.org/wiki/Kernel_density_estimation)
H.eig = eigen(H.scv)
H.sqrt = H.eig$vectors %*% diag(sqrt(H.eig$values)) %*% solve(H.eig$vectors)
H = solve(H.sqrt)
dH = det(H.scv)

Gkde = function(par){
return( -log(mean(dmvnorm(t(H%*%t(par-dat)),rep(0,2),diag(2),log=FALSE)/sqrt(dH))))
}

# Optimisation
Max = optim(c(0,0),Gkde)$par
Max

Shape-restricted estimators tend to be faster, for example

Cule, M. L., Samworth, R. J. and Stewart, M. I. (2010). Maximum likelihood estimation of a multi-dimensional log-concave density. Journal Royal Statistical Society B 72: 545–600.

But they are too peaked for this purpose.

The problem in high dimensions is difficult to attack independently of the method used due to the nature of the question itself. For example, the method propopsed in another answer (mean-shift) is nice but it is known that estimating the derivative of a density is even more difficult that estimating the density itself in terms of the errors (I am not criticising this, just pointing out how difficult this problem is). Then you will probably need thousands of observations for accuarately estimating the mode in dimensions higher than $4$ in non-toy problems.

Other methods that you may consider using are: fitting a multivariate finite mixture of normals (or other flexible distributions) or

Abraham, C., Biau, G. and Cadre, B. (2003). Simple estimation of the mode of a multivariate density. The Canadian Journal of Statistics 31: 23–34.

I hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.