treequest 0.3.1__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {treequest-0.3.1 → treequest-0.3.2}/PKG-INFO +2 -1
- {treequest-0.3.1 → treequest-0.3.2}/README.md +1 -0
- {treequest-0.3.1 → treequest-0.3.2}/pyproject.toml +1 -1
- treequest-0.3.2/src/treequest/__init__.py +40 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/ab_mcts_a/prob_state.py +24 -12
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/ab_mcts_m/algo.py +49 -1
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/ab_mcts_m/pymc_interface.py +35 -6
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/tree.py +9 -1
- treequest-0.3.1/src/treequest/__init__.py +0 -33
- {treequest-0.3.1 → treequest-0.3.2}/.gitignore +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/LICENSE +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/ab_mcts_a/algo.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/ab_mcts_m/_ab_mcts_m_imports.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/ab_mcts_m/numpyro_utils.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/base.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/best_first_search.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/multi_armed_bandit_ucb.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/standard_mcts.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/algos/tree_of_thought_bfs.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/imports.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/py.typed +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/ranker.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/trial.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/types.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/__init__.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/__init__.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/ab_mcts_a.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/ab_mcts_m.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/base.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/best_first_search.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/multi_armed_bandit_ucb.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/standard_mcts.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/tree_of_thoughts_bfs.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/assets/colormaps.json +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/assets/d3.LICENSE.txt +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/assets/d3.v7.min.js +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/assets/d3_tree.html.jinja2 +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/build_snapshot.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/errors.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/render.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/renderers/__init__.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/renderers/color_utils.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/renderers/graphviz_renderer.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/renderers/html.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/renderers/json_yaml.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/renderers/mermaid.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/snapshot.py +0 -0
- {treequest-0.3.1 → treequest-0.3.2}/src/treequest/visualization.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: treequest
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: A Tree Search Library with Flexible API for LLM Inference-Time Scaling
|
|
5
5
|
Author-email: Kou Misaki <kou.misaki@sakana.ai>, Takuya Akiba <takiba@sakana.ai>
|
|
6
6
|
License-File: LICENSE
|
|
@@ -237,6 +237,7 @@ The variation is not limited to LLM types; you can use different prompts, action
|
|
|
237
237
|
- Idempotent: calling `tell` twice on the same `trial_id` does not add extra nodes.
|
|
238
238
|
- For queue-based algorithms, over-told Trials beyond possible number of childs from a parent node (e.g., `(# actions)*samples_per_action` for StandardMCTS) become `INVALID` and are not reflected.
|
|
239
239
|
- Scores are expected to be normalized to the `[0, 1]` range.
|
|
240
|
+
- `ABMCTSM` exposes an internal `_advanced_config` for advanced knobs (e.g., bypassing the runtime check or tuning Bayesian priors). In most cases, the defaults are sufficient; only change it if you understand the impact.
|
|
240
241
|
|
|
241
242
|
## Algorithms
|
|
242
243
|
|
|
@@ -201,6 +201,7 @@ The variation is not limited to LLM types; you can use different prompts, action
|
|
|
201
201
|
- Idempotent: calling `tell` twice on the same `trial_id` does not add extra nodes.
|
|
202
202
|
- For queue-based algorithms, over-told Trials beyond possible number of childs from a parent node (e.g., `(# actions)*samples_per_action` for StandardMCTS) become `INVALID` and are not reflected.
|
|
203
203
|
- Scores are expected to be normalized to the `[0, 1]` range.
|
|
204
|
+
- `ABMCTSM` exposes an internal `_advanced_config` for advanced knobs (e.g., bypassing the runtime check or tuning Bayesian priors). In most cases, the defaults are sufficient; only change it if you understand the impact.
|
|
204
205
|
|
|
205
206
|
## Algorithms
|
|
206
207
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
# Expose the real symbol to static type checkers / IDEs even when optional
|
|
5
|
+
# dependencies for ABMCTSM are not installed at runtime.
|
|
6
|
+
from .algos.ab_mcts_m.algo import ABMCTSM
|
|
7
|
+
else:
|
|
8
|
+
from .algos.ab_mcts_m._ab_mcts_m_imports import _import as _ab_mcts_m_import
|
|
9
|
+
|
|
10
|
+
if not _ab_mcts_m_import.is_successful():
|
|
11
|
+
# Create a placeholder that raises an informative error when accessed
|
|
12
|
+
class _ABMCTSMPlaceholder:
|
|
13
|
+
def __getattr__(self, name): # type: ignore
|
|
14
|
+
_ab_mcts_m_import.check()
|
|
15
|
+
raise ImportError("ABMCTSM import failed.")
|
|
16
|
+
|
|
17
|
+
def __call__(self, *args, **kwargs): # type: ignore
|
|
18
|
+
_ab_mcts_m_import.check()
|
|
19
|
+
raise ImportError("ABMCTSM import failed.")
|
|
20
|
+
|
|
21
|
+
ABMCTSM = _ABMCTSMPlaceholder() # type: ignore
|
|
22
|
+
else:
|
|
23
|
+
from .algos.ab_mcts_m.algo import ABMCTSM # type: ignore[assignment]
|
|
24
|
+
|
|
25
|
+
from .algos.ab_mcts_a.algo import ABMCTSA
|
|
26
|
+
from .algos.base import Algorithm
|
|
27
|
+
from .algos.standard_mcts import StandardMCTS
|
|
28
|
+
from .algos.tree_of_thought_bfs import TreeOfThoughtsBFSAlgo
|
|
29
|
+
from .ranker import top_k
|
|
30
|
+
from .vis import render
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"StandardMCTS",
|
|
34
|
+
"top_k",
|
|
35
|
+
"TreeOfThoughtsBFSAlgo",
|
|
36
|
+
"ABMCTSA",
|
|
37
|
+
"ABMCTSM",
|
|
38
|
+
"Algorithm",
|
|
39
|
+
"render",
|
|
40
|
+
]
|
|
@@ -13,6 +13,24 @@ from treequest.algos.tree import Node
|
|
|
13
13
|
T = TypeVar("T")
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
def _child_index_by_identity(parent: Node, child: Node) -> int:
|
|
17
|
+
"""
|
|
18
|
+
Return the index of `child` in `parent.children` using identity comparison.
|
|
19
|
+
|
|
20
|
+
NOTE: Avoid `list.index()` here because it relies on `__eq__`, and user-defined
|
|
21
|
+
states may include objects (e.g., numpy arrays / torch tensors) whose equality
|
|
22
|
+
returns non-bool values and can raise when coerced to `bool`.
|
|
23
|
+
"""
|
|
24
|
+
for i, n in enumerate(parent.children):
|
|
25
|
+
if n is child:
|
|
26
|
+
return i
|
|
27
|
+
raise ValueError(
|
|
28
|
+
"Child node not found in parent.children by identity. "
|
|
29
|
+
f"child.expand_idx={getattr(child, 'expand_idx', None)}, "
|
|
30
|
+
f"parent.expand_idx={getattr(parent, 'expand_idx', None)}"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
16
34
|
@dataclasses.dataclass
|
|
17
35
|
class BetaPrior:
|
|
18
36
|
"""
|
|
@@ -278,18 +296,15 @@ class NodeProbState:
|
|
|
278
296
|
assert node.parent is not None
|
|
279
297
|
|
|
280
298
|
# Update for continuing with existing nodes
|
|
299
|
+
child_idx = _child_index_by_identity(node.parent, node)
|
|
281
300
|
if self.model_selection_strategy.startswith("multiarm_bandit_"):
|
|
282
301
|
# Update the node's probability
|
|
283
|
-
self.node_probas["shared"][
|
|
284
|
-
node.parent.children.index(node)
|
|
285
|
-
].tell_observation(reward)
|
|
302
|
+
self.node_probas["shared"][child_idx].tell_observation(reward)
|
|
286
303
|
# For multiarm bandit strategies, update shared CONT distribution
|
|
287
304
|
self.gen_vs_cont_probas["shared"]["CONT"].tell_observation(reward)
|
|
288
305
|
else:
|
|
289
306
|
# Update the node's probability
|
|
290
|
-
self.node_probas[action][
|
|
291
|
-
reward
|
|
292
|
-
)
|
|
307
|
+
self.node_probas[action][child_idx].tell_observation(reward)
|
|
293
308
|
# For stack strategy, update action-specific CONT distribution
|
|
294
309
|
self.gen_vs_cont_probas[action]["CONT"].tell_observation(reward)
|
|
295
310
|
|
|
@@ -444,14 +459,11 @@ class NodeProbState:
|
|
|
444
459
|
|
|
445
460
|
# Initialize the node's probability distribution with its score
|
|
446
461
|
assert node.parent is not None
|
|
462
|
+
child_idx = _child_index_by_identity(node.parent, node)
|
|
447
463
|
if model_selection_strategy == "stack":
|
|
448
|
-
self.node_probas[action][
|
|
449
|
-
node.score
|
|
450
|
-
)
|
|
464
|
+
self.node_probas[action][child_idx].tell_observation(node.score)
|
|
451
465
|
else:
|
|
452
|
-
self.node_probas["shared"][
|
|
453
|
-
node.parent.children.index(node)
|
|
454
|
-
].tell_observation(node.score)
|
|
466
|
+
self.node_probas["shared"][child_idx].tell_observation(node.score)
|
|
455
467
|
|
|
456
468
|
def get_action_for_child(self, child: Node) -> str:
|
|
457
469
|
"""
|
|
@@ -47,6 +47,37 @@ class ABMCTSMState(Generic[StateT]):
|
|
|
47
47
|
trial_store: TrialStore[StateT] = field(default_factory=TrialStore[StateT])
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class ABMCTSMAdvancedConfig:
|
|
52
|
+
"""
|
|
53
|
+
Advanced/experimental ABMCTSM configuration.
|
|
54
|
+
|
|
55
|
+
Most users should rely on the defaults.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
# If True, validate that rewards/scores are in [0, 1].
|
|
59
|
+
validate_reward_range: bool = True
|
|
60
|
+
|
|
61
|
+
# Prior sigmas for the underlying Bayesian model.
|
|
62
|
+
prior_mu_alpha_sigma: float = 0.2
|
|
63
|
+
prior_sigma_alpha_sigma: float = 0.2
|
|
64
|
+
prior_sigma_y_sigma: float = 0.3
|
|
65
|
+
|
|
66
|
+
def __post_init__(self) -> None:
|
|
67
|
+
if self.prior_mu_alpha_sigma <= 0:
|
|
68
|
+
raise ValueError(
|
|
69
|
+
f"prior_mu_alpha_sigma must be > 0, got {self.prior_mu_alpha_sigma}"
|
|
70
|
+
)
|
|
71
|
+
if self.prior_sigma_alpha_sigma <= 0:
|
|
72
|
+
raise ValueError(
|
|
73
|
+
f"prior_sigma_alpha_sigma must be > 0, got {self.prior_sigma_alpha_sigma}"
|
|
74
|
+
)
|
|
75
|
+
if self.prior_sigma_y_sigma <= 0:
|
|
76
|
+
raise ValueError(
|
|
77
|
+
f"prior_sigma_y_sigma must be > 0, got {self.prior_sigma_y_sigma}"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
50
81
|
class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
51
82
|
"""
|
|
52
83
|
Monte Carlo Tree Search algorithm using AB-MCTS-M algorithm.
|
|
@@ -63,6 +94,7 @@ class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
|
63
94
|
min_subtree_size_for_pruning: int = 4,
|
|
64
95
|
same_score_proportion_threshold: float = 0.75,
|
|
65
96
|
max_process_workers: int = os.cpu_count() or 1,
|
|
97
|
+
_advanced_config: ABMCTSMAdvancedConfig | None = None,
|
|
66
98
|
is_worker: bool = False,
|
|
67
99
|
):
|
|
68
100
|
"""
|
|
@@ -79,7 +111,13 @@ class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
|
79
111
|
min_subtree_size_for_pruning: Pruning Config, see PruningConfig class.
|
|
80
112
|
same_score_proportion_threshold: Pruning Config, see PruningConfig class.
|
|
81
113
|
max_process_workers: Maximum number of parallel processes used for running PyMC sampling.
|
|
114
|
+
_advanced_config: Advanced/experimental configuration. Defaults are recommended.
|
|
82
115
|
"""
|
|
116
|
+
self._advanced_config = (
|
|
117
|
+
_advanced_config
|
|
118
|
+
if _advanced_config is not None
|
|
119
|
+
else ABMCTSMAdvancedConfig()
|
|
120
|
+
)
|
|
83
121
|
self.enable_pruning = enable_pruning
|
|
84
122
|
self.pruning_config = PruningConfig(
|
|
85
123
|
min_subtree_size_for_pruning=min_subtree_size_for_pruning,
|
|
@@ -94,6 +132,9 @@ class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
|
94
132
|
enable_pruning=self.enable_pruning,
|
|
95
133
|
pruning_config=self.pruning_config,
|
|
96
134
|
reward_average_priors=self.reward_average_priors,
|
|
135
|
+
prior_mu_alpha_sigma=self._advanced_config.prior_mu_alpha_sigma,
|
|
136
|
+
prior_sigma_alpha_sigma=self._advanced_config.prior_sigma_alpha_sigma,
|
|
137
|
+
prior_sigma_y_sigma=self._advanced_config.prior_sigma_y_sigma,
|
|
97
138
|
model_selection_strategy=self.model_selection_strategy,
|
|
98
139
|
)
|
|
99
140
|
|
|
@@ -195,6 +236,9 @@ class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
|
195
236
|
def _get_generation_action(
|
|
196
237
|
self, state: ABMCTSMState[StateT], node: Node[StateT], actions: list[str]
|
|
197
238
|
) -> str:
|
|
239
|
+
if len(actions) == 1:
|
|
240
|
+
return actions[0]
|
|
241
|
+
|
|
198
242
|
observations = Observation.collect_all_observations_of_descendant(
|
|
199
243
|
node, state.all_observations
|
|
200
244
|
)
|
|
@@ -255,6 +299,7 @@ class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
|
255
299
|
min_subtree_size_for_pruning=self.pruning_config.min_subtree_size_for_pruning,
|
|
256
300
|
same_score_proportion_threshold=self.pruning_config.same_score_proportion_threshold,
|
|
257
301
|
max_process_workers=1,
|
|
302
|
+
_advanced_config=self._advanced_config,
|
|
258
303
|
is_worker=True,
|
|
259
304
|
)
|
|
260
305
|
|
|
@@ -298,7 +343,10 @@ class ABMCTSM(Algorithm[StateT, ABMCTSMState[StateT]]):
|
|
|
298
343
|
|
|
299
344
|
# Add new node to the tree
|
|
300
345
|
new_node = state.tree.add_node(
|
|
301
|
-
result,
|
|
346
|
+
result,
|
|
347
|
+
parent_node,
|
|
348
|
+
trial_id=finished_trial.trial_id,
|
|
349
|
+
validate_score_range=self._advanced_config.validate_reward_range,
|
|
302
350
|
)
|
|
303
351
|
|
|
304
352
|
# Record observation
|
|
@@ -148,6 +148,9 @@ class PyMCInterface:
|
|
|
148
148
|
enable_pruning: bool = True,
|
|
149
149
|
pruning_config: Optional[PruningConfig] = None,
|
|
150
150
|
reward_average_priors: Optional[float | Dict[str, float]] = None,
|
|
151
|
+
prior_mu_alpha_sigma: float = 0.2,
|
|
152
|
+
prior_sigma_alpha_sigma: float = 0.2,
|
|
153
|
+
prior_sigma_y_sigma: float = 0.3,
|
|
151
154
|
model_selection_strategy: str = "multiarm_bandit_thompson",
|
|
152
155
|
):
|
|
153
156
|
_import.check()
|
|
@@ -161,6 +164,22 @@ class PyMCInterface:
|
|
|
161
164
|
self.reward_average_priors = (
|
|
162
165
|
reward_average_priors if reward_average_priors is not None else dict()
|
|
163
166
|
)
|
|
167
|
+
if prior_mu_alpha_sigma <= 0:
|
|
168
|
+
raise ValueError(
|
|
169
|
+
f"prior_mu_alpha_sigma must be > 0, got {prior_mu_alpha_sigma}"
|
|
170
|
+
)
|
|
171
|
+
if prior_sigma_alpha_sigma <= 0:
|
|
172
|
+
raise ValueError(
|
|
173
|
+
f"prior_sigma_alpha_sigma must be > 0, got {prior_sigma_alpha_sigma}"
|
|
174
|
+
)
|
|
175
|
+
if prior_sigma_y_sigma <= 0:
|
|
176
|
+
raise ValueError(
|
|
177
|
+
f"prior_sigma_y_sigma must be > 0, got {prior_sigma_y_sigma}"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
self.prior_mu_alpha_sigma = prior_mu_alpha_sigma
|
|
181
|
+
self.prior_sigma_alpha_sigma = prior_sigma_alpha_sigma
|
|
182
|
+
self.prior_sigma_y_sigma = prior_sigma_y_sigma
|
|
164
183
|
|
|
165
184
|
# Strategy for model selection:
|
|
166
185
|
# "stack": Perform separate fits for each model (traditional approach)
|
|
@@ -491,13 +510,19 @@ class PyMCInterface:
|
|
|
491
510
|
with pm.Model(coords=coords if not is_prior_model else None) as model:
|
|
492
511
|
# Priors START
|
|
493
512
|
# Overall Goodness of the model itself; mu is set to be 0.5 (50% prob of solving the problem)
|
|
494
|
-
mu_alpha = pm.Normal(
|
|
513
|
+
mu_alpha = pm.Normal(
|
|
514
|
+
"mu_alpha",
|
|
515
|
+
mu=self.get_reward_average_prior(action=None),
|
|
516
|
+
sigma=self.prior_mu_alpha_sigma,
|
|
517
|
+
)
|
|
495
518
|
|
|
496
519
|
# expresses the strength of score fluctuation across answers
|
|
497
|
-
sigma_alpha = pm.HalfNormal(
|
|
520
|
+
sigma_alpha = pm.HalfNormal(
|
|
521
|
+
"sigma_alpha", sigma=self.prior_sigma_alpha_sigma
|
|
522
|
+
)
|
|
498
523
|
|
|
499
524
|
# expresses the strength of score fluctuation inside answers
|
|
500
|
-
sigma_y = pm.HalfNormal("sigma_y", sigma=
|
|
525
|
+
sigma_y = pm.HalfNormal("sigma_y", sigma=self.prior_sigma_y_sigma)
|
|
501
526
|
# Priors END
|
|
502
527
|
|
|
503
528
|
group_dims = "action" if not is_prior_model else None
|
|
@@ -543,14 +568,18 @@ class PyMCInterface:
|
|
|
543
568
|
# Priors START
|
|
544
569
|
# Overall Goodness of the model itself; mu is set to be 0.5 (50% prob of solving the problem)
|
|
545
570
|
mu_alpha = pm.Normal(
|
|
546
|
-
"mu_alpha",
|
|
571
|
+
"mu_alpha",
|
|
572
|
+
mu=self.get_reward_average_prior(action),
|
|
573
|
+
sigma=self.prior_mu_alpha_sigma,
|
|
547
574
|
)
|
|
548
575
|
|
|
549
576
|
# expresses the strength of score fluctuation across answers
|
|
550
|
-
sigma_alpha = pm.HalfNormal(
|
|
577
|
+
sigma_alpha = pm.HalfNormal(
|
|
578
|
+
"sigma_alpha", sigma=self.prior_sigma_alpha_sigma
|
|
579
|
+
)
|
|
551
580
|
|
|
552
581
|
# expresses the strength of score fluctuation inside answers
|
|
553
|
-
sigma_y = pm.HalfNormal("sigma_y", sigma=
|
|
582
|
+
sigma_y = pm.HalfNormal("sigma_y", sigma=self.prior_sigma_y_sigma)
|
|
554
583
|
# Priors END
|
|
555
584
|
|
|
556
585
|
group_dims = "child_idx" if not is_prior_model else None
|
|
@@ -14,6 +14,9 @@ class Node(Generic[StateT]):
|
|
|
14
14
|
# Scores should be in the range from 0 to 1. For root, we set it to be -1.0 as a placeholder.
|
|
15
15
|
score: float = -1.0
|
|
16
16
|
|
|
17
|
+
# If True, validate that score is in [0, 1] for non-root nodes.
|
|
18
|
+
validate_score_range: bool = dataclasses.field(default=True, kw_only=True)
|
|
19
|
+
|
|
17
20
|
# Reflects the order of expansion. The root has expand_idx = -1, followed by 0,1,2,...
|
|
18
21
|
expand_idx: int = -1
|
|
19
22
|
|
|
@@ -23,7 +26,9 @@ class Node(Generic[StateT]):
|
|
|
23
26
|
|
|
24
27
|
def __post_init__(self) -> None:
|
|
25
28
|
if not self.is_root():
|
|
26
|
-
if
|
|
29
|
+
if self.validate_score_range and not (
|
|
30
|
+
self.score <= 1.0 and self.score >= 0.0
|
|
31
|
+
):
|
|
27
32
|
raise RuntimeError(
|
|
28
33
|
f"The score value should be between 0 and 1, while {self.score} is set."
|
|
29
34
|
)
|
|
@@ -117,11 +122,14 @@ class Tree(Generic[StateT]):
|
|
|
117
122
|
state_score: StateScoreType[StateT],
|
|
118
123
|
parent: Node[StateT],
|
|
119
124
|
trial_id: Optional[TrialId] = None,
|
|
125
|
+
*,
|
|
126
|
+
validate_score_range: bool = True,
|
|
120
127
|
) -> Node[StateT]:
|
|
121
128
|
state, score = state_score
|
|
122
129
|
node = Node(
|
|
123
130
|
state=state,
|
|
124
131
|
score=score,
|
|
132
|
+
validate_score_range=validate_score_range,
|
|
125
133
|
parent=parent,
|
|
126
134
|
expand_idx=self.size - 1,
|
|
127
135
|
trial_id=trial_id,
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from .algos.ab_mcts_m._ab_mcts_m_imports import _import as _ab_mcts_m_import
|
|
2
|
-
|
|
3
|
-
if not _ab_mcts_m_import.is_successful():
|
|
4
|
-
# Create a placeholder that raises an informative error when accessed
|
|
5
|
-
class _ABMCTSMPlaceholder:
|
|
6
|
-
def __getattr__(self, name): # type: ignore
|
|
7
|
-
_ab_mcts_m_import.check()
|
|
8
|
-
raise ImportError("ABMCTSM import failed.")
|
|
9
|
-
|
|
10
|
-
def __call__(self, *args, **kwargs): # type: ignore
|
|
11
|
-
_ab_mcts_m_import.check()
|
|
12
|
-
raise ImportError("ABMCTSM import failed.")
|
|
13
|
-
|
|
14
|
-
ABMCTSM = _ABMCTSMPlaceholder() # type: ignore
|
|
15
|
-
else:
|
|
16
|
-
from .algos.ab_mcts_m.algo import ABMCTSM # type: ignore[assignment]
|
|
17
|
-
|
|
18
|
-
from .algos.ab_mcts_a.algo import ABMCTSA
|
|
19
|
-
from .algos.base import Algorithm
|
|
20
|
-
from .algos.standard_mcts import StandardMCTS
|
|
21
|
-
from .algos.tree_of_thought_bfs import TreeOfThoughtsBFSAlgo
|
|
22
|
-
from .ranker import top_k
|
|
23
|
-
from .vis import render
|
|
24
|
-
|
|
25
|
-
__all__ = [
|
|
26
|
-
"StandardMCTS",
|
|
27
|
-
"top_k",
|
|
28
|
-
"TreeOfThoughtsBFSAlgo",
|
|
29
|
-
"ABMCTSA",
|
|
30
|
-
"ABMCTSM",
|
|
31
|
-
"Algorithm",
|
|
32
|
-
"render",
|
|
33
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{treequest-0.3.1 → treequest-0.3.2}/src/treequest/vis/algo_adapters/multi_armed_bandit_ucb.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|