-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_nodes.go
97 lines (81 loc) · 2.16 KB
/
models_nodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gotoml
import (
"fmt"
)
// Noder interface
type Noder interface {
GetRawVal() string
PutRawVal(s string)
GetReward() float64
PutReward(f float64)
GetVisited() int
PutVisited(v int)
GetActionsQv() interface{}
GetActionQv(aid int) float64
PutActionQv(aid int, v float64)
TakeAction(epsilG float64) (aid int)
GetStateQv() float64
PutStateQv(v float64)
Print()
}
// Node type of a Grid world
type Node struct {
RawVal string //raw value in 'real' world
Reward float64 //Reward of Noder should be >-100 & <100
StateQv float64 //Noder Q value
Visited int //number of updates
ActionsQv Actioner //actions Q value in x directions
}
// GetRawVal to get raw value from node
func (n *Node) GetRawVal() string {
return n.RawVal
}
// PutRawVal to put raw value on node
func (n *Node) PutRawVal(s string) {
n.RawVal = s
}
// GetReward to get Reward value from node
func (n *Node) GetReward() float64 {
return n.Reward
}
// PutReward to put Reward value on node
func (n *Node) PutReward(f float64) {
n.Reward = f
}
// GetVisited to get number of visits from node
func (n *Node) GetVisited() int {
return int(n.Visited)
}
// PutVisited to put number of visits on node
func (n *Node) PutVisited(v int) {
n.Visited = v
}
// GetActionsQv to get Actions Quality Value list from node
func (n *Node) GetActionsQv() interface{} {
return n.ActionsQv.GetActionsQv()
}
// GetActionQv to get specific Quality Value from action node
func (n *Node) GetActionQv(aid int) float64 {
return n.ActionsQv.GetActionQv(aid)
}
// PutActionQv to put specific Quality Value on action node
func (n *Node) PutActionQv(aid int, v float64) {
n.ActionsQv.PutActionQv(aid, v)
}
// GetStateQv to get State Quality Value from node
func (n *Node) GetStateQv() float64 {
return n.StateQv
}
// PutStateQv to put State Quality Value on node
func (n *Node) PutStateQv(v float64) {
n.StateQv = v
}
// Print for Printer interface
func (n *Node) Print() {
fmt.Printf("%v", n)
}
// TakeAction from a node based on epsilon
// epsilon between 0-1 1 for exploration max and 0 for exploitation max greedy)
func (n *Node) TakeAction(epsilG float64) (aid int) {
return n.ActionsQv.TakeAction(epsilG)
}