This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.go
90 lines (84 loc) · 1.87 KB
/
layer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package bareml
type Layer struct {
size int
activationType ActivationType
neurons []*Neuron
}
func NewLayer(size int, aType ActivationType) *Layer {
l := new(Layer)
l.activationType = aType
l.size = size
l.neurons = make([]*Neuron, size)
for i := 0; i < size; i++ {
l.neurons[i] = NewNeuron(0.0000000000000, aType)
}
return l
}
func (l *Layer) Copy() *Layer {
nl := new(Layer)
nl.size = l.Size()
nl.activationType = l.ActivationType()
nl.neurons = make([]*Neuron, nl.size)
for i := 0; i < nl.size; i++ {
nl.neurons[i] = l.GetNeurons()[i].Copy()
}
return nl
}
func (l *Layer) MatrixifyRawVals() *Matrix {
m := NewMatrix(1, l.size, false)
for i := 0; i < l.size; i++ {
m.Set(0, i, l.neurons[i].RawVal())
}
return m
}
func (l *Layer) MatrixifyActivatedVals() *Matrix {
m := NewMatrix(1, l.size, false)
for i := 0; i < l.size; i++ {
m.Set(0, i, l.neurons[i].ActivatedVal())
}
return m
}
func (l *Layer) MatrixifyDerivedVals() *Matrix {
m := NewMatrix(1, l.size, false)
for i := 0; i < l.size; i++ {
m.Set(0, i, l.neurons[i].DerivedVal())
}
return m
}
func (l *Layer) RawVals() []float64 {
ret := make([]float64, l.size)
for i := 0; i < l.size; i++ {
ret[i] = l.neurons[i].RawVal()
}
return ret
}
func (l *Layer) ActivatedVals() []float64 {
ret := make([]float64, l.size)
for i := 0; i < l.size; i++ {
ret[i] = l.neurons[i].ActivatedVal()
}
return ret
}
func (l *Layer) DerivedVals() []float64 {
ret := make([]float64, l.size)
for i := 0; i < l.size; i++ {
ret[i] = l.neurons[i].DerivedVal()
}
return ret
}
func (l *Layer) GetNeurons() []*Neuron {
return l.neurons
}
func (l *Layer) SetNeurons(ns []*Neuron) {
l.neurons = ns
l.size = len(l.neurons)
}
func (l *Layer) Size() int {
return l.size
}
func (l *Layer) Set(i int, val float64) {
l.neurons[i].Set(val)
}
func (l *Layer) ActivationType() ActivationType {
return l.activationType
}