我在Q-learning中使用Boltzman探索策略,每个状态至少有10个动作。我知道在只有两个动作的情况下,Boltzman探索策略可以非常简单地应用,如下所示:
- 使用Boltzman探索方程计算两个动作的pr1和pr2。
- 生成一个随机数r
- 假设pr1>pr2。如果r<=pr1,则选择对应于概率pr1的动作。如果r>pr1,则选择对应于pr2的动作。
然而,如何在有10个动作的情况下进行操作呢?在每个决策步骤,我都会更新所有动作的概率。这给我提供了一个所有动作的概率分布,其中最佳动作的概率最高。在这种情况下,如何使用Boltzman探索策略选择动作呢?
回答:
这里有一个关于加权随机抽样的优秀讨论:Darts, Dice, and Coins。
这是我对Vose的Alias方法的实现:
class WeightedRandom{ private alias : array[int]; private prob : array[double]; private random : Random; public this(p : array[double], random : Random) { this.random = random; def n = p.Length; alias = array(n); prob = array(n); def small = Queue(n); def large = Queue(n); def p = p.Map(_ * n : double); foreach (x in p with i) (if (x < 1.0) small else large).Enqueue(i); while (!small.IsEmpty && !large.IsEmpty) { def s = small.Dequeue(); def l = large.Dequeue(); prob[s] = p[s]; alias[s] = l; p[l] = p[l] + p[s] - 1; (if (p[l] < 1.0) small else large).Enqueue(l); } while (!large.IsEmpty) prob[large.Dequeue()] = 1.0; while (!small.IsEmpty) prob[small.Dequeue()] = 1.0; } public NextIndex() : int { def i = random.Next(prob.Length); if (random.NextDouble() < prob[i]) i; else alias[i]; }}