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

Feature request: deterministic (Dirac) distribution #1040

Closed
HenriDeh opened this issue Dec 19, 2019 · 4 comments
Closed

Feature request: deterministic (Dirac) distribution #1040

HenriDeh opened this issue Dec 19, 2019 · 4 comments

Comments

@HenriDeh
Copy link

HenriDeh commented Dec 19, 2019

Following this discussion, it appears the package could use a distribution that returns a fixed value.

In physics it is called a Dirac. It would be defined as

struct Dirac{T<:Real} <: ContinuousUnivariateDistribution
    x::T
end

function rand(dist::Dirac)
    return dist.x
end

dist = Dirac(1.0)
rand(dist) #returns 1.0

We should also add a multivariate equivalent where T<:Array{<:Real}

@johnczito
Copy link
Member

A Normal with zero variance behaves this way

julia> d = Normal(4.5, 0.0)
Normal{Float64}=4.5, σ=0.0)

julia> rand(d)
4.5

julia> logpdf(d, 4.5)
Inf

julia> logpdf(d, 5.0)
-Inf

So one approach is just to say

Dirac(x::Real) = Normal(x, zero(x))

@HenriDeh
Copy link
Author

Is it still interesting to define a Dirac struct in the repo ? One would only add the definition you propose and it would suffice

@nickrobinson251
Copy link
Contributor

There's an open PR, and I'm sure help getting it over the line would be appreciated :) https://github.com/JuliaStats/Distributions.jl/pull/861/files

@devmotion
Copy link
Member

Fixed by #1231.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants