Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
femtocleaner[bot] committed Aug 8, 2017
1 parent ebeab79 commit 9bfe801
Show file tree
Hide file tree
Showing 90 changed files with 689 additions and 699 deletions.
12 changes: 6 additions & 6 deletions perf/samplers.jl
Expand Up @@ -6,17 +6,17 @@ using Distributions
### define benchmark tasks

@compat abstract type UnivariateSamplerRun{Spl} <: Proc end
type BatchSamplerRun{Spl} <: UnivariateSamplerRun{Spl} end
type IndivSamplerRun{Spl} <: UnivariateSamplerRun{Spl} end
mutable struct BatchSamplerRun{Spl} <: UnivariateSamplerRun{Spl} end
mutable struct IndivSamplerRun{Spl} <: UnivariateSamplerRun{Spl} end

const batch_unit = 1000

Base.isvalid(::UnivariateSamplerRun, cfg) = true
Base.length(p::UnivariateSamplerRun, cfg) = batch_unit
Base.string{Spl}(p::UnivariateSamplerRun{Spl}) = getname(Spl)
Base.string(p::UnivariateSamplerRun{Spl}) where {Spl} = getname(Spl)

Base.start{Spl}(p::BatchSamplerRun{Spl}, cfg) = getsampler(Spl, cfg)
Base.start{Spl}(p::IndivSamplerRun{Spl}, cfg) = ()
Base.start(p::BatchSamplerRun{Spl}, cfg) where {Spl} = getsampler(Spl, cfg)
Base.start(p::IndivSamplerRun{Spl}, cfg) where {Spl} = ()
Base.done(p::UnivariateSamplerRun, cfg, s) = nothing

getsampler{Spl<:Sampleable}(::Type{Spl}, cfg) = Spl(cfg...)
Expand All @@ -27,7 +27,7 @@ function Base.run(p::BatchSamplerRun, cfg, s)
end
end

function Base.run{Spl}(p::IndivSamplerRun{Spl}, cfg, s)
function Base.run(p::IndivSamplerRun{Spl}, cfg, s) where Spl
for i = 1:batch_unit
rand(getsampler(Spl,cfg))
end
Expand Down
16 changes: 8 additions & 8 deletions src/common.jl
@@ -1,13 +1,13 @@
## sample space/domain

@compat abstract type VariateForm end
type Univariate <: VariateForm end
type Multivariate <: VariateForm end
type Matrixvariate <: VariateForm end
mutable struct Univariate <: VariateForm end
mutable struct Multivariate <: VariateForm end
mutable struct Matrixvariate <: VariateForm end

@compat abstract type ValueSupport end
type Discrete <: ValueSupport end
type Continuous <: ValueSupport end
mutable struct Discrete <: ValueSupport end
mutable struct Continuous <: ValueSupport end

Base.eltype(::Type{Discrete}) = Int
Base.eltype(::Type{Continuous}) = Float64
Expand Down Expand Up @@ -42,9 +42,9 @@ The default element type of a sample. This is the type of elements of the sample
by the `rand` method. However, one can provide an array of different element types to
store the samples using `rand!`.
"""
Base.eltype{F,S}(s::Sampleable{F,S}) = eltype(S)
Base.eltype{F}(s::Sampleable{F,Discrete}) = Int
Base.eltype{F}(s::Sampleable{F,Continuous}) = Float64
Base.eltype(s::Sampleable{F,S}) where {F,S} = eltype(S)
Base.eltype(s::Sampleable{F,Discrete}) where {F} = Int
Base.eltype(s::Sampleable{F,Continuous}) where {F} = Float64

"""
nsamples(s::Sampleable)
Expand Down
12 changes: 6 additions & 6 deletions src/edgeworth.jl
Expand Up @@ -9,11 +9,11 @@
skewness(d::EdgeworthAbstract) = skewness(d.dist) / sqrt(d.n)
kurtosis(d::EdgeworthAbstract) = kurtosis(d.dist) / d.n

immutable EdgeworthZ{D<:UnivariateDistribution} <: EdgeworthAbstract
struct EdgeworthZ{D<:UnivariateDistribution} <: EdgeworthAbstract
dist::D
n::Float64

function (::Type{EdgeworthZ{D}}){D<:UnivariateDistribution,T<:UnivariateDistribution}(d::T, n::Real)
function (::Type{EdgeworthZ{D}})(d::T, n::Real) where {D<:UnivariateDistribution,T<:UnivariateDistribution}
@check_args(EdgeworthZ, n > zero(n))
new{D}(d, n)
end
Expand Down Expand Up @@ -74,10 +74,10 @@ end


