Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for univariate von Mises distribution #223

Merged
merged 8 commits into from
Jun 23, 2014
Merged

Add support for univariate von Mises distribution #223

merged 8 commits into from
Jun 23, 2014

Conversation

jdrugo
Copy link
Contributor

@jdrugo jdrugo commented Apr 27, 2014

Adding a univariate von Mises distribution makes sense on top of the already available multivariante von Mises-Fisher distribution, if only for more efficient sampling from this distribution.

I have not yet included test scripts for this distribution, as doing so would require the use of circular statistics, which are not yet available in standard packages. The same applies to distribution fitting.

The initial implementation supports standard moments, pdf, cdf, and drawing
samples.

To support large concentrations, the scaled bessel function implementation
had to be used. This scaled version is currently not supported in Base,
such that its support is currently added only for the von Mises distribution.
Added description of constructors to univariate distribution
documentation. Also, renamed support to helper functions in vonmises.jl
end

## Helper functions
# Bessel function as in Base/math.jl, but with exponential scaling
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function would be more appropriate in Base.

@jdrugo
Copy link
Contributor Author

jdrugo commented Apr 27, 2014

Indeed, it should be in Base, but is not yet available. See JuliaLang/julia#6665

I have added it here temporarily, until it becomes available in Base.


type AmosException <: Exception
info::Int32
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than redefining these, you can just import them from Base.Math.

The support of the distribution was not defined, as AngularDistribution or
CircularDistribution class does not exist, yet.
@lindahua
Copy link
Contributor

@jdrugo Would you please incorporate latest changes in the master? Latest refactoring has substantial changes to many files, which makes this unmergeable in this form.

@lindahua lindahua added this to the v0.6 milestone Jun 20, 2014
@jdrugo
Copy link
Contributor Author

jdrugo commented Jun 20, 2014

@lindahua I currently do not have access to my computer, but will update the files at the beginning of the next week.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 54df12d on jdrugo:addvonmises into e200dc9 on JuliaStats:master.

@jdrugo
Copy link
Contributor Author

jdrugo commented Jun 23, 2014

The code is now updated in the light of the recent refactoring of Distributions.jl. It defines circmean, circvar, ... instead of mean, var, ... until a better solution is found (e.g. #224, even though this does not solve the issue of mean(rand(d, n)) not converging to mean(d) for large n).

Sampling from VonMises involves pre-computing some constants. Thus, it might make sense to write a separate VonMisesSampler. I can do this before a merge, if required.

@lindahua
Copy link
Contributor

Yes, please add the sampler. My suggestion is

  • add a samplers/vonmises.jl file, and introduce a sampler as
immutable VonMisesSampler <: Sampleable{Univariate,Continuous}
# cache some pre-computable quantities
...

function rand(s::VonMisesSampler)
     # move the sampling code here
end

and move the sampling code there.

  • add a statement like the following in univariate/vonmises.jl:
sampler(d::VonMises) = VonMisesSampler( ... )

Other than that, it looks good to me.

Introduced VonMisesSampler and VonMisesNormalApproxSampler. The latter cannot
be replaced by a Normal sampler, as VonMisesNormalApproxSampler additionally
ensures thatt he returned samples are within [0, 2pi].
@jdrugo
Copy link
Contributor Author

jdrugo commented Jun 23, 2014

I added both a VonMisesSampler and a VonMisesNormalApproxSampler for an efficient sampling of highly concentrated von Mises densities. Otherwise, the changes were implemented as suggested.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling eb5853f on jdrugo:addvonmises into e200dc9 on JuliaStats:master.

lindahua added a commit that referenced this pull request Jun 23, 2014
Add support for univariate von Mises distribution
@lindahua lindahua merged commit 9b897a2 into JuliaStats:master Jun 23, 2014
@lindahua
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: new distribution Feature request for a new distribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants