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

Dirac: Implement location, scale, affine transformation #1735

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/univariate/discrete/dirac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ External links:

* [Dirac measure on Wikipedia](http://en.wikipedia.org/wiki/Dirac_measure)
"""
struct Dirac{T} <: DiscreteUnivariateDistribution
struct Dirac{T<:Real} <: DiscreteUnivariateDistribution
i9e1 marked this conversation as resolved.
Show resolved Hide resolved
value::T
end

Expand All @@ -29,6 +29,9 @@ minimum(d::Dirac) = d.value
maximum(d::Dirac) = d.value
support(d::Dirac) = (d.value,)

location(d::Dirac) = d.value
scale(d::Dirac{T}) where {T} = one(T)
i9e1 marked this conversation as resolved.
Show resolved Hide resolved

#### Properties
mean(d::Dirac) = d.value
var(d::Dirac{T}) where {T} = zero(T)
Expand All @@ -53,6 +56,11 @@ mgf(d::Dirac, t) = exp(t * d.value)
cgf(d::Dirac, t) = t*d.value
cf(d::Dirac, t) = cis(t * d.value)

#### Affine transformation
Base.:+(d::Dirac, c::Real) = Dirac(d.value + c)
Base.:+(a::Dirac, b::Dirac) = Dirac(a.value + b.value)
i9e1 marked this conversation as resolved.
Show resolved Hide resolved
Base.:*(c::Real, d::Dirac) = Dirac(c * d.value)

#### Sampling

rand(rng::AbstractRNG, d::Dirac) = d.value
Loading