# Edgeworth approximation of the sum
immutable EdgeworthSum{D<:UnivariateDistribution} <: EdgeworthAbstract
struct EdgeworthSum{D<:UnivariateDistribution} <: EdgeworthAbstract
dist::D
n::Float64
function (::Type{EdgeworthSum{D}}){D<:UnivariateDistribution,T<:UnivariateDistribution}(d::T, n::Real)
function (::Type{EdgeworthSum{D}})(d::T, n::Real) where {D<:UnivariateDistribution,T<:UnivariateDistribution}
@check_args(EdgeworthSum, n > zero(n))
new{D}(d, n)
end
Expand All @@ -88,10 +88,10 @@ mean(d::EdgeworthSum) = d.n*mean(d.dist)
var(d::EdgeworthSum) = d.n*var(d.dist)

# Edgeworth approximation of the mean
immutable EdgeworthMean{D<:UnivariateDistribution} <: EdgeworthAbstract
struct EdgeworthMean{D<:UnivariateDistribution} <: EdgeworthAbstract
dist::D
n::Float64
function (::Type{EdgeworthMean{D}}){D<:UnivariateDistribution,T<:UnivariateDistribution}(d::T, n::Real)
function (::Type{EdgeworthMean{D}})(d::T, n::Real) where {D<:UnivariateDistribution,T<:UnivariateDistribution}
# although n would usually be an integer, no methods are require this
n > zero(n) ||
error("n must be positive")
Expand Down
2 changes: 1 addition & 1 deletion src/empirical.jl
Expand Up @@ -4,7 +4,7 @@
#
##############################################################################

immutable EmpiricalUnivariateDistribution <: ContinuousUnivariateDistribution
struct EmpiricalUnivariateDistribution <: ContinuousUnivariateDistribution
values::Vector{Float64}
support::Vector{Float64}
cdf::Function
Expand Down
10 changes: 5 additions & 5 deletions src/estimators.jl
Expand Up @@ -5,11 +5,11 @@ export nsamples, estimate

@compat abstract type Estimator{D<:Distribution} end

nsamples{D<:UnivariateDistribution}(e::Estimator{D}, x::Array) = length(x)
nsamples{D<:MultivariateDistribution}(e::Estimator{D}, x::Matrix) = size(x, 2)
nsamples(e::Estimator{D}, x::Array) where {D<:UnivariateDistribution} = length(x)
nsamples(e::Estimator{D}, x::Matrix) where {D<:MultivariateDistribution} = size(x, 2)

type MLEstimator{D<:Distribution} <: Estimator{D} end
mutable struct MLEstimator{D<:Distribution} <: Estimator{D} end
MLEstimator{D<:Distribution}(::Type{D}) = MLEstimator{D}()

estimate{D<:Distribution}(e::MLEstimator{D}, x) = fit_mle(D, x)
estimate{D<:Distribution}(e::MLEstimator{D}, x, w) = fit_mle(D, x, w)
estimate(e::MLEstimator{D}, x) where {D<:Distribution} = fit_mle(D, x)
estimate(e::MLEstimator{D}, x, w) where {D<:Distribution} = fit_mle(D, x, w)
14 changes: 7 additions & 7 deletions src/genericfit.jl
@@ -1,6 +1,6 @@
# generic functions for distribution fitting

