Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing a non-accepted eval on a chain; candidate exchange chains with replacement. #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/mopt/AlgoBGP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mutable struct BGPChain <: AbstractChain
sigma_update_steps :: Int64 # update sampling vars every sigma_update_steps iterations
sigma_adjust_by :: Float64 # adjust sampling vars by sigma_adjust_by percent up or down
smpl_iters :: Int64 # max number of trials to get a new parameter from MvNormal that lies within support
min_improve :: Float64
min_improve :: Float64
batches :: Vector{UnitRange{Int}} # vector of indices to update together.

"""
Expand Down Expand Up @@ -93,7 +93,7 @@ mutable struct BGPChain <: AbstractChain
this.m = m
# how many bundles + rest
nb, rest = divrem(np,batch_size)
this.sigma = sig
this.sigma = sig
this.batches = UnitRange{Int}[]
i = 1
for ib in 1:nb
Expand Down Expand Up @@ -232,7 +232,7 @@ function set_eval!(c::BGPChain,ev::Eval)
else
c.curr_val[c.iter] = c.curr_val[c.iter-1]
end
if (ev.value < c.best_val[c.iter-1])
if (ev.value < c.best_val[c.iter-1]) & (ev.accepted==true)
c.best_val[c.iter] = ev.value
c.best_id[c.iter] = c.iter
else
Expand Down Expand Up @@ -262,7 +262,7 @@ end

Computes the next `Eval` for chain `c`:

1. Get last accepted param
1. Get last accepted param
2. get a new param via [`proposal`](@ref)
3. [`evaluateObjective`](@ref)
4. Accept or Reject the new value via [`doAcceptReject!`](@ref)
Expand Down Expand Up @@ -392,7 +392,7 @@ end
"""
proposal(c::BGPChain)

Gaussian Transition Kernel centered on current parameter value.
Gaussian Transition Kernel centered on current parameter value.

1. Map all ``k`` parameters into ``\\mu \\in [0,1]^k``.
2. update all parameters by sampling from `MvNormal`, ``N(\\mu,\\sigma)``, where ``sigma`` is `c.sigma` until all params are in ``[0,1]^k``
Expand All @@ -411,8 +411,8 @@ function proposal(c::BGPChain)

# map into [0,1]
# (x-a)/(b-a) = z \in [0,1]
mu01 = mapto_01(mu,lb,ub)
mu01 = mapto_01(mu,lb,ub)

# Transition Kernel is q(.|theta(t-1)) ~ TruncatedN(theta(t-1), Sigma,lb,ub)

# if there is only one batch of params
Expand Down Expand Up @@ -626,7 +626,7 @@ function exchangeMoves!(algo::MAlgoBGP)
props = [(i,j) for i in 1:algo["N"], j in 1:algo["N"] if (i<j)]
# N pairs of chains are chosen uniformly in all possibel pairs with replacement
samples = algo["N"] < 3 ? algo["N"]-1 : algo["N"]
pairs = sample(props,samples,replace=false)
pairs = sample(props,samples,replace=true)

# @debug(logger,"")
# @debug(logger,"exchangeMoves: proposing pairs")
Expand Down