From 3b2f42dbf37413391af5f448f6cef7d43642d232 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 2 Jan 2010 02:18:52 +0100 Subject: [PATCH] probdist_add(), probdist_mul(): Phase out in favor of probdist_set() --- playout/elo.c | 8 +++++--- probdist.h | 22 +++++++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/playout/elo.c b/playout/elo.c index 59908ff..f8bdc31 100644 --- a/playout/elo.c +++ b/playout/elo.c @@ -84,14 +84,14 @@ elo_get_probdist(struct playout_policy *p, struct patternset *ps, struct board * moves++; /* Each valid move starts with gamma 1. */ - probdist_add(pd, f, 1.f); + float g = 1.f; /* Some easy features: */ /* XXX: We just disable them for now since we call the * pattern matcher; you need the gammas file. */ #if 0 if (is_bad_selfatari(b, to_play, m.coord)) - probdist_mul(pd, f, pp->selfatari); + g *= pp->selfatari; #endif /* Match pattern features: */ @@ -102,8 +102,10 @@ elo_get_probdist(struct playout_policy *p, struct patternset *ps, struct board * float gamma = feature_gamma(ps->fg, &p.f[i], NULL); //char buf[256] = ""; feature2str(buf, &p.f[i]); //fprintf(stderr, "<%d> %s feat %s gamma %f\n", f, coord2sstr(m.coord, b), buf, gamma); - probdist_mul(pd, f, gamma); + g *= gamma; } + + probdist_set(pd, f, g); //fprintf(stderr, "<%d> %s %f\n", f, coord2sstr(m.coord, b), pd->items[m.coord]); } diff --git a/probdist.h b/probdist.h index d28459c..91b6af7 100644 --- a/probdist.h +++ b/probdist.h @@ -3,6 +3,10 @@ /* Tools for picking an item according to a probability distribution. */ +/* The probability distribution structure is designed to be once + * initialized, then each item sequentially assigned a value one, + * then multiple times an item picked randomly. */ + #include "move.h" struct probdist { @@ -12,8 +16,7 @@ struct probdist { }; struct probdist *probdist_init(struct probdist *pd, int n); -static void probdist_add(struct probdist *pd, int i, float val); -static void probdist_mul(struct probdist *pd, int i, float val); +static void probdist_set(struct probdist *pd, int i, float val); int probdist_pick(struct probdist *pd); void probdist_done(struct probdist *pd); // Doesn't free pd itself @@ -23,25 +26,14 @@ void probdist_done(struct probdist *pd); // Doesn't free pd itself * functions otherwise. */ static inline void -probdist_add(struct probdist *pd, int i, float val) +probdist_set(struct probdist *pd, int i, float val) { #if 0 assert(i >= 0 && i < pd->n); assert(val >= 0); #endif - pd->items[i] += val; + pd->items[i] = val; pd->total += val; } -static inline void -probdist_mul(struct probdist *pd, int i, float val) -{ -#if 0 - assert(i >= 0 && i < pd->n); - assert(val >= 0); -#endif - pd->total += (val - 1) * pd->items[i]; - pd->items[i] *= val; -} - #endif -- 2.11.4.GIT