function suffstats{D<:Distribution}(dt::Type{D}, xs...)
function suffstats(dt::Type{D}, xs...) where D<:Distribution
argtypes = tuple(D, map(typeof, xs)...)
error("suffstats is not implemented for $argtypes.")
end
Expand All @@ -24,11 +24,11 @@ Here, `w` should be an array with length `n`, where `n` is the number of samples
"""
fit_mle(D, x, w)

fit_mle{D<:UnivariateDistribution}(dt::Type{D}, x::AbstractArray) = fit_mle(D, suffstats(D, x))
fit_mle{D<:UnivariateDistribution}(dt::Type{D}, x::AbstractArray, w::AbstractArray) = fit_mle(D, suffstats(D, x, w))
fit_mle(dt::Type{D}, x::AbstractArray) where {D<:UnivariateDistribution} = fit_mle(D, suffstats(D, x))
fit_mle(dt::Type{D}, x::AbstractArray, w::AbstractArray) where {D<:UnivariateDistribution} = fit_mle(D, suffstats(D, x, w))

fit_mle{D<:MultivariateDistribution}(dt::Type{D}, x::AbstractMatrix) = fit_mle(D, suffstats(D, x))
fit_mle{D<:MultivariateDistribution}(dt::Type{D}, x::AbstractMatrix, w::AbstractArray) = fit_mle(D, suffstats(D, x, w))
fit_mle(dt::Type{D}, x::AbstractMatrix) where {D<:MultivariateDistribution} = fit_mle(D, suffstats(D, x))
fit_mle(dt::Type{D}, x::AbstractMatrix, w::AbstractArray) where {D<:MultivariateDistribution} = fit_mle(D, suffstats(D, x, w))

fit{D<:Distribution}(dt::Type{D}, x) = fit_mle(D, x)
fit{D<:Distribution}(dt::Type{D}, args...) = fit_mle(D, args...)
fit(dt::Type{D}, x) where {D<:Distribution} = fit_mle(D, x)
fit(dt::Type{D}, args...) where {D<:Distribution} = fit_mle(D, args...)
4 changes: 2 additions & 2 deletions src/genericrand.jl
Expand Up @@ -77,14 +77,14 @@ rand(s::Sampleable{Multivariate}, n::Int) =

# matrix-variate

function _rand!{M<:Matrix}(s::Sampleable{Matrixvariate}, X::AbstractArray{M})
function _rand!(s::Sampleable{Matrixvariate}, X::AbstractArray{M}) where M<:Matrix
for i in 1:length(X)
X[i] = rand(s)
end
return X
end

rand!{M<:Matrix}(s::Sampleable{Matrixvariate}, X::AbstractArray{M}) =
rand!(s::Sampleable{Matrixvariate}, X::AbstractArray{M}) where {M<:Matrix} =
_rand!(s, X)

rand(s::Sampleable{Matrixvariate}, n::Int) =
Expand Down
8 changes: 4 additions & 4 deletions src/matrix/inversewishart.jl
Expand Up @@ -5,15 +5,15 @@ The [Inverse Wishart distribution](http://en.wikipedia.org/wiki/Inverse-Wishart_
is usually used a the conjugate prior for the covariance matrix of a multivariate normal
distribution, which is characterized by a degree of freedom ν, and a base matrix Φ.
"""
immutable InverseWishart{T<:Real, ST<:AbstractPDMat} <: ContinuousMatrixDistribution
struct InverseWishart{T<:Real, ST<:AbstractPDMat} <: ContinuousMatrixDistribution
df::T # degree of freedom
Ψ::ST # scale matrix
c0::T # log of normalizing constant
end

#### Constructors

function InverseWishart{T<:Real}(df::T, Ψ::AbstractPDMat{T})
function InverseWishart(df::T, Ψ::AbstractPDMat{T}) where T<:Real
p = dim(Ψ)
df > p - 1 || error("df should be greater than dim - 1.")
c0 = _invwishart_c0(df, Ψ)
Expand Down Expand Up @@ -46,7 +46,7 @@ insupport(d::InverseWishart, X::Matrix) = size(X) == size(d) && isposdef(X)
dim(d::InverseWishart) = dim(d.Ψ)
size(d::InverseWishart) = (p = dim(d); (p, p))
params(d::InverseWishart) = (d.df, d.Ψ, d.c0)
@inline partype{T<:Real}(d::InverseWishart{T}) = T
@inline partype(d::InverseWishart{T}) where {T<:Real} = T

### Conversion
function convert{T<:Real}(::Type{InverseWishart{T}}, d::InverseWishart)
Expand Down Expand Up @@ -95,7 +95,7 @@ end

rand(d::InverseWishart) = inv(cholfact!(rand(Wishart(d.df, inv(d.Ψ)))))

