A simple implement for MCTS algorithm.
Project description
PyMCT
This is a simple implement for Manto Carlo Tree Search algorithm.
Example
from cmath import inf
from random import randint, random
from PyMCT.MCT import MCTNode, MCTS
from typing import Union, List
from anytree import RenderTree
create a implement of MCTS class that has unique reward function, expand function and terminate condition.
class testMCTS(MCTS):
def __init__(self, root: MCTNode, c: Union[int, float], max_iter: int, debug=False) -> None:
super().__init__(root, c, max_iter, debug)
def get_reward(self, node: MCTNode):
node._reward = node.state
def expand(self, node: MCTNode) -> List[MCTNode]:
continue_chance = random()
if continue_chance <1:
for i in range(1,randint(1,5)):
new_node = MCTNode(state=(self.root.depth+1)*i,parent=node)
return node.children
def terminate(self) -> bool:
for node in self.root.descendants:
if node.uct == inf:
return False
if self.root.height >= 3:
return True
else:
return False
pass the root
test_mcts = testMCTS(root=root, c=2, debug=True, max_iter=100)
start the seacrh
test_mcts.iterate()
render the tree
print(RenderTree(test_mcts.root))
print the optimal path
test_mcts.find_optimal_path()
print(test_mcts.optimal_path)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
PyMCT-1.0.3.tar.gz
(16.0 kB
view details)
Built Distribution
PyMCT-1.0.3-py3-none-any.whl
(16.5 kB
view details)
File details
Details for the file PyMCT-1.0.3.tar.gz
.
File metadata
- Download URL: PyMCT-1.0.3.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc4cf62b50e9f671eb79535cc968451a75136c50309dfc8621c1dd7cef36dad7 |
|
MD5 | 430d7920199f22ab78eb9f58963d3e1a |
|
BLAKE2b-256 | 0cd56a42ee93d0faa625eef121e3aefac917f380ff946d8b18afa3329a22b147 |
File details
Details for the file PyMCT-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: PyMCT-1.0.3-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 314842cac70e3adc6a82338f1c165faf005c5eb3a13b48a0cab1d037ef9e903f |
|
MD5 | 8f83c90f7f6a11421b21c5d5b7870968 |
|
BLAKE2b-256 | 092ba3eff7d0d109336da4ce7674d8d4f24bec78f8c82c372c26b6de691889f5 |