backgammon/bin/train-evaluate-save

70 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-03-28 13:32:22 +00:00
#!/usr/bin/env ruby
2018-05-22 13:15:36 +00:00
MODELS_DIR = 'models'
2018-03-28 13:32:22 +00:00
def save(model_name)
require 'date'
2018-05-22 13:15:36 +00:00
model_path = File.join(MODELS_DIR, model_name)
2018-03-28 13:32:22 +00:00
episode_count = (File.read File.join(model_path, 'episodes_trained')).to_i
puts "Found model #{model_name} with episodes #{episode_count} trained!"
file_name = "model-#{model_name}-#{episode_count}-#{Time.now.strftime('%Y%m%d-%H%M%S')}.tar.gz"
2018-05-22 13:15:36 +00:00
save_path = File.join(MODELS_DIR, 'saves', file_name)
2018-03-28 13:32:22 +00:00
puts "Saving to #{save_path}"
2018-05-22 13:15:36 +00:00
system("tar", "-cvzf", save_path, "-C", MODELS_DIR, model_name)
2018-03-28 13:32:22 +00:00
end
def train(model, episodes)
system("python3", "main.py", "--train", "--model", model, "--episodes", episodes.to_s)
end
2018-05-22 13:15:36 +00:00
def force_train(model, episodes)
system("python3", "main.py", "--train", "--force-creation", "--model", model, "--episodes", episodes.to_s)
end
2018-03-28 13:32:22 +00:00
def evaluate(model, episodes, method)
system("python3", "main.py", "--eval" , "--model", model, "--episodes", episodes.to_s, "--eval-methods", method)
end
model = ARGV[0]
if model.nil? then raise "no model specified" end
2018-05-22 13:15:36 +00:00
if not File.exists? File.join(MODELS_DIR, model) then
force_train model, 10
2018-03-28 13:32:22 +00:00
save model
3.times do
evaluate model, 250, "pubeval"
end
3.times do
evaluate model, 250, "dumbeval"
end
end
2018-05-22 13:15:36 +00:00
# while true do
# save model
# train model, 1000
# save model
# train model, 1000
# 3.times do
# evaluate model, 250, "pubeval"
# end
# 3.times do
# evaluate model, 250, "dumbeval"
# end
# end
while true do
save model
train model, 500
5.times do
evaluate model, 250, "pubeval"
end
5.times do
evaluate model, 250, "dumbeval"
end
end