Skip to content
DeepForgeby svx
All problems

Dirichlet Noise On Priors

Problem

Mix Dirichlet noise into a prior distribution, as AlphaZero does at the MCTS root.

Create rng = random.Random(seed), draw n Gamma(alpha, 1) samples with rng.gammavariate, normalize them into a Dirichlet sample, and return (1 - epsilon) * priors + epsilon * noise. The seed makes the result reproducible.

Hint

Normalized Gamma samples are exactly a Dirichlet sample.

Test cases

case 1
in: [[0.5,0.3,0.2],0.5,0.25,42]
expected: [0.4450821975969227,0.23796534356096616,0.3169524588421112]
case 2
in: [[0.25,0.25,0.25,0.25],1,0.1,0]
expected: [0.2701100917755,0.2593944140089405,0.23823071911962349,0.23226477509593607]
case 3
in: [[0.6,0.4],2,0.5,7]
expected: [0.45664010302237007,0.5433598969776299]
Starter codePython
import random
def dirichlet_noise_priors(priors, alpha, epsilon, seed):
    # Your code here
    pass

3 test cases · run your code against them in the editor