overhaul presets system

This commit is contained in:
Connor Olding 2018-06-17 05:48:15 +02:00
parent 49dfcfe5b3
commit ebc494fb60
2 changed files with 207 additions and 163 deletions

View file

@ -1,7 +1,7 @@
local preset = rawget(_G, 'preset')
preset = preset ~= nil and preset ~= '' and preset or 'ars'
local common_cfg = {
local defaults = {
-- read-only modes:
playable_mode = false,
playback_mode = false,
@ -45,6 +45,7 @@ local common_cfg = {
deviation = 1.0,
unperturbed_trial = true, -- perform an extra trial without any noise.
-- this is good for logging, so i'd recommend it.
epoch_trials = 50,
graycode = false, -- for ARS.
negate_trials = true, -- try pairs of normal and negated noise directions.
-- AKA antithetic sampling. note that this doubles the number of trials.
@ -57,173 +58,23 @@ local common_cfg = {
sigma_decay = 0.0, -- for SNES, xNES.
}
local cfg
if preset == 'snes' then
cfg = {
es = 'snes',
log_fn = 'logs-snes.csv',
params_fn = 'params-snes.txt',
starting_lives = 1,
min_time = 300,
timer_loser = 1.0,
epoch_trials = 100,
negate_trials = false,
deviation = 1.0,
min_refresh = 0.2,
param_rate = 0.5,
sigma_rate = 0.1,
param_decay = 0.02, -- note: multiplied by its std, and param_rate.
sigma_decay = 0.01, -- note: multiplied by sigma_rate.
}
elseif preset == 'snes2' then
cfg = {
es = 'snes',
log_fn = 'logs-snes2.csv',
params_fn = 'params-snes2.txt',
start_big = true,
min_time = 300,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 0.5,
negate_trials = false,
min_refresh = 0.5,
epoch_trials = 100,
param_rate = 1.0,
sigma_rate = 0.01,
param_decay = 0.02,
sigma_decay = 0.01,
}
elseif preset == 'xnes' then
cfg = {
es = 'xnes',
log_fn = 'logs-xnes.csv',
params_fn = 'params-xnes.txt',
start_big = true,
min_time = 300,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 0.5,
negate_trials = false,
epoch_trials = 50,
param_rate = 1.0,
sigma_rate = 0.01,
covar_rate = 0.01,
}
elseif preset == 'xnes2' then
cfg = {
es = 'xnes',
log_fn = 'logs-xnes2.csv',
params_fn = 'params-xnes2.txt',
start_big = true,
min_time = 300,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 1.0,
negate_trials = true, --false,
epoch_trials = 10, --50,
param_rate = 0.5,
sigma_rate = 0.04,
covar_rate = 0.04,
param_decay = 0.004,
sigma_decay = 0.00128,
}
elseif preset == 'ars' then
cfg = {
es = 'ars',
epoch_top_trials = 20 * 2,
ars_lips = false,
log_fn = 'logs-ars.csv',
params_fn = 'params-ars.txt',
start_big = true,
min_time = 300,
timer_loser = 1.0,
bias_out = false,
deterministic = false,
graycode = false,
deviation = 0.1,
negate_trials = false,
epoch_trials = 25 * 2,
param_rate = 1.0,
param_decay = 0.0025,
}
elseif preset == 'play' then
cfg = {
playable_mode = true,
}
else
error("invalid preset: "..tostring(preset))
local presets = require("presets")
for _, cfg in pairs(presets) do
local parent = defaults
if cfg.parent ~= nil then
parent = presets[cfg.parent]
assert(parent, "no such parent preset: "..tostring(cfg.parent))
end
setmetatable(cfg, {__index=parent})
end
local cfg = presets[preset]
assert(cfg, "invalid preset: "..tostring(preset))
-- TODO: so, uhh..
-- what happens when playback_mode is true but unperturbed_trial is false?
setmetatable(cfg, {__index=common_cfg}) -- gets overridden later.
if cfg.es == 'ars' then
if cfg.param_rate == nil then cfg.param_rate = cfg.base_rate end
else
@ -232,9 +83,12 @@ end
if cfg.sigma_rate == nil then cfg.sigma_rate = cfg.base_rate end
if cfg.covar_rate == nil then cfg.covar_rate = cfg.sigma_rate end
local parent = getmetatable(cfg).__index
setmetatable(cfg, {
__index = function(t, n)
if common_cfg[n] ~= nil then return common_cfg[n] end
if parent ~= nil and parent[n] ~= nil then return parent[n] end
if n == 'name' then return nil end
if n == 'log_fn' then return nil end
if n == 'params_fn' then return nil end
if n == 'stats_fn' then return nil end

190
presets.lua Normal file
View file

@ -0,0 +1,190 @@
-- these are all still very experimental,
-- but they should at least give you a head-start.
local presets = {}
local function make_preset(cfg)
local name = cfg.name
if name ~= nil then
cfg.log_fn = cfg.log_fn or 'logs-'..name..'.csv'
cfg.params_fn = cfg.params_fn or 'params-'..name..'.txt'
end
presets[name] = cfg
return cfg
end
make_preset{
name = 'snes',
es = 'snes',
starting_lives = 1,
min_time = 300,
timer_loser = 1.0,
epoch_trials = 100,
negate_trials = false,
deviation = 1.0,
min_refresh = 0.2,
param_rate = 0.5,
sigma_rate = 0.1,
param_decay = 0.02,
sigma_decay = 0.01,
}
make_preset{
name = 'snes2',
es = 'snes',
start_big = true,
min_time = 300,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 0.5,
negate_trials = false,
min_refresh = 0.5,
epoch_trials = 100,
param_rate = 1.0,
sigma_rate = 0.01,
param_decay = 0.02,
sigma_decay = 0.01,
}
make_preset{
name = 'xnes',
es = 'xnes',
start_big = true,
min_time = 300,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 0.5,
negate_trials = false,
epoch_trials = 50,
param_rate = 1.0,
sigma_rate = 0.01,
covar_rate = 0.01,
}
make_preset{
name = 'xnes2',
es = 'xnes',
log_fn = 'logs-xnes4.csv',
params_fn = 'params-xnes4.txt',
start_big = true,
min_time = 300,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 1.0,
negate_trials = true, --false,
epoch_trials = 10, --50,
param_rate = 0.5,
sigma_rate = 0.04,
covar_rate = 0.04,
param_decay = 0.004,
sigma_decay = 0.00128,
}
make_preset{
name = 'xnes3',
es = 'xnes',
log_fn = 'logs-xnes5b.csv',
params_fn = 'params-xnes5b.txt',
start_big = true,
timer_loser = 1.0,
score_multiplier = 0,
init_zeros = true,
reduce_tiles = true,
bias_out = false,
deterministic = false,
deviation = 0.1207,
negate_trials = true,
epoch_trials = 10,
param_rate = 0.5,
sigma_rate = 0.16,
covar_rate = 0.04,
param_decay = 0.004, -- this should be ok now that it's mul by sigma.
sigma_decay = 0.00128, -- this might be okay... but watch out.
}
make_preset{
name = 'ars',
es = 'ars',
epoch_top_trials = 20 * 2,
ars_lips = false,
start_big = true,
min_time = 300,
timer_loser = 1.0,
bias_out = false,
deterministic = false,
graycode = false,
deviation = 0.1,
negate_trials = false,
epoch_trials = 25 * 2,
param_rate = 1.0,
param_decay = 0.0025,
}
make_preset{
name = 'play',
playable_mode = true,
}
return presets