Commit 712e054f authored by Dahua Lin's avatar Dahua Lin

add generic function: nsamples

This is useful for generic algorithms that work on arbitrary types of
distributions (e.g. fitting a finite mixture model).
parent cc190c7a
......@@ -120,6 +120,7 @@ export # types
moment, # moments of distribution
# mueta, # derivative of inverse link function
# mustart, # starting values of mean vector in GLMs
nsamples, # get the number of samples in a data array based on distribution types
pdf, # probability density function (ContinuousDistribution)
pmf, # probability mass function (DiscreteDistribution)
quantile, # inverse of cdf (defined for p in (0,1))
......
......@@ -4,6 +4,11 @@
#
##############################################################################
# generic function to get number of samples
nsamples{D<:UnivariateDistribution}(dt::Type{D}, x::Array) = length(x)
nsamples{D<:MultivariateDistribution}(dt::Type{D}, x::Matrix) = size(x, 2)
nsamples{D<:MatrixDistribution,T}(dt::Type{D}, x::Array{Matrix{T}}) = length(x)
#### Statistics ####
......
......@@ -135,6 +135,7 @@ for d in [Arcsine(),
# check that we can generate many random draws at once
x = rand(d, n)
@test nsamples(typeof(d), x) == n
# check that sequence of draws satifies insupport()
@test insupport(d, x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment