-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
63 lines (52 loc) · 984 Bytes
/
util.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
package neat
import (
"fmt"
"math/rand"
)
// Check loops
func checkLoops(neuron, from TNeuron) bool {
if neuron == from {
return true
}
for i := 0; i < from.ConnectionsLength(); i++ {
if checkLoops(neuron, from.GetConnection(i)) {
return true
}
}
return false
}
// Random
//func random() float64 {
// return rand.Float64()
//}
func randWeight() float64 {
return rand.Float64()*2 - 1
}
func randScaleWeight(scale float64) float64 {
return randWeight() * scale
}
func probability(pro float64) bool {
return rand.Float64() < pro
}
func randIndex(from, to int) int {
return rand.Intn(to-from) + from
}
func randInt(max int) int {
return rand.Intn(max)
}
// Neurons name
func inputName(i int) string {
return "I-" + fmt.Sprint(i)
}
func outputName(i int) string {
return "O-" + fmt.Sprint(i)
}
// Array
func getIndex(neuron TNeuron, neurons []TNeuron) int {
for i := 0; i < len(neurons); i++ {
if neuron == neurons[i] {
return i
}
}
return -1
}