Skip to content

Commit

Permalink
adjust the parameter theraml_ratio to nburnin
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiyiLi committed Nov 8, 2024
1 parent d3cdff9 commit 66e5025
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
block=16,
measure::Union{Nothing,Function}=nothing,
measurefreq::Int=1,
thermal_ratio::Int=100,
nburnin::Int=100,
inplace::Bool=false,
adapt=true,
gamma=1.0,
Expand Down Expand Up @@ -36,7 +36,7 @@ Calculate the integrals, collect statistics, and return a `Result` struct contai
- 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.
- 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.
- `measurefreq`: How often the measurement function is called (default: `1`).
- `thermal_ratio` : Tha thermalization steps to total steps ratio for MCMC method
- `nburnin` : Tha thermalization steps for MCMC method
- `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.
- `adapt`: Whether to adapt the grid and the reweight factor (default: `true`).
- `gamma`: Learning rate of the reweight factor after each iteration (default: `1.0`).
Expand Down Expand Up @@ -82,7 +82,7 @@ function integrate(integrand::Function;
ignore::Int=adapt ? 1 : 0, #ignore the first `ignore` iterations in average
measure::Union{Nothing,Function}=nothing,
measurefreq::Int=1,
thermal_ratio::Int = 100,
nburnin::Int = 100,
inplace::Bool=false, # whether to use the inplace version of the integrand
parallel::Symbol=:nothread, # :thread or :nothread
print=-1, printio=stdout, timer=[],
Expand Down Expand Up @@ -154,13 +154,13 @@ function integrate(integrand::Function;
Threads.@threads for _ in 1:block/MCUtility.mpi_nprocs()
_block!(configs, obsSum, obsSquaredSum, summedConfig, solver, progress,
integrand, nevalperblock, print, timer, debug,
measure, measurefreq, thermal_ratio, inplace, parallel)
measure, measurefreq, nburnin, inplace, parallel)
end
else
for _ in 1:block/MCUtility.mpi_nprocs()
_block!(configs, obsSum, obsSquaredSum, summedConfig, solver, progress,
integrand, nevalperblock, print, timer, debug,
measure, measurefreq, thermal_ratio, inplace, parallel)
measure, measurefreq, nburnin, inplace, parallel)
end
end
end
Expand Down Expand Up @@ -236,7 +236,7 @@ end
function _block!(configs, obsSum, obsSquaredSum, summedConfig,
solver, progress,
integrand::Function, nevalperblock, print, timer, debug::Bool,
measure::Union{Nothing,Function}, measurefreq, thermal_ratio, inplace, parallel)
measure::Union{Nothing,Function}, measurefreq, nburnin, inplace, parallel)

rank = MCUtility.threadid(parallel)
# println(rank)
Expand All @@ -252,7 +252,7 @@ function _block!(configs, obsSum, obsSquaredSum, summedConfig,
measure=measure, measurefreq=measurefreq, inplace=inplace)
elseif solver == :mcmc
MCMC.montecarlo(config_n, integrand, nevalperblock, print, timer, debug;
measure=measure, measurefreq=measurefreq, thermal_ratio = thermal_ratio)
measure=measure, measurefreq=measurefreq, nburnin = nburnin)
else
error("Solver $solver is not supported!")
end
Expand Down
6 changes: 3 additions & 3 deletions src/mcmc/montecarlo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function montecarlo(config::Configuration{N,V,P,O,T}, integrand::Function, neval
measurefreq::Int=1,
measure::Union{Nothing,Function}=nothing,
idx::Int=1, # the integral to start with
thermal_ratio::Int=100
nburnin::Int=100
) where {N,V,P,O,T}

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

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

######## accumulate variable #################
if state.curr != config.norm
Expand Down

0 comments on commit 66e5025

Please sign in to comment.