From 66e5025e43fde614d6736c164bdb4305496a6c5d Mon Sep 17 00:00:00 2001 From: ZhiyiLi Date: Fri, 8 Nov 2024 14:43:21 +0800 Subject: [PATCH] adjust the parameter theraml_ratio to nburnin --- src/main.jl | 14 +++++++------- src/mcmc/montecarlo.jl | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.jl b/src/main.jl index 5da38ba..bc2fb39 100644 --- a/src/main.jl +++ b/src/main.jl @@ -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, @@ -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`). @@ -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=[], @@ -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 @@ -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) @@ -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 diff --git a/src/mcmc/montecarlo.jl b/src/mcmc/montecarlo.jl index cb3487a..0def570 100644 --- a/src/mcmc/montecarlo.jl +++ b/src/mcmc/montecarlo.jl @@ -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 @@ -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 @@ -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