/
main.go
48 lines (38 loc) · 1.01 KB
/
main.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
package main
import (
"fmt"
"os"
"strconv"
"github.com/sjwhitworth/golearn/base"
"github.com/sjwhitworth/golearn/neural"
)
func main() {
xOne, err := strconv.ParseInt(os.Args[1], 10, 64)
xTwo, err := strconv.ParseInt(os.Args[2], 10, 64)
fmt.Println("")
if err != nil {
panic(err)
}
XNORData, _ := base.ParseCSVToInstances("xnor.csv", false)
net := neural.NewMultiLayerNet([]int{3})
net.MaxIterations = 20000
net.Fit(XNORData)
pred := net.Predict(XNORData)
var inputVectorIndex int
if xOne == 0 && xTwo == 0 {
inputVectorIndex = 0
fmt.Println(base.GetClass(pred, inputVectorIndex))
} else if xOne == 0 && xTwo == 1 {
inputVectorIndex = 1
fmt.Println(base.GetClass(pred, inputVectorIndex))
} else if xOne == 1 && xTwo == 0 {
inputVectorIndex = 2
fmt.Println(base.GetClass(pred, inputVectorIndex))
} else if xOne == 1 && xTwo == 1 {
inputVectorIndex = 3
fmt.Println(base.GetClass(pred, inputVectorIndex))
} else {
fmt.Println("Your input is incorrect. Quitting. ")
}
fmt.Println("")
}