Skip to content

Commit

Permalink
Update deprecated functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-j-smith committed Jun 11, 2017
1 parent 2311fbb commit 80c744d
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions doc/examples/epil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ epil = Dict{Symbol, Any}(
epil[:N] = size(epil[:y], 1)
epil[:T] = size(epil[:y], 2)

epil[:logBase4] = log(epil[:Base] / 4)
epil[:logBase4] = log.(epil[:Base] / 4)
epil[:BT] = epil[:logBase4] .* epil[:Trt]
epil[:logAge] = log(epil[:Age])
epil[:logAge] = log.(epil[:Age])
map(key -> epil[Symbol(string(key, "bar"))] = mean(epil[key]),
[:logBase4, :Trt, :BT, :logAge, :V4])

Expand Down
2 changes: 1 addition & 1 deletion doc/examples/leuk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ model = Model(
),

S0 = Logical(1,
dL0 -> exp(-cumsum(dL0)),
dL0 -> exp.(-cumsum(dL0)),
false
),

Expand Down
4 changes: 2 additions & 2 deletions doc/examples/line_amwg_slice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ logf = function(x::DenseVector)
b1 = x[2]
logs2 = x[3]
(-0.5 * length(data[:y]) - 0.001) * logs2 -
(0.5 * sumabs2(data[:y] - b0 - b1 * data[:x]) + 0.001) / exp(logs2) -
(0.5 * sum(abs2, data[:y] - b0 - b1 * data[:x]) + 0.001) / exp(logs2) -
0.5 * b0^2 / 1000 - 0.5 * b1^2 / 1000
end

Expand All @@ -37,6 +37,6 @@ logs2 = SliceMultivariate([0.0], 5.0, logf_logs2)
for i in 1:n
sample!(beta, adapt = (i <= burnin))
sample!(logs2)
sim[i, :, 1] = [beta; exp(logs2)]
sim[i, :, 1] = [beta; exp.(logs2)]
end
describe(sim)
2 changes: 1 addition & 1 deletion doc/examples/magnesium.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ model = Model(
),

OR = Logical(1,
mu -> exp(mu)
mu -> exp.(mu)
),

tau = Logical(1,
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/mice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ model = Model(
),

median = Logical(1,
(beta, r) -> exp(-beta / r) * log(2)^(1 / r)
(beta, r) -> exp.(-beta / r) * log(2)^(1 / r)
),

veh_control = Logical(
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/pollution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Gibbs_sigma2 = Sampler([:sigma2],
(mu, sigma2, y) ->
begin
a = length(y) / 2.0 + shape(sigma2.distr)
b = sumabs2(y - mu) / 2.0 + scale(sigma2.distr)
b = sum(abs2, y - mu) / 2.0 + scale(sigma2.distr)
rand(InverseGamma(a, b))
end
)
Expand Down
4 changes: 2 additions & 2 deletions doc/mcmc/newmultivardist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

## Logical indicating whether x is in the support
function insupport{T<:Real}(d::NewMultivarDist, x::AbstractVector{T})
length(d) == length(x) && all(isfinite(x))
length(d) == length(x) && all(isfinite.(x))
end

## Normalized or unnormalized log-density value
function _logpdf{T<:Real}(d::NewMultivarDist, x::AbstractVector{T})
-length(x) * log(d.sigma) - 0.5 * sumabs2(x - d.mu) / d.sigma^2
-length(x) * log(d.sigma) - 0.5 * sum(abs2, x - d.mu) / d.sigma^2
end

end
Expand Down
2 changes: 1 addition & 1 deletion doc/samplers/abc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Model-Based Constructor
.. function:: ABC(params::ElementOrVector{Symbol}, \
scale::ElementOrVector{T<:Real}, summary::Function, \
epsilon::Real; kernel::KernelDensityType=SymUniform, \
dist::Function=(Tsim, Tobs) -> sqrt(sumabs2(Tsim - Tobs)), \
dist::Function=(Tsim, Tobs) -> sqrt(sum(abs2, Tsim - Tobs)), \
proposal::SymDistributionType=Normal, maxdraw::Integer=1, \
nsim::Integer=1, decay::Real=1.0, randeps::Bool=false, \
args...)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ whose form is inverse gamma with :math:`n / 2 + \alpha_\pi` shape and :math:`(\b
(mu, s2, y) ->
begin
a = length(y) / 2.0 + shape(s2.distr)
b = sumabs2(y - mu) / 2.0 + scale(s2.distr)
b = sum(abs2, y - mu) / 2.0 + scale(s2.distr)
rand(InverseGamma(a, b))
end
)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Gibbs_s2 = Sampler([:s2],
(mu, s2, y) ->
begin
a = length(y) / 2.0 + shape(s2.distr)
b = sumabs2(y - mu) / 2.0 + scale(s2.distr)
b = sum(abs2, y - mu) / 2.0 + scale(s2.distr)
rand(InverseGamma(a, b))
end
)
Expand Down
4 changes: 2 additions & 2 deletions src/distributions/pdmats2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ module PDMats2
length(r) == n || throw(ArgumentError("incompatible array length"))
wx = whiten(a, x)
for j = 1:n
r[j] = sumabs2(wx[:, j])
r[j] = sum(abs2, wx[:, j])
end
r
end

invquad(a::PBDiagMat, x::Vector{Float64}) = sumabs2(whiten(a, x))
invquad(a::PBDiagMat, x::Vector{Float64}) = sum(abs2, whiten(a, x))


#################### Auxiliary Functions ####################
Expand Down
2 changes: 1 addition & 1 deletion src/output/chainsummary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Base.show(io::IO, s::ChainSummary)
cnwid = map(length, s.colnames)
## s.value as right alignable strings
charv = mapslices(showoff, s.value, 1)
colwid = 1 + max(cnwid, vec(maximum(map(length, charv), [1, 3])))
colwid = 1 + max.(cnwid, vec(maximum(map(length, charv), [1, 3])))
m, n, f = size(charv)
for k in 1:f
## write the column headers centered on the column widths
Expand Down
2 changes: 1 addition & 1 deletion src/output/gelmandiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ function gelmandiag(c::AbstractChains; alpha::Real=0.05, mpsrf::Bool=false,
end

hdr = header(c) * "\nGelman, Rubin, and Brooks Diagnostic:"
ChainSummary(round(psrf, 3), psrf_names, psrf_labels, hdr)
ChainSummary(round.(psrf, 3), psrf_names, psrf_labels, hdr)
end
2 changes: 1 addition & 1 deletion src/output/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function mixeddensityplot(c::AbstractChains;
plots = Array{Plot}(size(c, 2))
discrete = indiscretesupport(c, barbounds)
plots[discrete] = plot(c[:, discrete, :], :bar; args...)
plots[!discrete] = plot(c[:, !discrete, :], :density; args...)
plots[.!discrete] = plot(c[:, .!discrete, :], :density; args...)
return plots
end

Expand Down
4 changes: 2 additions & 2 deletions src/output/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function changerate(c::AbstractChains)
r_mv += any(delta)
end
end
vals = round([r; r_mv] / (m * (n - 1)), 3)
vals = round.([r; r_mv] / (m * (n - 1)), 3)
ChainSummary(vals, [c.names; "Multivariate"], ["Change Rate"], header(c))
end

Expand Down Expand Up @@ -89,6 +89,6 @@ function summarystats(c::AbstractChains; etype=:bm, args...)
mapslices(x -> f(x), c.value, [1, 3]),
[2, 1, 3]
)
stats = [vals min((vals[:, 2] ./ vals[:, 4]).^2, size(c.value, 1))]
stats = [vals min.((vals[:, 2] ./ vals[:, 4]).^2, size(c.value, 1))]
ChainSummary(stats, c.names, labels, header(c))
end
2 changes: 1 addition & 1 deletion src/samplers/abc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
function ABC{T<:Real}(params::ElementOrVector{Symbol},
scale::ElementOrVector{T}, summary::Function,
epsilon::Real; kernel::KernelDensityType=SymUniform,
dist::Function=(Tsim, Tobs) -> sqrt(sumabs2(Tsim - Tobs)),
dist::Function=(Tsim, Tobs) -> sqrt(sum(abs2, Tsim - Tobs)),
proposal::SymDistributionType=Normal, maxdraw::Integer=1,
nsim::Integer=1, decay::Real=1.0, randeps::Bool=false,
args...)
Expand Down
4 changes: 2 additions & 2 deletions src/samplers/amm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type AMMTune <: SamplerTune
function AMMTune{T<:Real}(x::Vector, Sigma::Matrix{T},
logf::Nullable{Function}; beta::Real=0.05,
scale::Real=2.38)
new(logf, false, beta, 0, Vector{Float64}(), Matrix{Float64}(), scale,
cholfact(Sigma)[:L], Matrix{Float64}())
new(logf, false, beta, 0, Vector{Float64}(), Matrix{Float64}(0, 0), scale,
cholfact(Sigma)[:L], Matrix{Float64}(0, 0))
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/samplers/bhmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ function sample!(v::BHMCVariate, logf::Function)
totaltime = 0.0 ## time the particle already moved

n = length(v) ## length of binary vector
S = sign(tune.position)
S = sign.(tune.position)

while true
a = tune.velocity[:]
b = tune.position[:]
phi = atan2(b, a)
phi = atan2.(b, a)

## time to hit or cross wall
walltime = -phi
Expand Down Expand Up @@ -117,6 +117,6 @@ function sample!(v::BHMCVariate, logf::Function)
end

## convert from (-/+1) to (0/1)
v[:] = (sign(tune.position) + ones(n)) / 2.0
v[:] = (sign.(tune.position) + ones(n)) / 2.0
v
end
4 changes: 2 additions & 2 deletions src/samplers/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function sample!(v::HMCVariate, logfgrad::Function)

## Evaluate potential and kinetic energies at start and end of trajectory
SigmaLinv = inv(tune.SigmaL)
Kp0 = 0.5 * sumabs2(SigmaLinv * p0)
Kp1 = 0.5 * sumabs2(SigmaLinv * p1)
Kp0 = 0.5 * sum(abs2, SigmaLinv * p0)
Kp1 = 0.5 * sum(abs2, SigmaLinv * p1)

if rand() < exp((logf1 - Kp1) - (logf0 - Kp0))
v[:] = x1
Expand Down
4 changes: 2 additions & 2 deletions src/samplers/mala.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function sample!(v::MALAVariate, logfgrad::Function)
y = v + M2 * grad0 + L * randn(length(v))
logf1, grad1 = logfgrad(y)

q0 = -0.5 * sumabs2(Linv * (v - y - M2 * grad1))
q1 = -0.5 * sumabs2(Linv * (y - v - M2 * grad0))
q0 = -0.5 * sum(abs2, Linv * (v - y - M2 * grad1))
q1 = -0.5 * sum(abs2, Linv * (y - v - M2 * grad0))

if rand() < exp((logf1 - q1) - (logf0 - q0))
v[:] = y
Expand Down
2 changes: 1 addition & 1 deletion src/samplers/miss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function MISSTune(d::Distribution, v)
end

function MISSTune(D::Array{UnivariateDistribution}, v::Array)
inds = find(isnan(v))
inds = find(isnan.(v))
MISSTune(dims(D), inds, inds)
end

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function logpdfgrad!{T<:Real}(block::SamplingBlock, x::AbstractVector{T},
dtype::Symbol)
grad = gradlogpdf!(block, x, dtype)
logf = logpdf!(block, x)
(logf, ifelse(isfinite(grad), grad, 0.0))
(logf, ifelse.(isfinite.(grad), grad, 0.0))
end

function unlist(block::SamplingBlock)
Expand Down

0 comments on commit 80c744d

Please sign in to comment.