Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/univariate/discrete/discretenonparametric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ function modes(d::DiscreteNonParametric)
end

function mgf(d::DiscreteNonParametric, t::Real)
x, p = params(d)
x = support(d)
p = probs(d)
s = zero(Float64)
for i in 1:length(x)
s += p[i] * exp(t*x[i])
Expand All @@ -224,7 +225,8 @@ function mgf(d::DiscreteNonParametric, t::Real)
end

function cf(d::DiscreteNonParametric, t::Real)
x, p = params(d)
x = support(d)
p = probs(d)
s = zero(Complex{Float64})
for i in 1:length(x)
s += p[i] * cis(t*x[i])
Expand Down
6 changes: 6 additions & 0 deletions test/univariate/discrete/categorical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ for p in Any[
@test pdf.(d, support(d)) == p
@test pdf.(d, 1:k) == p

@test cf(d, 0) ≈ 1.0
@test cf(d, 1) ≈ p' * cis.(1:length(p))

@test mgf(d, 0) ≈ 1.0
@test mgf(d, 1) ≈ p' * exp.(1:length(p))

# The test utilities are currently only able to handle Float64s
if partype(d) === Float64
test_distr(d, 10^6)
Expand Down