-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcharacters_test.go
67 lines (61 loc) · 1.06 KB
/
characters_test.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
// Example borrowed from https://github.com/stevenmiller888/go-mind
package drago_test
import (
"log"
"github.com/aaparella/drago"
)
var (
a = character(
".#####." +
"#.....#" +
"#.....#" +
"#######" +
"#.....#" +
"#.....#" +
"#.....#")
b = character(
"######." +
"#.....#" +
"#.....#" +
"######." +
"#.....#" +
"#.....#" +
"######.")
c = character(
"#######" +
"#......" +
"#......" +
"#......" +
"#......" +
"#......" +
"#######")
)
func ExampleLearn() {
m := drago.New(0.3, 10000, []int{49, 3, 1}, []drago.Activator{new(drago.Sigmoid)})
m.Learn([][][]float64{
{c, []float64{.5}},
{b, []float64{.3}},
{a, []float64{.1}},
})
result := m.Predict(
character(
"#######" +
"#......" +
"#......" +
"#......" +
"#......" +
"#......" +
"#######"))
log.Println(result)
}
func character(chars string) []float64 {
flt := make([]float64, len(chars))
for i := 0; i < len(chars); i++ {
if chars[i] == '#' {
flt[i] = 1.0
} else { // if '.'
flt[i] = 0.0
}
}
return flt
}