Go to the documentation of this file.
14 #ifndef INCLUDED_protocols_elscripts_module_MonteCarlo_hh
15 #define INCLUDED_protocols_elscripts_module_MonteCarlo_hh
22 std::string MonteCarlo = R
"DELIM(
----- MonteCarlo Module ------
if modules == nil then
modules = {}
setmetatable( modules, {__index = _G} )
end
modules.MonteCarlo = function ( pose, mover, filter, trials, temp)
if pose == nil then error("Syntax: modules.MonteCarlo( pose, mover, filter, optional: trials, temp )") end
if mover == nil then error("Syntax: modules.MonteCarlo( pose, mover, filter, optional: trials, temp )") end
if filter == nil then error("Syntax: modules.MonteCarlo( pose, mover, filter, optional: trials, temp )") end
if trials == nil then trials = 10 end
if temp == nil then temp = 1 end
math.randomseed( os.time() )
local oldscore = filter( pose )
local accepted = pose:clone()
local working_pose = pose:clone()
local accept_counter = 0
for i=1,trials do
mover( working_pose )
local currentscore = filter( working_pose )
if currentscore == nil then error('Filter function returning nil, fix that') end
if currentscore < oldscore then
accept_counter = accept_counter + 1
accepted = working_pose
oldscore = currentscore
elseif math.random() >= math.exp( math.min(40, math.max( -40, (oldscore - currentscore)/temp ) ) ) then
accept_counter = accept_counter + 1
accepted = working_pose
oldscore = currentscore
end
end
print('Finished Monte Carlo. Out of '..trials..' trials '..accept_counter..' accepted')
end
)DELIM";