-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 1.04 KB
/
Copy pathmain.go
File metadata and controls
42 lines (34 loc) · 1.04 KB
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
package main
import "fmt"
import "math"
import "os"
import "strconv"
func main() {
var iterations int
var e error
iterations, e = strconv.Atoi(os.Args[len(os.Args) -1])
if e != nil {
fmt.Println("Parse error")
}
inputs := []float64{1.1, 0.8}
target := 0.6
tests := 1
sum := 0.0
for i := 0; i < tests; i++ {
res := backPropSimulation(SetupNeuralNetwork(), iterations, inputs, target)
sum += math.Abs(res - target) / target
fmt.Println("Result:",res)
}
avgErr := sum / float64(tests) // In the future, std deviation may be more useful
fmt.Println(iterations, "iterations completed with", (avgErr * 100), "% error")
}
func backPropSimulation(nn NeuronNetwork, iterations int, inputs []float64, target float64) float64 {
prop := BackPropogator{nn, target, 1}
for i := 0; i < iterations; i++ {
prop.nn.inputs = inputs
prop.nn.Update() // Execute network
output := prop.nn.outputs[0]
prop.Propogate(output) // Run backpropagation algorithm given our output
}
return prop.nn.outputs[0]
}