This commit is contained in:
a 2023-07-06 10:48:20 +01:00
parent 2f1636a33c
commit 5f5c236213
3 changed files with 10 additions and 3 deletions

View File

@ -2,9 +2,12 @@ package algo
import ( import (
"lukechampine.com/frand" "lukechampine.com/frand"
"tuxpa.in/a/gambit"
"tuxpa.in/a/gambit/helper" "tuxpa.in/a/gambit/helper"
) )
var _ gambit.Bandit = (*EpsilonGreedy)(nil)
type EpsilonGreedy struct { type EpsilonGreedy struct {
Epsilon float64 Epsilon float64
cr helper.CountReward cr helper.CountReward

View File

@ -17,13 +17,12 @@ func main() {
n := 100 n := 100
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
b.Update( g.Observe(
// select a random arm // select a random arm
b.Select(frand.Float64()), frand.Float64(),
// and supply a random score // and supply a random score
float64(frand.Intn(4)), float64(frand.Intn(4)),
) )
} }
log.Println(g.AllocateSolution()) log.Println(g.AllocateSolution())
} }

View File

@ -15,3 +15,8 @@ func (g *Gang) AllocateSolution() ([]int, []float64) {
g.b.Reward(b) g.b.Reward(b)
return a, b return a, b
} }
func (g *Gang) Observe(score float64, reward float64) {
g.b.Update(g.b.Select(score), reward)
}