Skip to content

Commit

Permalink
rename itrunc -> trunc, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Dec 1, 2014
1 parent 17e53ad commit 4763c44
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/empirical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end

function quantile(d::EmpiricalUnivariateDistribution, p::Float64)
n = length(d.values)
index = ifloor(p * n) + 1
index = floor(Int,p * n) + 1
index > n ? d.values[n] : d.values[index]
end

Expand Down
10 changes: 5 additions & 5 deletions src/samplers/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function rand(s::BinomialGeomSampler)
if v > n # in case when v is very large or infinity
break
end
y += iceil(v)
y += ceil(Int,v)
if y > n
break
end
Expand Down Expand Up @@ -145,7 +145,7 @@ function rand(s::BinomialTPESampler)
u = s.p4*rand()
v = rand()
if u <= s.p1
y = ifloor(s.xM-s.p1*v+u)
y = floor(Int,s.xM-s.p1*v+u)
# Goto 6
break
elseif u <= s.p2 # Step 2
Expand All @@ -155,18 +155,18 @@ function rand(s::BinomialTPESampler)
# Goto 1
continue
end
y = ifloor(x)
y = floor(Int,x)
# Goto 5
elseif u <= s.p3 # Step 3
y = ifloor(s.xL + log(v)/s.λL)
y = floor(Int,s.xL + log(v)/s.λL)
if y < 0
# Goto 1
continue
end
v *= (u-s.p2)*s.λL
# Goto 5
else # Step 4
y = ifloor(s.xR-log(v)/s.λR)
y = floor(Int,s.xR-log(v)/s.λR)
if y > s.n
# Goto 1
continue
Expand Down
6 changes: 3 additions & 3 deletions src/samplers/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ immutable PoissonADSampler <: Sampleable{Univariate,Discrete}
end

PoissonADSampler::Float64) =
PoissonADSampler(μ,sqrt(μ),6.0*μ^2,ifloor(μ-1.1484))
PoissonADSampler(μ,sqrt(μ),6.0*μ^2,floor(Int,μ-1.1484))

function rand(s::PoissonADSampler)
# Step N
G = s.μ + s.s*randn()

if G >= 0.0
K = ifloor(G)
K = floor(Int,G)
# Step I
if K >= s.L
return K
Expand Down Expand Up @@ -89,7 +89,7 @@ function rand(s::PoissonADSampler)
continue
end

K = ifloor(s.μ + s.s*T)
K = floor(Int,s.μ + s.s*T)
px,py,fx,fy = procf(s.μ,K,s.s)
c = 0.1069/s.μ

