def undo(self, index): super(MCTSPlayer, self).undo(index) self.probability = self.prob_history.pop() if self.mct.root.parent and self.mct.root.parent.parent: self.mct.root = self.mct.root.parent.parent else: self.mct.root = MCTNode(None, 1.0)
def one_iteration(worker_env): env = make_env() evals_before = env.count_evals() time_before = time.time() root = construct_root_node(args, env) mct_root = MCTNode(root) mct_search(mct_root, expand_visits=args.mcts_expand, num_steps=args.mcts_num_steps, fitness=env.fitness, finish=env.finish, is_finished=env.is_finished, successors=env.successors, early_end_test=env.early_end_test, sample_by_urgency=args.mcts_sample_by_urgency, urgency_method=args.mcts_urgency_method, urgency_c_uct_explore=args.mcts_urgency_c_uct) env.cache.print_self("AT END") if args.print_size_hist: print_k_histogram(domain) return mct_root.best_score, env.count_evals( ) - evals_before, time.time() - time_before
def test_mcts(self): env = domain_parity_apptree.make_env_app_tree() node = MCTNode(UFTNode(UnfinishedLeaf(), 3)) run_basic_mcts(node, env, 1, 3)
def test_mcts(self): env = domain_parity_stack.make_env_stack() node = MCTNode(StackNode([])) run_basic_mcts(node, env, 1, 3)
def test_mcts(self): env = domain_koza_stack.make_env_stack(5) node = MCTNode(StackNode([])) run_basic_mcts(node, env)
def test_mcts(self): env = domain_koza_apptree.make_env_app_tree() node = MCTNode(ChooseKTNode(UnfinishedLeaf(), 5)) run_basic_mcts(node, env)
from mcts import MCTNode, mct_search from nmcs import nested_mc_search from domain_koza_apptree import make_env_app_tree from domain_koza_stack import make_env_stack from tree_node import ChooseKTNode, StackNode from tree_stats import TreeStats from utils import experiment_eval if __name__ == "__main__": make_env = make_env_app_tree #make_env = lambda: make_env_stack(20) if False: # MCTS - one run env = make_env() # tracer_deco.enable_tracer = True # random.seed(5) tree_stats = TreeStats() # root = MCTNode(ChooseKTNode(UnfinishedLeaf(), 5)) root = MCTNode(StackNode([])) mct_search(root, expand_visits=8, num_steps=4000, fitness=env.fitness, finish=env.finish, is_finished=env.is_finished, successors=env.successors, tree_stats=tree_stats) print('=' * 20) print(root.pretty_str()) print(tree_stats.pretty_str())