Documentation ¶
Index ¶
- type Bandit
- type GridState
- type GridWorld
- func (w *GridWorld) Actions() []int
- func (w *GridWorld) Height() int
- func (w *GridWorld) NextState(s *GridState, a int) *GridState
- func (w *GridWorld) OneHot(state *GridState) []float64
- func (w *GridWorld) Reset() *GridState
- func (w *GridWorld) Reward(s *GridState, a int, n *GridState) float64
- func (w *GridWorld) Size() int
- func (w *GridWorld) Step(a int) (*GridState, float64, bool)
- func (w *GridWorld) Width() int
- type NonStatBandit
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bandit ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/agent/env" "github.com/itsubaki/neu/math/rand" ) func main() { bandit := env.NewBandit(10, rand.Const(1)) for i := 0; i < 10; i++ { fmt.Print(bandit.Play(i)) } }
Output: 1101110011
type GridState ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/agent/env" ) func main() { s0 := &env.GridState{Height: 0, Width: 0} s1 := &env.GridState{Height: 0, Width: 1} s2 := &env.GridState{Height: 1, Width: 0} s3 := &env.GridState{Height: 1, Width: 1} fmt.Println(s0.Equals(s0)) fmt.Println(s0.Equals(s1)) fmt.Println(s0.Equals(s2)) fmt.Println(s0.Equals(s3)) }
Output: true false false false
type GridWorld ¶
type GridWorld struct { ActionSpace []int ActionMeaning map[int]string RewardMap [][]float64 GoalState *GridState WallState *GridState StartState *GridState AgentState *GridState State []GridState }
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/agent/env" ) func main() { e := env.NewGridWorld() fmt.Println(e.Height(), e.Width()) fmt.Println(e.Size()) for _, a := range e.Actions() { fmt.Println(a, e.ActionMeaning[a]) } for _, s := range e.State { fmt.Println(s, e.Reward(nil, 0, &s)) } }
Output: 3 4 12 0 UP 1 DOWN 2 LEFT 3 RIGHT (0, 0) 0 (0, 1) 0 (0, 2) 0 (0, 3) 1 (1, 0) 0 (1, 1) 0 (1, 2) 0 (1, 3) -1 (2, 0) 0 (2, 1) 0 (2, 2) 0 (2, 3) 0
func NewGridWorld ¶
func NewGridWorld() *GridWorld
func (*GridWorld) NextState ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/agent/env" ) func main() { e := env.NewGridWorld() fmt.Println(e.NextState(&env.GridState{Height: 0, Width: 0}, 0)) fmt.Println(e.NextState(&env.GridState{Height: 0, Width: 0}, 1)) fmt.Println(e.NextState(&env.GridState{Height: 0, Width: 0}, 2)) fmt.Println(e.NextState(&env.GridState{Height: 0, Width: 0}, 3)) fmt.Println() fmt.Println(e.NextState(&env.GridState{Height: 1, Width: 0}, 0)) fmt.Println(e.NextState(&env.GridState{Height: 1, Width: 0}, 1)) fmt.Println(e.NextState(&env.GridState{Height: 1, Width: 0}, 2)) fmt.Println(e.NextState(&env.GridState{Height: 1, Width: 0}, 3)) fmt.Println() fmt.Println(e.NextState(&env.GridState{Height: 2, Width: 3}, 0)) fmt.Println(e.NextState(&env.GridState{Height: 2, Width: 3}, 1)) fmt.Println(e.NextState(&env.GridState{Height: 2, Width: 3}, 2)) fmt.Println(e.NextState(&env.GridState{Height: 2, Width: 3}, 3)) }
Output: (0, 0) (1, 0) (0, 0) (0, 1) (0, 0) (2, 0) (1, 0) (1, 0) (1, 3) (2, 3) (2, 2) (2, 3)
func (*GridWorld) OneHot ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/agent/env" ) func main() { e := env.NewGridWorld() fmt.Println(e.OneHot(&env.GridState{Height: 0, Width: 0})) fmt.Println(e.OneHot(&env.GridState{Height: 1, Width: 1})) fmt.Println(e.OneHot(&env.GridState{Height: 2, Width: 0})) fmt.Println(e.OneHot(&env.GridState{Height: 2, Width: 3})) }
Output: [1 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 1]
type NonStatBandit ¶
Example ¶
package main import ( "fmt" "github.com/itsubaki/neu/agent/env" "github.com/itsubaki/neu/math/rand" ) func main() { bandit := env.NewNonStatBandit(10, rand.Const(1)) for i := 0; i < 10; i++ { fmt.Print(bandit.Play(i)) } }
Output: 1101110010
func NewNonStatBandit ¶
func NewNonStatBandit(arms int, s randv2.Source) *NonStatBandit
func (*NonStatBandit) Play ¶
func (b *NonStatBandit) Play(arm int) float64
Click to show internal directories.
Click to hide internal directories.