* @param input
* The input to this synapse.
* @return The output from this synapse.
*/
public MLData compute(final MLData input) {
final MLData result = new BasicMLData(this.outputCount);
if (this.neurons.size() == 0) {
throw new NeuralNetworkError(
"This network has not been evolved yet, it has no neurons in the NEAT synapse.");
}
int flushCount = 1;
if (this.snapshot) {
flushCount = this.networkDepth;
}
// iterate through the network FlushCount times
for (int i = 0; i < flushCount; ++i) {
int outputIndex = 0;
int index = 0;
result.clear();
// populate the input neurons
while (this.neurons.get(index).getNeuronType()
== NEATNeuronType.Input) {
this.neurons.get(index).setOutput(input.getData(index));
index++;
}
// set the bias neuron
this.neurons.get(index++).setOutput(1);
while (index < this.neurons.size()) {
final NEATNeuron currentNeuron = this.neurons.get(index);
double sum = 0;
for (final NEATLink link : currentNeuron.getInboundLinks()) {
final double weight = link.getWeight();
final double neuronOutput = link.getFromNeuron()
.getOutput();
sum += weight * neuronOutput;
}
final double[] d = new double[1];
d[0] = sum / currentNeuron.getActivationResponse();
this.activationFunction.activationFunction(d,0,d.length);
this.neurons.get(index).setOutput(d[0]);
if (currentNeuron.getNeuronType() == NEATNeuronType.Output) {
result.setData(outputIndex++, currentNeuron.getOutput());
}
index++;
}
}
this.outputActivationFunction.activationFunction(result.getData(), 0, result.size());
return result;
}