Commit 34cb37c1 authored by Dahua Lin's avatar Dahua Lin

Merge pull request #157 from JuliaStats/minmax

Change min/max to minimum/maximum
parents 9b6d27d9 0b3832e1
......@@ -167,7 +167,8 @@ export
var, # variance of distribution
wsample # weighted sampling from a source array
import Base.mean, Base.median, Base.quantile, Base.max, Base.min, Base.scale
import Base.mean, Base.median, Base.quantile, Base.scale
import Base.max, Base.min, Base.maximum, Base.minimum
import Base.Random, Base.rand, Base.rand!, Base.std, Base.var, Base.cor, Base.cov
import Base.show, Base.sprand
import NumericExtensions.dim, NumericExtensions.entropy
......
......@@ -48,8 +48,8 @@ function kde{T <: Real}(data::Vector{T},
end
# Find interval that will contain almost all mass
dlo = min(data) - 3 * window
dhi = max(data) + 3 * window
dlo = minimum(data) - 3 * window
dhi = maximum(data) + 3 * window
# Check that interval for estimation is valid
if dlo >= dhi
......
......@@ -59,8 +59,8 @@ isupperbounded(::Union(Bernoulli, Type{Bernoulli})) = true
islowerbounded(::Union(Bernoulli, Type{Bernoulli})) = true
isbounded(::Union(Bernoulli, Type{Bernoulli})) = true
min(::Union(Bernoulli, Type{Bernoulli})) = 0
max(::Union(Bernoulli, Type{Bernoulli})) = 1
minimum(::Union(Bernoulli, Type{Bernoulli})) = 0
maximum(::Union(Bernoulli, Type{Bernoulli})) = 1
support(::Union(Bernoulli, Type{Bernoulli})) = 0:1
insupport(::Union(Bernoulli, Type{Bernoulli}), x::Real) = (x == 0 || x == 1)
......
......@@ -11,8 +11,8 @@ end
Binomial(size::Integer) = Binomial(size, 0.5)
Binomial() = Binomial(1, 0.5)
min(d::Binomial) = 0
max(d::Binomial) = d.size
minimum(d::Binomial) = 0
maximum(d::Binomial) = d.size
@_jl_dist_2p Binomial binom
......@@ -66,8 +66,8 @@ isupperbounded(d::Union(Binomial, Type{Binomial})) = true
islowerbounded(d::Union(Binomial, Type{Binomial})) = true
isbounded(d::Union(Binomial, Type{Binomial})) = true
min(d::Union(Binomial, Type{Binomial})) = 0
max(d::Binomial) = d.size
minimum(d::Union(Binomial, Type{Binomial})) = 0
maximum(d::Binomial) = d.size
support(d::Binomial) = 0:d.size
insupport(d::Binomial, x::Real) = isinteger(x) && 0 <= x <= d.size
......
......@@ -22,8 +22,8 @@ isupperbounded(::Union(Categorical, Type{Categorical})) = true
islowerbounded(::Union(Categorical, Type{Categorical})) = true
isbounded(::Union(Categorical, Type{Categorical})) = true
min(::Union(Categorical, Type{Categorical})) = 1
max(d::Categorical) = d.K
minimum(::Union(Categorical, Type{Categorical})) = 1
maximum(d::Categorical) = d.K
support(d::Categorical) = 1:d.K
# evaluation
......@@ -141,7 +141,7 @@ mode(d::Categorical) = indmax(d.prob)
function modes(d::Categorical)
K = d.K
p = d.prob
maxp = max(p)
maxp = maximum(p)
r = Array(Int, 0)
for k = 1:K
@inbounds if p[k] == maxp
......@@ -225,7 +225,7 @@ end
fit_mle{T<:Integer}(::Type{Categorical}, data::(Int, Array{T})) = fit_mle(Categorical, data...)
fit_mle{T<:Integer}(::Type{Categorical}, data::(Int, Array{T}), w::Array{Float64}) = fit_mle(Categorical, data..., w)
fit_mle{T<:Integer}(::Type{Categorical}, x::Array{T}) = fit_mle(Categorical, max(x), x)
fit_mle{T<:Integer}(::Type{Categorical}, x::Array{T}, w::Array{Float64}) = fit_mle(Categorical, max(x), x, w)
fit_mle{T<:Integer}(::Type{Categorical}, x::Array{T}) = fit_mle(Categorical, maximum(x), x)
fit_mle{T<:Integer}(::Type{Categorical}, x::Array{T}, w::Array{Float64}) = fit_mle(Categorical, maximum(x), x, w)
......@@ -59,8 +59,8 @@ isupperbounded(::Union(DiscreteUniform, Type{DiscreteUniform})) = true
islowerbounded(::Union(DiscreteUniform, Type{DiscreteUniform})) = true
isbounded(::Union(DiscreteUniform, Type{DiscreteUniform})) = true
min(d::DiscreteUniform) = d.a
max(d::DiscreteUniform) = d.b
minimum(d::DiscreteUniform) = d.a
maximum(d::DiscreteUniform) = d.b
support(d::DiscreteUniform) = d.a:d.b
insupport(d::DiscreteUniform, x::Number) = isinteger(x) && d.a <= x <= d.b
......
......@@ -71,8 +71,8 @@ islowerbounded(::Union(EmpiricalUnivariateDistribution, Type{EmpiricalUnivariate
isbounded(::Union(EmpiricalUnivariateDistribution, Type{EmpiricalUnivariateDistribution})) = true
hasfinitesupport(d::Union(EmpiricalUnivariateDistribution, Type{EmpiricalUnivariateDistribution})) = true
min(d::EmpiricalUnivariateDistribution) = min(d.values[1])
max(d::EmpiricalUnivariateDistribution) = max(d.values[end])
minimum(d::EmpiricalUnivariateDistribution) = d.values[1]
maximum(d::EmpiricalUnivariateDistribution) = d.values[end]
support(d::EmpiricalUnivariateDistribution) = d.support
### fit model
......@@ -80,4 +80,4 @@ support(d::EmpiricalUnivariateDistribution) = d.support
function fit_mle{T <: Real}(::Type{EmpiricalUnivariateDistribution},
x::Vector{T})
EmpiricalUnivariateDistribution(x)
end
\ No newline at end of file
end
......@@ -69,8 +69,8 @@ islowerbounded(::Union(Exponential, Type{Exponential})) = true
isbounded(::Union(Exponential, Type{Exponential})) = false
hasfinitesupport(::Union(Exponential, Type{Exponential})) = false
min(::Union(Exponential, Type{Exponential})) = 0.0
max(::Union(Exponential, Type{Exponential})) = Inf
minimum(::Union(Exponential, Type{Exponential})) = 0.0
maximum(::Union(Exponential, Type{Exponential})) = Inf
insupport(::Union(Exponential, Type{Exponential}), x::Real) = x >= 0.0
......
......@@ -57,9 +57,8 @@ isupperbounded(d::Union(Geometric, Type{Geometric})) = false
islowerbounded(d::Union(Geometric, Type{Geometric})) = true
isbounded(d::Union(Geometric, Type{Geometric})) = false
min(d::Union(Geometric, Type{Geometric})) = 0
max(d::Geometric) = Inf
insupport(d::Geometric, x::Real) = isinteger(x) && x >= 0
minimum(d::Union(Geometric, Type{Geometric})) = 0
maximum(d::Geometric) = Inf
## Fit model
......
......@@ -11,9 +11,9 @@ isupperbounded(::Union(KSDist, Type{KSDist})) = true
islowerbounded(::Union(KSDist, Type{KSDist})) = true
isbounded(::Union(KSDist, Type{KSDist})) = true
min(d::KSDist) = 1 / (2 * d.n)
max(d::KSDist) = 1.0
insupport(d::KSDist, x::Real) = min(d) <= x <= 1.0
minimum(d::KSDist) = 1 / (2 * d.n)
maximum(d::KSDist) = 1.0
insupport(d::KSDist, x::Real) = minimum(d) <= x <= 1.0
# TODO: implement Simard and L'Ecuyer (2011) meta-algorithm
# requires Pomeranz and Pelz-Good algorithms
......
......@@ -21,8 +21,8 @@ isupperbounded(::Union(Levy, Type{Levy})) = false
islowerbounded(::Union(Levy, Type{Levy})) = true
isbounded(::Union(Levy, Type{Levy})) = false
min(d::Levy) = d.location
max(d::Levy) = Inf
minimum(d::Levy) = d.location
maximum(d::Levy) = Inf
insupport(d::Levy, x::Real) = d.location <= x && isfinite(x)
mean(d::Levy) = Inf
......
......@@ -23,8 +23,8 @@ isupperbounded(::Union(NegativeBinomial, Type{NegativeBinomial})) = false
islowerbounded(::Union(NegativeBinomial, Type{NegativeBinomial})) = true
isbounded(::Union(NegativeBinomial, Type{NegativeBinomial})) = false
min(::Union(NegativeBinomial, Type{NegativeBinomial})) = 0
max(::Union(NegativeBinomial, Type{NegativeBinomial})) = Inf
minimum(::Union(NegativeBinomial, Type{NegativeBinomial})) = 0
maximum(::Union(NegativeBinomial, Type{NegativeBinomial})) = Inf
insupport(::NegativeBinomial, x::Real) = isinteger(x) && zero(x) <= x
insupport(::Type{NegativeBinomial}, x::Real) = isinteger(x) && zero(x) <= x
......
......@@ -14,8 +14,8 @@ islowerbounded(::Union(Pareto, Type{Pareto})) = true
isupperbounded(::Union(Pareto, Type{Pareto})) = false
isbounded(::Union(Pareto, Type{Pareto})) = false
min(d::Pareto) = d.scale
max(d::Pareto) = Inf
minimum(d::Pareto) = d.scale
maximum(d::Pareto) = Inf
insupport(d::Pareto, x::Number) = isfinite(x) && x >= d.scale
mean(d::Pareto) = d.shape > 1.0 ? (d.scale * d.shape) / (d.shape - 1.0) : Inf
......
......@@ -29,8 +29,8 @@ isupperbounded(::Union(Poisson, Type{Poisson})) = false
islowerbounded(::Union(Poisson, Type{Poisson})) = true
isbounded(::Union(Poisson, Type{Poisson})) = false
min(::Union(Poisson, Type{Poisson})) = 0
max(::Union(Poisson, Type{Poisson})) = Inf
minimum(::Union(Poisson, Type{Poisson})) = 0
maximum(::Union(Poisson, Type{Poisson})) = Inf
insupport(::Poisson, x::Real) = isinteger(x) && zero(x) <= x
insupport(::Type{Poisson}, x::Real) = isinteger(x) && zero(x) <= x
......
......@@ -8,8 +8,8 @@ isupperbounded(::Union(Skellam, Type{Skellam})) = false
islowerbounded(::Union(Skellam, Type{Skellam})) = false
isbounded(::Union(Skellam, Type{Skellam})) = false
min(::Union(Skellam, Type{Skellam})) = -Inf
max(::Union(Skellam, Type{Skellam})) = Inf
minimum(::Union(Skellam, Type{Skellam})) = -Inf
maximum(::Union(Skellam, Type{Skellam})) = Inf
insupport(::Skellam, x::Real) = isinteger(x) && zero(x) <= x
insupport(::Type{Skellam}, x::Real) = isinteger(x) && zero(x) <= x
......
......@@ -37,9 +37,9 @@ isupperbounded(::Union(Triangular, Type{Triangular})) = true
islowerbounded(::Union(Triangular, Type{Triangular})) = true
isbounded(::Union(Triangular, Type{Triangular})) = true
min(d::Triangular) = d.location - d.scale
max(d::Triangular) = d.location + d.scale
insupport(d::Triangular, x::Real) = min(d) <= x <= max(d)
minimum(d::Triangular) = d.location - d.scale
maximum(d::Triangular) = d.location + d.scale
insupport(d::Triangular, x::Real) = minimum(d) <= x <= maximum(d)
kurtosis(d::Triangular) = -0.6
......
......@@ -14,8 +14,8 @@ isupperbounded(::Union(Uniform, Type{Uniform})) = true
islowerbounded(::Union(Uniform, Type{Uniform})) = true
isbounded(::Union(Uniform, Type{Uniform})) = true
min(d::Uniform) = d.a
max(d::Uniform) = d.b
minimum(d::Uniform) = d.a
maximum(d::Uniform) = d.b
insupport(d::Uniform, x::Real) = d.a <= x <= d.b
entropy(d::Uniform) = log(d.b - d.a)
......
......@@ -121,8 +121,8 @@ macro continuous_distr_support(D, lb, ub)
isupperbounded(::Union($D, Type{$D})) = true
islowerbounded(::Union($D, Type{$D})) = true
isbounded(::Union($D, Type{$D})) = true
min(::Union($D, Type{$D})) = $lb
max(::Union($D, Type{$D})) = $ub
minimum(::Union($D, Type{$D})) = $lb
maximum(::Union($D, Type{$D})) = $ub
insupport(::Union($D, Type{$D}), x::Real) = ($lb <= x <= $ub)
end)
......@@ -131,8 +131,8 @@ macro continuous_distr_support(D, lb, ub)
isupperbounded(::Union($D, Type{$D})) = false
islowerbounded(::Union($D, Type{$D})) = true
isbounded(::Union($D, Type{$D})) = false
min(::Union($D, Type{$D})) = $lb
max(::Union($D, Type{$D})) = $ub
minimum(::Union($D, Type{$D})) = $lb
maximum(::Union($D, Type{$D})) = $ub
insupport(::Union($D, Type{$D}), x::Real) = (isfinite(x) && x >= $lb)
end)
......@@ -141,8 +141,8 @@ macro continuous_distr_support(D, lb, ub)
isupperbounded(::Union($D, Type{$D})) = true
islowerbounded(::Union($D, Type{$D})) = false
isbounded(::Union($D, Type{$D})) = false
min(::Union($D, Type{$D})) = $lb
max(::Union($D, Type{$D})) = $ub
minimum(::Union($D, Type{$D})) = $lb
maximum(::Union($D, Type{$D})) = $ub
insupport(::Union($D, Type{$D}), x::Real) = (isfinite(x) && x <= $ub)
end)
......@@ -151,8 +151,8 @@ macro continuous_distr_support(D, lb, ub)
isupperbounded(::Union($D, Type{$D})) = false
islowerbounded(::Union($D, Type{$D})) = false
isbounded(::Union($D, Type{$D})) = false
min(::Union($D, Type{$D})) = $lb
max(::Union($D, Type{$D})) = $ub
minimum(::Union($D, Type{$D})) = $lb
maximum(::Union($D, Type{$D})) = $ub
insupport(::Union($D, Type{$D}), x::Real) = isfinite(x)
end)
......
......@@ -31,8 +31,8 @@ for d in [
# NB: uncomment if some tests failed
# println(d)
xmin = min(d)
xmax = max(d)
xmin = minimum(d)
xmax = maximum(d)
@assert isa(xmin, Int)
@assert isa(xmax, Int)
@assert xmin <= xmax
......@@ -53,11 +53,11 @@ for d in [
# check that we can generate many random draws at once
x = rand(d, n)
@test isa(x, Vector{Int})
@test xmin <= min(x) <= max(x) <= xmax
@test xmin <= minimum(x) <= maximum(x) <= xmax
# check that we can generate many random draws in-place
rand!(d, x)
@test xmin <= min(x) <= max(x) <= xmax
@test xmin <= minimum(x) <= maximum(x) <= xmax
####
#
......
......@@ -17,12 +17,12 @@ w = rand(n0)
x = rand(DiscreteUniform(10, 15), n0)
d = fit(DiscreteUniform, x)
@test isa(d, DiscreteUniform)
@test min(d) == min(x)
@test max(d) == max(x)
@test minimum(d) == minimum(x)
@test maximum(d) == maximum(x)
d = fit(DiscreteUniform, rand(DiscreteUniform(10, 15), N))
@test min(d) == 10
@test max(d) == 15
@test minimum(d) == 10
@test maximum(d) == 15
# Bernoulli
......@@ -243,14 +243,14 @@ d = fit_mle(Normal, x, w; sigma=σ)
x = rand(Uniform(1.2, 5.8), n0)
d = fit(Uniform, x)
@test isa(d, Uniform)
@test 1.2 <= min(d) <= max(d) <= 5.8
@test min(d) == min(x)
@test max(d) == max(x)
@test 1.2 <= minimum(d) <= maximum(d) <= 5.8
@test minimum(d) == minimum(x)
@test maximum(d) == maximum(x)
d = fit(Uniform, rand(Uniform(1.2, 5.8), N))
@test 1.2 <= min(d) <= max(d) <= 5.8
@test_approx_eq_eps min(d) 1.2 0.02
@test_approx_eq_eps max(d) 5.8 0.02
@test 1.2 <= minimum(d) <= maximum(d) <= 5.8
@test_approx_eq_eps minimum(d) 1.2 0.02
@test_approx_eq_eps maximum(d) 5.8 0.02
# Gamma
......
......@@ -34,11 +34,11 @@ for d in [
println("expected mean = $dmean")
println("empirical mean = $xmean")
println("--> abs.dev = $(max(abs(dmean - xmean)))")
println("--> abs.dev = $(maximum(abs(dmean - xmean)))")
println("expected cov = $dcov")
println("empirical cov = $xcov")
println("--> abs.dev = $(max(abs(dcov - xcov)))")
println("--> abs.dev = $(maximum(abs(dcov - xcov)))")
println("expected entropy = $dent")
println("empirical entropy = $xent")
......
......@@ -36,8 +36,8 @@ for i = 1:n
@assert v[1] != v[2]
x[:,i] = v
end
@test min(x) == 11
@test max(x) == 15
@test minimum(x) == 11
@test maximum(x) == 15
x[:] -= 10 # brings x to 1:5
p0 = fill(1/5, 5)
......@@ -53,8 +53,8 @@ for i = 1 : n
@assert sv[1] < sv[2] < sv[3] < sv[4]
x[:,i] = v
end
@test min(x) == 11
@test max(x) == 20
@test minimum(x) == 11
@test maximum(x) == 20
x[:] -= 10
p0 = fill(0.1, 10)
......@@ -72,8 +72,8 @@ for i = 1 : n
@assert sv[1] < sv[2] < sv[3] < sv[4]
x[:,i] = v
end
@test min(x) >= a
@test max(x) <= b
@test minimum(x) >= a
@test maximum(x) <= b
#### weighted sampling
......
......@@ -197,11 +197,11 @@ for d in [Arcsine(),
for i = 1:n_samples
c[i] = c[i]*n_samples - i
end
a = max(abs(c))
a = maximum(abs(c))
for i = 1:n_samples
c[i] += 1.0
end
b = max(abs(c))
b = maximum(abs(c))
ks = max(a,b)
kss = ks/n_samples
ksp = ccdf(Kolmogorov(),ks/sqrt(n_samples))
......
......@@ -5,9 +5,9 @@ const randi = Distributions.randi
n = 1_000_000
x = Int[randi(10) for i = 1:n]
@test min(x) == 1
@test max(x) == 10
@test minimum(x) == 1
@test maximum(x) == 10
x = Int[randi(3, 12) for i = 1:n]
@test min(x) == 3
@test max(x) == 12
@test minimum(x) == 3
@test maximum(x) == 12
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