Esempio n. 1
0
func (e *engine) learn(req *request) {
	r := *req

	in := r[0].(*[]float64)
	ideal := r[1].(*[]float64)
	speed := r[2].(float64)
	learn.Learn(e.Network, *in, *ideal, speed)
}
Esempio n. 2
0
func MulriplyMain() {

	network := neural.NewNetwork(2, []int{5, 5, 1})
	network.RandomizeSynapses()

	ch := make(chan float64, 300)

	go func() {
		tick := time.Tick(5 * time.Second)
		acount := 1000
		arr := make([]float64, acount)
		index := 0

		for {
			select {
			case v := <-ch:
				arr[index] = v
				index++
				if index == len(arr) {
					index = 0
				}
			case <-tick:
				var sum float64 = 0
				for _, val := range arr {
					sum += val
				}

				//log.Println(index)
				//log.Println(arr)
				log.Printf("Avarege error: %f", sum/float64(acount))

			}
		}

	}()

	count := 100000000000
	for i := 0; i < count; i++ {
		test := []float64{rand.Float64(), rand.Float64()}
		result := network.Calculate(test)[0]

		ch <- math.Abs(test[0]*test[1] - result)

		log.Printf("Error value: %f * %f = %f", test[0], test[1], test[0]*test[1])

		learn.Learn(network, test, []float64{test[0] * test[1]}, 0.1)
	}

}
Esempio n. 3
0
func learnNetwork(n *neural.Network) {
	samples := make([]*Sample, 0, 10)

	samples = append(samples, loadSample("plus"))
	samples = append(samples, loadSample("minus"))
	samples = append(samples, loadSample("multiple"))
	samples = append(samples, loadSample("divide"))

	for i := 0; i < 10000; i++ {

		for _, s := range samples {
			learn.Learn(n, s.In, s.Out, speed)
		}

	}

}
Esempio n. 4
0
func learnLangFile(n *neural.Network, path string, out []float64) {
	//log.Println("Learning ", path)
	sample := getSampleFromFile(path)
	learn.Learn(n, sample, out, learningSpeed)
}