Expand Down
16 changes: 8 additions & 8 deletions src/testutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ function test_samples(s::Sampleable{Univariate, Discrete}, # the sampleable
vmin = minimum(distr)
vmax = maximum(distr)

rmin = ifloor(quantile(distr, 0.00001))::Int
rmax = ifloor(quantile(distr, 0.99999))::Int
rmin = floor(Int,quantile(distr, 0.00001))::Int
rmax = floor(Int,quantile(distr, 0.99999))::Int
m = rmax - rmin + 1 # length of the range
p0 = pdf(distr, rmin:rmax) # reference probability masses
@assert length(p0) == m
Expand All @@ -90,8 +90,8 @@ function test_samples(s::Sampleable{Univariate, Discrete}, # the sampleable
cub = Array(Int, m)
for i = 1:m
bp = Binomial(n, p0[i])
clb[i] = ifloor(quantile(bp, q/2))
cub[i] = iceil(cquantile(bp, q/2))
clb[i] = floor(Int,quantile(bp, q/2))
cub[i] = ceil(Int,cquantile(bp, q/2))
@assert cub[i] >= clb[i]
end

Expand Down Expand Up @@ -178,8 +178,8 @@ function test_samples(s::Sampleable{Univariate, Continuous}, # the sampleable
for i = 1:nbins
pi = cdfs[i+1] - cdfs[i]
bp = Binomial(n, pi)
clb[i] = ifloor(quantile(bp, q/2))
cub[i] = iceil(cquantile(bp, q/2))
clb[i] = floor(Int,quantile(bp, q/2))
cub[i] = ceil(Int,cquantile(bp, q/2))
@assert cub[i] >= clb[i]
end

Expand Down Expand Up @@ -231,8 +231,8 @@ end
function get_evalsamples(d::DiscreteUnivariateDistribution, q::Float64)
# samples for testing evaluation functions (even spacing)

lv = (islowerbounded(d) ? minimum(d) : ifloor(quantile(d, q/2)))::Int
hv = (isupperbounded(d) ? maximum(d) : iceil(cquantile(d, q/2)))::Int
lv = (islowerbounded(d) ? minimum(d) : floor(Int,quantile(d, q/2)))::Int
hv = (isupperbounded(d) ? maximum(d) : ceil(Int,cquantile(d, q/2)))::Int
@assert lv <= hv
return lv:hv
end
Expand Down
2 changes: 1 addition & 1 deletion src/univariate/continuous/ksonesided.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function ccdf(d::KSOneSided, x::Float64)
end
n = d.n
s = 0.0
for j = 0:ifloor(n-n*x)
for j = 0:floor(Int,n-n*x)
p = x+j/n
s += pdf(Binomial(n,p),j) / p
end
Expand Down
4 changes: 2 additions & 2 deletions src/univariate/discrete/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ params(d::Binomial) = (d.n, d.p)

mean(d::Binomial) = ntrials(d) * succprob(d)
var(d::Binomial) = ntrials(d) * succprob(d) * failprob(d)
mode(d::Binomial) = ((n, p) = params(d); n > 0 ? iround((n + 1) * d.prob) : 0)
mode(d::Binomial) = ((n, p) = params(d); n > 0 ? round(Int,(n + 1) * d.prob) : 0)
modes(d::Binomial) = Int[mode(d)]

median(d::Binomial) = iround(mean(d))
median(d::Binomial) = round(Int,mean(d))

function skewness(d::Binomial)
n, p1 = params(d)
Expand Down
4 changes: 2 additions & 2 deletions src/univariate/discrete/discreteuniform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ modes(d::DiscreteUniform) = [d.a:d.b]

cdf(d::DiscreteUniform, x::Int) = (x < d.a ? 0.0 :
x > d.b ? 1.0 :
(ifloor(x) - d.a + 1.0) * d.pv)
(floor(Int,x) - d.a + 1.0) * d.pv)

pdf(d::DiscreteUniform, x::Int) = insupport(d, x) ? d.pv : 0.0

Expand Down Expand Up @@ -93,7 +93,7 @@ function _logpdf!(r::AbstractArray, d::DiscreteUniform, x::AbstractArray)
return r
end

quantile(d::DiscreteUniform, p::Float64) = d.a + ifloor(p * span(d))
quantile(d::DiscreteUniform, p::Float64) = d.a + floor(Int,p * span(d))

function mgf(d::DiscreteUniform, t::Real)
a, b = d.a, d.b
Expand Down
2 changes: 1 addition & 1 deletion src/univariate/discrete/geometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ end

### Sampling

rand(d::Geometric) = ifloor(-randexp() / log1p(-d.p))
rand(d::Geometric) = floor(Int,-randexp() / log1p(-d.p))


### Model Fitting
Expand Down
2 changes: 1 addition & 1 deletion src/univariate/discrete/negativebinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ skewness(d::NegativeBinomial) = (p = succprob(d); (2.0 - p) / sqrt((1.0 - p) * d

kurtosis(d::NegativeBinomial) = (p = succprob(d); 6.0 / d.r + (p * p) / ((1.0 - p) * d.r))

mode(d::NegativeBinomial) = (p = succprob(d); ifloor((1.0 - p) * (d.r - 1.) / p))
mode(d::NegativeBinomial) = (p = succprob(d); floor(Int,(1.0 - p) * (d.r - 1.) / p))


### Evaluation
Expand Down
4 changes: 2 additions & 2 deletions src/univariate/discrete/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ rate(d::Poisson) = d.λ

mean(d::Poisson) = d.λ

mode(d::Poisson) = ifloor(d.λ)
mode(d::Poisson) = floor(Int,d.λ)

function modes(d::Poisson)
λ = d.λ
isinteger(λ) ? [int(λ)-1,int(λ)] : [ifloor(λ)]
isinteger(λ) ? [int(λ)-1,int(λ)] : [floor(Int,λ)]
end

var(d::Poisson) = d.λ
Expand Down
10 changes: 5 additions & 5 deletions src/univariates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,35 +144,35 @@ logpdf(d::ContinuousUnivariateDistribution, x::Real) = logpdf(d, float64(x))

function cdf(d::DiscreteUnivariateDistribution, x::Int)
c = 0.0
for y = minimum(d):ifloor(x)
for y = minimum(d):floor(Int,x)
c += pdf(d, y)
end
return c
end

cdf(d::DiscreteUnivariateDistribution, x::Real) = cdf(d, ifloor(x))
cdf(d::DiscreteUnivariateDistribution, x::Real) = cdf(d, floor(Int,x))

cdf(d::ContinuousUnivariateDistribution, x::Float64) = throw(MethodError(cdf, (d, x)))
cdf(d::ContinuousUnivariateDistribution, x::Real) = cdf(d, float64(x))

# ccdf

ccdf(d::DiscreteUnivariateDistribution, x::Int) = 1.0 - cdf(d, x)
ccdf(d::DiscreteUnivariateDistribution, x::Real) = ccdf(d, ifloor(x))
ccdf(d::DiscreteUnivariateDistribution, x::Real) = ccdf(d, floor(Int,x))
ccdf(d::ContinuousUnivariateDistribution, x::Float64) = 1.0 - cdf(d, x)
ccdf(d::ContinuousUnivariateDistribution, x::Real) = ccdf(d, float64(x))

# logcdf

logcdf(d::DiscreteUnivariateDistribution, x::Int) = log(cdf(d, x))
logcdf(d::DiscreteUnivariateDistribution, x::Real) = logcdf(d, ifloor(x))
logcdf(d::DiscreteUnivariateDistribution, x::Real) = logcdf(d, floor(Int,x))
logcdf(d::ContinuousUnivariateDistribution, x::Float64) = log(cdf(d, x))
logcdf(d::ContinuousUnivariateDistribution, x::Real) = logcdf(d, float64(x))

# logccdf

logccdf(d::DiscreteUnivariateDistribution, x::Int) = log(ccdf(d, x))
logccdf(d::DiscreteUnivariateDistribution, x::Real) = logccdf(d, ifloor(x))
logccdf(d::DiscreteUnivariateDistribution, x::Real) = logccdf(d, floor(Int,x))
logccdf(d::ContinuousUnivariateDistribution, x::Float64) = log(ccdf(d, x))
logccdf(d::ContinuousUnivariateDistribution, x::Real) = logccdf(d, float64(x))

Expand Down
4 changes: 2 additions & 2 deletions test/rmath/geometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ distlist = [


for d in distlist
for x in [0.0:20.0,linspace(21.0,maxintfloat()/4,1_000_000)]
x = iround(x)
for x in [0.0:20.0,linspace(21.0,float(typemax(Int32)),1_000_000)]
x = round(Int,x)

test_rmath(pdf,d,x)
test_rmath(logpdf,d,x)
Expand Down

0 comments on commit 4763c44

Please sign in to comment.