Code covered by the BSD License  

Highlights from
vmrand(fMu, fKappa, varargin)

5.0 | 1 rating Rate this file 20 Downloads (last 30 days) File Size: 5.17 KB File ID: #37241 Version: 1.1

vmrand(fMu, fKappa, varargin)


Dylan Muir (view profile)


19 Jun 2012 (Updated )

Draw random numbers from the Von Mises distribution

| Watch this File

File Information

This function uses an envelope-rejection method based on a wrapped Cauchy distribution to draw random variates from an arbitrary Von Mises distribution, first proposed in [1].
'fMu' and 'fKappa' are the mean and variance parameter of the Von Mises distribution over [-pi, pi). 'tVMVariates' will be a tensor containing random variates drawn from the defined distribution. If 'fMu' and 'fKappa' are non-scalar, then they must be the same size. In this case 'tVMVariates' will be the same size. If 'fMu' and 'fKappa' are scalar, then the number of variates returned can be specified as extra arguments.
If only single dimension 'M' is provided, then the return argument 'tfVMVariates' will be M x M.
This implementation is vectorised, and requires O(7.5*N) space.
[1] D. J. Best and N. I. Fisher, 1979. "Efficient Simulation of the von Mises Distribution", Journal of the Royal Statistical Society. Series C (Applied Statistics), Vol. 28, No. 2, pp. 152-157.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
08 Dec 2014 Dylan Muir

Dylan Muir (view profile)

Dear Mr M.,
thanks for your feedback. I have updated the code and fixed the bug. Please let me know if you still receive the error.

Best regards,

Comment only
07 Dec 2014 Mr M.

Mr M. (view profile)

Sometimes I've got the following error:

Error using .*
Matrix dimensions must agree.

Error in vmrand (line 148)
tfVMVariates(tbDraw & tbAccept) = sign(rand(nNumToAccept, 1) - 0.5)
.* acos(tfF(tbDraw & tbAccept));

Comment only
07 Dec 2014 Mr M.

Mr M. (view profile)

08 Dec 2014 1.1

Fixed bugs, where providing non-scalar parameters would sometimes cause an error message.

Contact us