function _rand!{M<:Matrix}(d::InverseWishart, X::AbstractArray{M})
function _rand!(d::InverseWishart, X::AbstractArray{M}) where M<:Matrix
wd = Wishart(d.df, inv(d.Ψ))
for i in 1:length(X)
X[i] = inv(cholfact!(rand(wd)))
Expand Down
6 changes: 3 additions & 3 deletions src/matrix/wishart.jl
Expand Up @@ -9,15 +9,15 @@ The [Wishart distribution](http://en.wikipedia.org/wiki/Wishart_distribution) is
multidimensional generalization of the Chi-square distribution, which is characterized by
a degree of freedom ν, and a base matrix S.
"""
immutable Wishart{T<:Real, ST<:AbstractPDMat} <: ContinuousMatrixDistribution
struct Wishart{T<:Real, ST<:AbstractPDMat} <: ContinuousMatrixDistribution
df::T # degree of freedom
S::ST # the scale matrix
c0::T # the logarithm of normalizing constant in pdf
end

#### Constructors

function Wishart{T<:Real}(df::T, S::AbstractPDMat{T})
function Wishart(df::T, S::AbstractPDMat{T}) where T<:Real
p = dim(S)
df > p - 1 || error("dpf should be greater than dim - 1.")
c0 = _wishart_c0(df, S)
Expand Down Expand Up @@ -50,7 +50,7 @@ insupport(d::Wishart, X::Matrix) = size(X) == size(d) && isposdef(X)
dim(d::Wishart) = dim(d.S)
size(d::Wishart) = (p = dim(d); (p, p))
params(d::Wishart) = (d.df, d.S, d.c0)
@inline partype{T<:Real}(d::Wishart{T}) = T
@inline partype(d::Wishart{T}) where {T<:Real} = T

### Conversion
function convert{T<:Real}(::Type{Wishart{T}}, d::Wishart)
Expand Down
20 changes: 10 additions & 10 deletions src/matrixvariates.jl
Expand Up @@ -24,7 +24,7 @@ mean(d::MatrixDistribution)

# sampling

rand!{M<:Matrix}(d::MatrixDistribution, A::AbstractArray{M}) = _rand!(sampler(d), A)
rand!(d::MatrixDistribution, A::AbstractArray{M}) where {M<:Matrix} = _rand!(sampler(d), A)

"""
rand(d::MatrixDistribution, n)
Expand All @@ -35,14 +35,14 @@ rand(d::MatrixDistribution, n::Int) = _rand!(sampler(d), Vector{Matrix{eltype(d)

# pdf & logpdf

_pdf{T<:Real}(d::MatrixDistribution, x::AbstractMatrix{T}) = exp(_logpdf(d, x))
_pdf(d::MatrixDistribution, x::AbstractMatrix{T}) where {T<:Real} = exp(_logpdf(d, x))

"""
logpdf(d::MatrixDistribution, AbstractMatrix)
Compute the logarithm of the probability density at the input matrix `x`.
"""
function logpdf{T<:Real}(d::MatrixDistribution, x::AbstractMatrix{T})
function logpdf(d::MatrixDistribution, x::AbstractMatrix{T}) where T<:Real
size(x) == size(d) ||
throw(DimensionMismatch("Inconsistent array dimensions."))
_logpdf(d, x)
Expand All @@ -53,44 +53,44 @@ end
Compute the probability density at the input matrix `x`.
"""
function pdf{T<:Real}(d::MatrixDistribution, x::AbstractMatrix{T})
function pdf(d::MatrixDistribution, x::AbstractMatrix{T}) where T<:Real
size(x) == size(d) ||
throw(DimensionMismatch("Inconsistent array dimensions."))
_pdf(d, x)
end

function _logpdf!{M<:Matrix}(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M})
function _logpdf!(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M}) where M<:Matrix
for i = 1:length(X)
r[i] = logpdf(d, X[i])
end
return r
end

function _pdf!{M<:Matrix}(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M})
function _pdf!(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M}) where M<:Matrix
for i = 1:length(X)
r[i] = pdf(d, X[i])
end
return r
end

function logpdf!{M<:Matrix}(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M})
function logpdf!(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M}) where M<:Matrix
length(X) == length(r) ||
throw(DimensionMismatch("Inconsistent array dimensions."))
_logpdf!(r, d, X)
end

function pdf!{M<:Matrix}(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M})
function pdf!(r::AbstractArray, d::MatrixDistribution, X::AbstractArray{M}) where M<:Matrix
length(X) == length(r) ||
throw(DimensionMismatch("Inconsistent array dimensions."))
_pdf!(r, d, X)
end

function logpdf{M<:Matrix}(d::MatrixDistribution, X::AbstractArray{M})
function logpdf(d::MatrixDistribution, X::AbstractArray{M}) where M<:Matrix
T = promote_type(partype(d), eltype(M))
_logpdf!(Array{T}(size(X)), d, X)
end

function pdf{M<:Matrix}(d::MatrixDistribution, X::AbstractArray{M})
function pdf(d::MatrixDistribution, X::AbstractArray{M}) where M<:Matrix
T = promote_type(partype(d), eltype(M))
_pdf!(Array{T}(size(X)), d, X)
end
Expand Down
16 changes: 8 additions & 8 deletions src/mixtures/mixturemodel.jl
Expand Up @@ -13,11 +13,11 @@

@compat abstract type AbstractMixtureModel{VF<:VariateForm,VS<:ValueSupport,C<:Distribution} <: Distribution{VF, VS} end

immutable MixtureModel{VF<:VariateForm,VS<:ValueSupport,C<:Distribution} <: AbstractMixtureModel{VF,VS,C}
struct MixtureModel{VF<:VariateForm,VS<:ValueSupport,C<:Distribution} <: AbstractMixtureModel{VF,VS,C}
components::Vector{C}
prior::Categorical

function (::Type{MixtureModel{VF,VS,C}}){VF,VS,C}(cs::Vector{C}, pri::Categorical)
function (::Type{MixtureModel{VF,VS,C}})(cs::Vector{C}, pri::Categorical) where {VF,VS,C}
length(cs) == ncategories(pri) ||
error("The number of components does not match the length of prior.")
new{VF,VS,C}(cs, pri)
Expand All @@ -35,7 +35,7 @@ end
The type of the components of `d`.
"""
component_type{VF,VS,C}(d::AbstractMixtureModel{VF,VS,C}) = C
component_type(d::AbstractMixtureModel{VF,VS,C}) where {VF,VS,C} = C

"""
components(d::AbstractMixtureModel)
Expand Down Expand Up @@ -101,7 +101,7 @@ rand!(d::AbstractMixtureModel, r::AbstractArray)
Construct a mixture model with a vector of `components` and a `prior` probability vector.
If no `prior` is provided then all components will have the same prior probabilities.
"""
MixtureModel{C<:Distribution}(components::Vector{C}) =
MixtureModel(components::Vector{C}) where {C<:Distribution} =
MixtureModel(components, Categorical(length(components)))

"""
Expand All @@ -116,13 +116,13 @@ function MixtureModel{C<:Distribution}(::Type{C}, params::AbstractArray)
MixtureModel(components)
end

function MixtureModel{C<:Distribution}(components::Vector{C}, prior::Categorical)
function MixtureModel(components::Vector{C}, prior::Categorical) where C<:Distribution
VF = variate_form(C)
VS = value_support(C)
MixtureModel{VF,VS,C}(components, prior)
end

MixtureModel{C<:Distribution}(components::Vector{C}, p::Vector{Float64}) =
MixtureModel(components::Vector{C}, p::Vector{Float64}) where {C<:Distribution} =
MixtureModel(components, Categorical(p))

_construct_component{C<:Distribution}(::Type{C}, arg) = C(arg)
Expand Down Expand Up @@ -471,12 +471,12 @@ componentwise_logpdf(d::MultivariateMixture, x::AbstractMatrix) = componentwise_

## Sampling

immutable MixtureSampler{VF,VS,Sampler} <: Sampleable{VF,VS}
struct MixtureSampler{VF,VS,Sampler} <: Sampleable{VF,VS}
csamplers::Vector{Sampler}
psampler::AliasTable
end

function MixtureSampler{VF,VS}(d::MixtureModel{VF,VS})
function MixtureSampler(d::MixtureModel{VF,VS}) where {VF,VS}
csamplers = map(sampler, d.components)
psampler = sampler(d.prior)
MixtureSampler{VF,VS,eltype(csamplers)}(csamplers, psampler)
Expand Down
4 changes: 2 additions & 2 deletions src/mixtures/unigmm.jl
@@ -1,6 +1,6 @@
# Univariate Gaussian Mixture Models

immutable UnivariateGMM <: UnivariateMixture{Continuous,Normal}
struct UnivariateGMM <: UnivariateMixture{Continuous,Normal}
K::Int
means::Vector{Float64}
stds::Vector{Float64}
Expand Down Expand Up @@ -29,7 +29,7 @@ rand(d::UnivariateGMM) = (k = rand(d.prior); d.means[k] + randn() * d.stds[k])

params(d::UnivariateGMM) = (d.means, d.stds, d.prior)

immutable UnivariateGMMSampler <: Sampleable{Univariate,Continuous}
struct UnivariateGMMSampler <: Sampleable{Univariate,Continuous}
means::Vector{Float64}
stds::Vector{Float64}
psampler::AliasTable
Expand Down

0 comments on commit 9bfe801

Please sign in to comment.