123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package main
- import (
- "fmt"
- "log"
- "os"
- "time"
- neuralnetwork "./neuralnetworkbase"
- remotecontrol "./remotecontrol"
- teach "./teach"
- )
- func main() {
- sizes := []int{13, 14, 14, 3}
- nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewRPropInitializer(neuralnetwork.RPropConfig{
- NuPlus: 1.2,
- NuMinus: 0.5,
- DeltaMax: 50.0,
- DeltaMin: 0.000001,
- }))
- rc := &remotecontrol.RemoteControl{}
- nn.SetStateWatcher(rc)
- // inFile, err := os.Open("./networkstate")
- // if err != nil {
- // log.Fatal(err)
- // }
- // defer inFile.Close()
- // nn.LoadState(inFile)
- // nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewBackPropInitializer(0.1))
- // for i := 0; i < nn.Count; i++ {
- // if i > 0 {
- // fmt.Printf("Weights before:\n%v\n\n", mat.Formatted(nn.Weights[i], mat.Prefix(""), mat.Excerpt(0)))
- // fmt.Printf("Biases before:\n%v\n\n", mat.Formatted(nn.Biases[i], mat.Prefix(""), mat.Excerpt(0)))
- // fmt.Printf("Z before:\n%v\n\n", mat.Formatted(nn.Z[i], mat.Prefix(""), mat.Excerpt(0)))
- // }
- // fmt.Printf("A before:\n%v\n\n", mat.Formatted(nn.A[i], mat.Prefix(""), mat.Excerpt(0)))
- // }
- go func() {
- // teacher := teach.NewMNISTReader("./minst.data", "./mnist.labels")
- teacher := teach.NewTextDataReader("wine.data", 7)
- nn.Teach(teacher, 1000)
- // for i := 0; i < nn.Count; i++ {
- // if i > 0 {
- // fmt.Printf("Weights after:\n%v\n\n", mat.Formatted(nn.Weights[i], mat.Prefix(""), mat.Excerpt(0)))
- // fmt.Printf("Biases after:\n%v\n\n", mat.Formatted(nn.Biases[i], mat.Prefix(""), mat.Excerpt(0)))
- // fmt.Printf("Z after:\n%v\n\n", mat.Formatted(nn.Z[i], mat.Prefix(""), mat.Excerpt(0)))
- // }
- // fmt.Printf("A after:\n%v\n\n", mat.Formatted(nn.A[i], mat.Prefix(""), mat.Excerpt(0)))
- // }
- outFile, err := os.OpenFile("./data", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
- if err != nil {
- log.Fatal(err)
- }
- defer outFile.Close()
- nn.SaveState(outFile)
- outFile.Close()
- failCount := 0
- teacher.Reset()
- for teacher.NextValidator() {
- dataSet, expect := teacher.GetValidator()
- index, _ := nn.Predict(dataSet)
- time.Sleep(400 * time.Millisecond)
- if expect.At(index, 0) != 1.0 {
- failCount++
- // fmt.Printf("Fail: %v, %v\n\n", teacher.ValidationIndex(), expect.At(index, 0))
- }
- }
- fmt.Printf("Fail count: %v\n\n", failCount)
- }()
- // nn = &neuralnetwork.NeuralNetwork{}
- // inFile, err := os.Open("./data")
- // if err != nil {
- // log.Fatal(err)
- // }
- // defer inFile.Close()
- // nn.LoadState(inFile)
- // inFile.Close()
- // failCount = 0
- // teacher.Reset()
- // for teacher.NextValidator() {
- // dataSet, expect := teacher.GetValidator()
- // index, _ := nn.Predict(dataSet)
- // if expect.At(index, 0) != 1.0 {
- // failCount++
- // // fmt.Printf("Fail: %v, %v\n\n", teacher.ValidationIndex(), expect.At(index, 0))
- // }
- // }
- // fmt.Printf("Fail count: %v\n\n", failCount)
- rc.Run()
- }
|