Skip to content

Commit

Permalink
Amended LoadSensors to use default BIAS value when it's not provided …
Browse files Browse the repository at this point in the history
…as input
  • Loading branch information
yaricom committed Dec 24, 2018
1 parent 3e6f27c commit eaec124
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions neat/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,27 @@ func (n *Network) Relax(maxSteps int, maxAllowedSignalDelta float64) (bool, erro

// Takes an array of sensor values and loads it into SENSOR inputs ONLY
func (n *Network) LoadSensors(sensors []float64) error {
if len(sensors) != len(n.inputs) {
return NetErrUnsupportedSensorsArraySize
}

counter := 0
for _, node := range n.inputs {
if node.IsSensor() {
node.SensorLoad(sensors[counter])
counter += 1
if len(sensors) == len(n.inputs) {
// BIAS value provided as input
for _, node := range n.inputs {
if node.IsSensor() {
node.SensorLoad(sensors[counter])
counter += 1
}
}
} else {
// use default BIAS value
for _, node := range n.inputs {
if node.NeuronType == InputNeuron {
node.SensorLoad(sensors[counter])
counter += 1
} else {
node.SensorLoad(1.0) // default BIAS value
}
}
}

return nil
}

Expand Down

0 comments on commit eaec124

Please sign in to comment.