env

package
v0.0.0-...-25ab4ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bandit

type Bandit struct {
	Rates  []float64
	Source randv2.Source
}
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

func NewBandit

func NewBandit(arms int, s randv2.Source) *Bandit

func (*Bandit) Play

func (b *Bandit) Play(arm int) float64

type GridState

type GridState struct {
	Height int
	Width  int
}
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

func (*GridState) Equals

func (s *GridState) Equals(o *GridState) bool

func (GridState) String

func (s GridState) String() string

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) Actions

func (w *GridWorld) Actions() []int

func (*GridWorld) Height

func (w *GridWorld) Height() int

func (*GridWorld) NextState

func (w *GridWorld) NextState(s *GridState, a int) *GridState
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

func (w *GridWorld) OneHot(state *GridState) []float64
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]

func (*GridWorld) Reset

func (w *GridWorld) Reset() *GridState
Example
package main

import (
	"fmt"

	"github.com/itsubaki/neu/agent/env"
)

func main() {
	e := env.NewGridWorld()

	fmt.Println(e.AgentState)
	fmt.Println(e.Step(0))
	fmt.Println(e.AgentState)

	fmt.Println(e.Reset())

}
Output:

(2, 0)
(1, 0) 0 false
(1, 0)
(2, 0)

func (*GridWorld) Reward

func (w *GridWorld) Reward(s *GridState, a int, n *GridState) float64

func (*GridWorld) Size

func (w *GridWorld) Size() int

func (*GridWorld) Step

func (w *GridWorld) Step(a int) (*GridState, float64, bool)

func (*GridWorld) Width

func (w *GridWorld) Width() int

type NonStatBandit

type NonStatBandit struct {
	Arms   int
	Rates  []float64
	Source randv2.Source
}
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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL