Skip to content

Commit 66e5025

Browse files
author
ZhiyiLi
committed
adjust the parameter theraml_ratio to nburnin
1 parent d3cdff9 commit 66e5025

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/main.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
block=16,
88
measure::Union{Nothing,Function}=nothing,
99
measurefreq::Int=1,
10-
thermal_ratio::Int=100,
10+
nburnin::Int=100,
1111
inplace::Bool=false,
1212
adapt=true,
1313
gamma=1.0,
@@ -36,7 +36,7 @@ Calculate the integrals, collect statistics, and return a `Result` struct contai
3636
- For `solver = :vegas` or `:vegasmc`, the function signature should be `measure(var, obs, relative_weights, config)`. Here, `obs` is a vector of observable values for each component of the integrand and `relative_weights` are the weights calculated from the integrand multiplied by the probability of the corresponding variables.
3737
- For `solver = :mcmc`, the signature should be `measure(idx, var, obs, relative_weight, config)`, where `obs` is the observable vector and `relative_weight` is the weight calculated from the `idx`-th integrand multiplied by the probability of the variables.
3838
- `measurefreq`: How often the measurement function is called (default: `1`).
39-
- `thermal_ratio` : Tha thermalization steps to total steps ratio for MCMC method
39+
- `nburnin` : Tha thermalization steps for MCMC method
4040
- `inplace`: Whether to use the inplace version of the integrand. Default is `false`, which is more convenient for integrand with a few return values but may cause type instability. Only useful for the :vegas and :vegasmc solver.
4141
- `adapt`: Whether to adapt the grid and the reweight factor (default: `true`).
4242
- `gamma`: Learning rate of the reweight factor after each iteration (default: `1.0`).
@@ -82,7 +82,7 @@ function integrate(integrand::Function;
8282
ignore::Int=adapt ? 1 : 0, #ignore the first `ignore` iterations in average
8383
measure::Union{Nothing,Function}=nothing,
8484
measurefreq::Int=1,
85-
thermal_ratio::Int = 100,
85+
nburnin::Int = 100,
8686
inplace::Bool=false, # whether to use the inplace version of the integrand
8787
parallel::Symbol=:nothread, # :thread or :nothread
8888
print=-1, printio=stdout, timer=[],
@@ -154,13 +154,13 @@ function integrate(integrand::Function;
154154
Threads.@threads for _ in 1:block/MCUtility.mpi_nprocs()
155155
_block!(configs, obsSum, obsSquaredSum, summedConfig, solver, progress,
156156
integrand, nevalperblock, print, timer, debug,
157-
measure, measurefreq, thermal_ratio, inplace, parallel)
157+
measure, measurefreq, nburnin, inplace, parallel)
158158
end
159159
else
160160
for _ in 1:block/MCUtility.mpi_nprocs()
161161
_block!(configs, obsSum, obsSquaredSum, summedConfig, solver, progress,
162162
integrand, nevalperblock, print, timer, debug,
163-
measure, measurefreq, thermal_ratio, inplace, parallel)
163+
measure, measurefreq, nburnin, inplace, parallel)
164164
end
165165
end
166166
end
@@ -236,7 +236,7 @@ end
236236
function _block!(configs, obsSum, obsSquaredSum, summedConfig,
237237
solver, progress,
238238
integrand::Function, nevalperblock, print, timer, debug::Bool,
239-
measure::Union{Nothing,Function}, measurefreq, thermal_ratio, inplace, parallel)
239+
measure::Union{Nothing,Function}, measurefreq, nburnin, inplace, parallel)
240240

241241
rank = MCUtility.threadid(parallel)
242242
# println(rank)
@@ -252,7 +252,7 @@ function _block!(configs, obsSum, obsSquaredSum, summedConfig,
252252
measure=measure, measurefreq=measurefreq, inplace=inplace)
253253
elseif solver == :mcmc
254254
MCMC.montecarlo(config_n, integrand, nevalperblock, print, timer, debug;
255-
measure=measure, measurefreq=measurefreq, thermal_ratio = thermal_ratio)
255+
measure=measure, measurefreq=measurefreq, nburnin = nburnin)
256256
else
257257
error("Solver $solver is not supported!")
258258
end

src/mcmc/montecarlo.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function montecarlo(config::Configuration{N,V,P,O,T}, integrand::Function, neval
7474
measurefreq::Int=1,
7575
measure::Union{Nothing,Function}=nothing,
7676
idx::Int=1, # the integral to start with
77-
thermal_ratio::Int=100
77+
nburnin::Int=100
7878
) where {N,V,P,O,T}
7979

8080
@assert measurefreq > 0
@@ -131,7 +131,7 @@ function montecarlo(config::Configuration{N,V,P,O,T}, integrand::Function, neval
131131
# end
132132
startTime = time()
133133

134-
for i = 1:neval
134+
for i = 1:(neval+nburnin)
135135
# config.neval += 1
136136
config.visited[state.curr] += 1
137137
_update = rand(config.rng, updates) # randomly select an update
@@ -141,7 +141,7 @@ function montecarlo(config::Configuration{N,V,P,O,T}, integrand::Function, neval
141141
if debug && (isfinite(state.probability) == false)
142142
@warn("integrand probability = $(state.probability) is not finite at step $(config.neval)")
143143
end
144-
if i % measurefreq == 0 && i >= neval / thermal_ratio
144+
if i % measurefreq == 0 && i >= nburnin
145145

146146
######## accumulate variable #################
147147
if state.curr != config.norm

0 commit comments

Comments
 (0)