本文整理汇总了Python中brain.Brain.save方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.save方法的具体用法?Python Brain.save怎么用?Python Brain.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_single_player
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import save [as 别名]
def train_single_player():
sim = DummyGame() # Breakout()
brain = Brain(sim.width, sim.height, sim.actions_count)
player = QLearn(sim, brain, "AI")
scorer = Scorer(stats_frequency)
for games in xrange(train_games):
play_single_player_game(player, sim, scorer, display_board=True)
# Save the model to disk and load it as an inference only model
model_path = brain.save(models_root)
print 'Saved trained model to', model_path
示例2: train_with_opponent
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import save [as 别名]
def train_with_opponent():
sim = Connect4()
if train_mode == "mixt":
opponents = [RandomPlayer("Rand")]
for idx, model_path in enumerate(os.listdir(models_root)):
full_path = os.path.join(models_root, model_path)
prev_brain = Brain(sim.width,
sim.height,
sim.actions_count,
load_path=full_path)
opponents.append(QLearn(sim, prev_brain, "v" + str(idx)))
elif train_mode == "random":
opponents = [RandomPlayer("Rand")]
elif train_mode == "minmax":
opponents = [MinMax(max_level=minmax_level)]
else:
raise ValueError, ("Invalid train_mode. Got %s expected "
"(mixt|random|minmax)") % train_mode
scorer = Scorer(stats_frequency)
for step in xrange(new_models):
brain = Brain(sim.width, sim.height, sim.actions_count)
player = QLearn(sim, brain, "AI")
w = [0.1 * i for i in xrange(1, len(opponents) + 1)]
p = [wi / sum(w) for wi in w]
for games in xrange(1, 100000):
if games % win_threshold_games == 0:
# If the new model wins more than 90% of the games of the last 300
win_statistics = scorer.get_statistics(win_threshold_games)[0]
if win_statistics > win_threshold_percentage:
# Save the model to disk and load it as an inference only model
model_path = brain.save(models_root)
prev_brain = Brain(sim.width,
sim.height,
sim.actions_count,
load_path=model_path)
opponents.append(QLearn(sim, prev_brain, "V" + str(step),
exploration_period=0, discount_factor=0.9))
print "-" * 70
print("New model wins %d%s against previous models after "
"%d games") % (win_statistics, "%", games)
print "-" * 70
print ''
break
opponent = np.random.choice(opponents, 1, p)[0]
players = [player, opponent]
play_game_with_opponent(players, sim, scorer)
human_player = HumanPlayer("Player")
while True:
play_game_with_opponent([opponents[-1], human_player], sim, scorer)