byte-vortex/nonzero-repro-artifacts / nonuct_cnode_patch.diff
byte-vortex's picture
download
raw
3.2 kB
diff --git a/core/mcts/ctree/ctree_sampled/lib/cnode.cpp b/core/mcts/ctree/ctree_sampled/lib/cnode.cpp
index 16e8a14..a322972 100644
--- a/core/mcts/ctree/ctree_sampled/lib/cnode.cpp
+++ b/core/mcts/ctree/ctree_sampled/lib/cnode.cpp
@@ -330,7 +330,16 @@ namespace tree
if (value_score > 1)
value_score = 1;
- float ucb_value = prior_score + value_score;
+ // NonUCT: additive surrogate term. this->nonuct_weight defaults to
+ // 0.0 (set via CTree constructor / a new setter), so with no
+ // wiring from Python this reduces exactly to the original MAZero
+ // pUCT score -- existing configs/results are unaffected unless the
+ // weight is explicitly turned on. child->nonuct_score is raw
+ // eta(theta,a) (unbounded), so it is squashed to comparable scale
+ // via the same asinh-family shape rather than mixed in raw.
+ float nonuct_term = this->nonuct_weight * tanhf(child->get_nonuct_score());
+
+ float ucb_value = prior_score + value_score + nonuct_term;
return ucb_value;
}
diff --git a/core/mcts/ctree/ctree_sampled/lib/cnode.h b/core/mcts/ctree/ctree_sampled/lib/cnode.h
index 7b307d7..be713c8 100644
--- a/core/mcts/ctree/ctree_sampled/lib/cnode.h
+++ b/core/mcts/ctree/ctree_sampled/lib/cnode.h
@@ -12,6 +12,10 @@ namespace tree
{
int visit_count, num_children, hidden_state_index_x;
float reward, pred_value, prior, pred_prob, beta, beta_hat;
+ // NonUCT: eta(theta, a) computed in Python (AsinhGLMSurrogate) and
+ // pushed into this node before selection runs. Defaults to 0 so
+ // nodes never touched by the surrogate behave like standard pUCT.
+ float nonuct_score = 0.0f;
bool is_root;
tools::SubTreeValueSet subtree_info;
std::vector<CNode *> children; // shape = (num_children, )
@@ -27,6 +31,12 @@ namespace tree
float get_qsa(float discount);
float get_mean_q(float parent_q, float discount);
+ // NonUCT: set/get the precomputed asinh-GLM surrogate score for
+ // this node. Called from Python after computing eta(theta, a)
+ // for the candidate action this node represents.
+ void set_nonuct_score(float score) { this->nonuct_score = score; }
+ float get_nonuct_score() { return this->nonuct_score; }
+
// shape = (agent_num, action_space_size)
void get_marginal_visit_count(tools::Array2D<int>); // marginal visit_count of sampled actions
void get_marginal_priors(tools::Array2D<float>); // marginal node prior of sampled actions
@@ -63,6 +73,10 @@ namespace tree
public:
int agent_num, action_space_size, sampled_times, tot_nodes;
float rho, lam;
+ // NonUCT: weight on the surrogate term in ucb_score. 0.0 = exact
+ // original MAZero behavior (opt-in only via set_nonuct_weight).
+ float nonuct_weight = 0.0f;
+ void set_nonuct_weight(float w) { this->nonuct_weight = w; }
CNode *node_pool_ptr;
CNode *root;
tools::CMinMaxStats minmax_stat; // maintaining qsa for all nodes in the tree except the root.

Xet Storage Details

Size:
3.2 kB
·
Xet hash:
949502a4b997b97e87e9e436820e4173ef3891402a54fa6e859228a7ffc52455

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.