(
tree_dict: Dict[str, Any],
max_num_children: int,
c_puct: float,
root_tag: str = "0",
)
| 52 | |
| 53 | |
| 54 | def rebuild_tree( |
| 55 | tree_dict: Dict[str, Any], |
| 56 | max_num_children: int, |
| 57 | c_puct: float, |
| 58 | root_tag: str = "0", |
| 59 | ) -> Tuple[Type[InferNoder], int]: |
| 60 | root = InferNode( |
| 61 | parent=None, |
| 62 | tag=root_tag, |
| 63 | c_puct=c_puct, |
| 64 | **tree_dict[root_tag], |
| 65 | ) |
| 66 | candidates = [root] |
| 67 | max_depth = 0 |
| 68 | while candidates: |
| 69 | node = candidates.pop(0) |
| 70 | for idx in range(max_num_children): |
| 71 | tag = f"{node.tag}.{idx}" |
| 72 | depth = node.depth + 1 |
| 73 | if tag in tree_dict: |
| 74 | child = InferNode( |
| 75 | parent=node, |
| 76 | tag=tag, |
| 77 | depth=depth, |
| 78 | c_puct=c_puct, |
| 79 | **tree_dict[tag], |
| 80 | ) |
| 81 | max_depth = max(max_depth, depth) |
| 82 | node.children.append(child) |
| 83 | candidates.append(child) |
| 84 | return root, max_depth |
| 85 | |
| 86 | |
| 87 | def is_valid_final_answer_node(node: Type[InferNode]) -> bool: |
no test coverage detected