@@ -24,11 +24,13 @@ class MCTS(BaseObject):
2424 ----------
2525 states : list[str], optional, default=None
2626 Possible values for the nodes. Underscores indicate whether the values are
27- supposed to be prepended or appended to the sequence.
27+ supposed to be prepended or appended to the sequence. Must be non-empty and
28+ contain unique entries.
2829 depth : int, optional, default=20
29- Maximum depth of the search tree, also the length of the generated sequences.
30+ Maximum depth of the search tree, also the length of the generated
31+ sequences. Must be >= 1.
3032 n_iterations : int, optional, default=1000
31- Number of iterations per round for the MCTS algorithm.
33+ Number of iterations per round for the MCTS algorithm. Must be >= 1.
3234 experiment : BaseAptamerEval, optional, default=None
3335 An instance of an experiment class definingthe goal function for the algorithm.
3436
@@ -74,17 +76,23 @@ def __init__(
7476 n_iterations : int = 1000 ,
7577 experiment = None ,
7678 ) -> None :
79+ if depth < 1 :
80+ raise ValueError (f"`depth` must be >= 1, got { depth } ." )
7781 if n_iterations < 1 :
7882 raise ValueError (f"`n_iterations` must be >= 1, got { n_iterations } ." )
7983
84+ if states is None :
85+ states = ["A_" , "C_" , "G_" , "U_" , "_A" , "_C" , "_G" , "_U" ]
86+ elif not states :
87+ raise ValueError ("`states` must contain at least one entry." )
88+ elif len (states ) != len (set (states )):
89+ raise ValueError ("`states` must contain unique entries." )
90+
8091 self .experiment = experiment
8192 self .depth = depth
8293 self .n_iterations = n_iterations
8394
8495 super ().__init__ ()
85-
86- if states is None :
87- states = ["A_" , "C_" , "G_" , "U_" , "_A" , "_C" , "_G" , "_U" ]
8896 self .states = states
8997
9098 self .root = TreeNode (
0 commit comments