-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.go
80 lines (63 loc) · 1.25 KB
/
output.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
package channn
import (
"fmt"
"sync"
)
// Output
type Output struct {
InChan chan float64
NumIn *int32
Bias float64
mutex *sync.Mutex
Control chan *ControlMessage
Result float64
OutChan chan float64
nType NeuronType
}
func (o *Output) String() string {
return fmt.Sprintf("output %s", &o)
}
func (o Output) GetResult() float64 {
o.Result = <-o.OutChan
return o.Result
}
func (o *Output) GetInChanPtr() *chan float64 {
return &o.InChan
}
func (po *Output) ReceiveControlMsg(msg *ControlMessage) {
po.Control <- msg
}
// Fire accepts the value which is the sum of all inputs
// with the bias added; it sends the result of calling the sigmoid
// function on this value.
func (so *Output) Fire(val float64) {
so.OutChan <- Sigmoid(val)
}
func (o *Output) Listen() {
var counter = *o.NumIn
var layerTotal float64
for {
select {
case inVal := <-o.InChan:
layerTotal += inVal
counter--
if counter == 0 {
// The sum of the (Xi * Wj)
o.Fire(layerTotal + o.Bias)
layerTotal = 0.0
counter = *o.NumIn
}
case ctlMsg := <-o.Control:
switch ctlMsg.Id {
case DESTROY:
return
case INCREMENT_INPUT:
cur := (*o.NumIn + 1)
o.NumIn = &cur
counter = *o.NumIn
default:
continue
}
}
}
}