Created
June 20, 2011 20:27
-
-
Save kylelemons/1036496 to your computer and use it in GitHub Desktop.
How to broadcast a message to peers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type neuron struct { | |
coef float64 | |
input chan *stimulus | |
output []chan *stimulus | |
} | |
func newNeuron(coef float64) *neuron { | |
n := &neuron{ | |
coef: coef, | |
input: make(chan *stimulus), | |
} | |
go func() { | |
for stimulus := range n.input { | |
for _, out := range n.output { | |
out <- stimulus.mult(coef) | |
} | |
} | |
for _, out := range n.output { | |
close(out) | |
} | |
}() | |
return n | |
} | |
func (n *neuron) stimulates(remote *neuron) { | |
n.output = append(n.output, remote.input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment