O'Reilly logo

Python Reinforcement Learning Projects by Rajalingappaa Shanmugamani, Yang Wenzhuo, Sean Saito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

mcts.py

mcts.py contains our implementation of Monte Carlo tree search. Our first class is RootNode, which is meant to represent the root node of the MCTS tree at the start of a simulation. By definition, the root node does not have a parent. Having a separate class for the root node is not absolutely necessary, but it does keep the code cleaner:

import collectionsimport mathimport numpy as npimport utilsfrom config import MCTSPARAMETERS, GOPARAMETERSclass RootNode(object):    def __init__(self):        self.parent_node = None        self.child_visit_counts = collections.defaultdict(float)        self.child_cumulative_rewards = collections.defaultdict(float)

Next, we implement the MCTreeSearchNode class. This class has several attributes, the most important ones ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required