From c994a2d63ac6605c197133a0d788b0a3c245402e Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Tue, 17 Jan 2012 18:13:13 +0100 Subject: [PATCH] UCT avg_score: Track avg score of last move search explicitly in the tree --- uct/tree.c | 4 +--- uct/tree.h | 3 +++ uct/uct.c | 3 ++- uct/walk.c | 4 ++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/uct/tree.c b/uct/tree.c index 8d0687b..d15a407 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -777,9 +777,7 @@ tree_promote_node(struct tree *tree, struct tree_node **node) tree->root_color = stone_other(tree->root_color); board_symmetry_update(tree->board, &tree->root_symmetry, node_coord(*node)); - /* See tree.score description for explanation on why don't we zero - * score on node promotion. */ - // tree->score.playouts = 0; + tree->avg_score.playouts = 0; /* If the tree deepest node was under node, or if we called tree_garbage_collect, * tree->max_depth is correct. Otherwise we could traverse the tree diff --git a/uct/tree.h b/uct/tree.h index ea6c262..c16080a 100644 --- a/uct/tree.h +++ b/uct/tree.h @@ -109,6 +109,9 @@ struct tree { * is only informative, the actual value is computed per simulation * based on leaf node depth. */ floating_t extra_komi; + /* Score in simulations, averaged over all branches, in the last + * search episode. */ + struct move_stats avg_score; /* We merge local (non-tenuki) sequences for both colors, occuring * anywhere in the tree; nodes are created on-demand, special 'pass' diff --git a/uct/uct.c b/uct/uct.c index d41d384..385ee5d 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -326,7 +326,8 @@ uct_search(struct uct *u, struct board *b, struct time_info *ti, enum stone colo struct uct_thread_ctx *ctx = uct_search_stop(); if (UDEBUGL(2)) tree_dump(t, u->dumpthres); if (UDEBUGL(2)) - fprintf(stderr, "(avg score %f/%d value %f/%d)\n", + fprintf(stderr, "(avg score %f/%d; dynkomi's %f/%d value %f/%d)\n", + t->avg_score.value, t->avg_score.playouts, u->dynkomi->score.value, u->dynkomi->score.playouts, u->dynkomi->value.value, u->dynkomi->value.playouts); uct_progress_status(u, t, color, ctx->games, true); diff --git a/uct/walk.c b/uct/walk.c index 8f87957..b48cd5b 100644 --- a/uct/walk.c +++ b/uct/walk.c @@ -135,6 +135,9 @@ uct_progress_json(struct uct *u, struct tree *t, enum stone color, int playouts, fprintf(stderr, "]"); if (big) { + /* Average score. */ + if (t->avg_score.playouts > 0) + fprintf(stderr, ", \"avg\": {\"score\": %.3f}", t->avg_score.value); /* Ownership statistics. Value (0..1000) for each possible * point describes likelihood of this point becoming black. * Normally, white rate is 1000-value; exception are possible @@ -537,6 +540,7 @@ uct_playout(struct uct *u, struct board *b, enum stone player_color, struct tree floating_t rval = scale_value(u, b, result); u->policy->update(u->policy, t, n, node_color, player_color, &amaf, &b2, rval); + stats_add_result(&t->avg_score, result / 2, 1); if (t->use_extra_komi) { stats_add_result(&u->dynkomi->score, result / 2, 1); stats_add_result(&u->dynkomi->value, rval, 1); -- 2.11.4.GIT