Skip to content

Commit a373707

Browse files
committed
minor things, typos and alike
1 parent 3100ad8 commit a373707

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/SimulatedAnnealingABC.jl

+16-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Holds state of algorithm
2727
"""
2828
mutable struct SABCstate
2929
ϵ::Vector{Float64} # epsilon = temperature
30-
algorithm::Symbol # the algorithm used
30+
algorithm::Symbol # the algorithm used
3131

3232
# Containers to store trajectories
3333
ϵ_history::Vector{Vector{Float64}}
@@ -50,6 +50,8 @@ Holds results from a SABC run with fields:
5050
- `state`: state of algorithm
5151
5252
The history of ϵ can be accessed with the field `state.ϵ_history`.
53+
The history of ρ can be accessed with the field `state.ρ_history`.
54+
The history of u can be accessed with the field `state.u_history`.
5355
"""
5456
struct SABCresult{T, S}
5557
population::Vector{T}
@@ -66,17 +68,18 @@ function show(io::Base.IO, s::SABCresult)
6668
mean_u = round(mean(s.u), sigdigits = 4)
6769
acc_rate = round(s.state.n_accept / (s.state.n_simulation - n_particles),
6870
sigdigits = 4)
69-
7071
println(io, "Approximate posterior sample with $n_particles particles:")
7172
println(io, " - algorithm: :$(s.state.algorithm)")
7273
println(io, " - simulations used: $(s.state.n_simulation)")
7374
println(io, " - number of population updates: $(s.state.n_population_updates)")
7475
println(io, " - average transformed distance: $mean_u")
7576
println(io, " - ϵ: $(round.(s.state.ϵ, sigdigits=4))")
76-
println(io, " - population resampling: $(s.state.n_resampling)")
77+
println(io, " - number of population resamplings: $(s.state.n_resampling)")
7778
println(io, " - acceptance rate: $(acc_rate)")
7879
println(io, "The sample can be accessed with the field `population`.")
7980
println(io, "The history of ϵ can be accessed with the field `state.ϵ_history`.")
81+
println(io, "The history of ρ can be accessed with the field `state.ρ_history`.")
82+
println(io, "The history of u can be accessed with the field `state.u_history`.")
8083
end
8184

8285
# -------------------------------------------
@@ -93,7 +96,7 @@ function update_epsilon_single_stat(ū, v)
9396
end
9497

9598
"""
96-
Update ϵ for multi-epsilons. See eq(19-20) in Albert et al. (in preparatory).
99+
Update ϵ for multi-epsilons. See eq(19-20) in Albert et al. (in preparation)
97100
"""
98101
function update_epsilon_multi_stats(u, v)
99102
n = size(u, 2) # number of statistics
@@ -120,10 +123,9 @@ end
120123
Resample population
121124
"""
122125
function resample_population(population, u, δ)
123-
124126
n = length(population)
125-
u_means = mean(u, dims=1)
126-
w = exp.(-sum(u[:,i] .* δ ./ u_means[i] for i in 1:size(u, 2)))
127+
= mean(u, dims=1)
128+
w = exp.(-sum(u[:,i] .* δ ./ [i] for i in 1:size(u, 2)))
127129
# Choose indexes based on weights w
128130
idx_resampled = sample(1:n, weights(w), n, replace=true)
129131
# Apply selected indexes to population and u's
@@ -160,7 +162,7 @@ proposal(θ, Σ::Float64) = θ + rand(Normal(0, sqrt(Σ)))
160162
## Arguments
161163
See docs for `sabc`
162164
163-
## Return
165+
## Returns
164166
- An object of type `SABCresult`
165167
"""
166168
function initialization(f_dist, prior::Distribution, args...;
@@ -194,7 +196,6 @@ function initialization(f_dist, prior::Distribution, args...;
194196
end
195197
ρ_history = [[mean(ic) for ic in eachcol(distances_prior)]]
196198

197-
198199
# ------------------
199200
# Estimate the cdf of ρ under the prior
200201

@@ -223,10 +224,12 @@ function initialization(f_dist, prior::Distribution, args...;
223224
u_history = [[mean(ic) for ic in eachcol(u)]]
224225
ϵ_history = [copy(ϵ)]
225226

227+
# ------------------
228+
# estimate jump covariance
226229
Σ_jump = estimate_jump_covariance(population, β)
227230

228231
# ---------------------
229-
# Collect parameters and states of the algorithm
232+
# Collect parameters and state of the algorithm
230233

231234
n_simulation = n_particles # N.B.: we consider only n_particles draws from the prior
232235
# and neglect the first call to f_dist ('initialization of containers')
@@ -290,8 +293,8 @@ function update_population!(population_state::SABCresult, f_dist, prior, args...
290293

291294
n_particles = length(population)
292295

293-
n_population_updates = n_simulation ÷ n_particles # populations update = total simulations / particles
294-
n_updates = n_population_updates * n_particles # number of calls to `f_dist`
296+
n_population_updates = n_simulation ÷ n_particles # population updates = total simulations / particles
297+
n_updates = n_population_updates * n_particles # number of calls to `f_dist` (individual particle updates)
295298
last_checkpoint_epsilon = 0 # set checkpoint counter to zero
296299

297300
# to estimate ETA
@@ -303,6 +306,7 @@ function update_population!(population_state::SABCresult, f_dist, prior, args...
303306
pmeter = Progress(n_population_updates; desc = "$n_population_updates population updates:",
304307
output = stderr, enabled = show_progressbar)
305308
generate_showvalues(ϵ, u) = () -> [("ϵ", round.(ϵ, sigdigits=4)), ("average transformed distance", round.(mean(u), sigdigits=4))]
309+
306310
for ix in 1:n_population_updates
307311

308312
# ----------------------------------------------------------

0 commit comments

Comments
 (0)