diff --git a/src/univariate/discrete/discretenonparametric.jl b/src/univariate/discrete/discretenonparametric.jl index 55dbcef87..d94c63aa1 100644 --- a/src/univariate/discrete/discretenonparametric.jl +++ b/src/univariate/discrete/discretenonparametric.jl @@ -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]) @@ -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]) diff --git a/test/univariate/discrete/categorical.jl b/test/univariate/discrete/categorical.jl index 0288c2dcd..28da03615 100644 --- a/test/univariate/discrete/categorical.jl +++ b/test/univariate/discrete/categorical.jl @@ -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)