* Compute the instar layer.
* @param input The input.
* @return The output.
*/
public MLData computeInstar(final MLData input) {
final MLData result = new BasicMLData(this.instarCount);
int w, i, j;
double sum, sumWinners, maxOut;
int winner = 0;
final boolean[] winners = new boolean[this.instarCount];
for (i = 0; i < this.instarCount; i++) {
sum = 0;
for (j = 0; j < this.inputCount; j++) {
sum += this.weightsInputToInstar.get(j, i) * input.getData(j);
}
result.setData(i, sum);
winners[i] = false;
}
sumWinners = 0;
for (w = 0; w < this.winnerCount; w++) {
maxOut = Double.MIN_VALUE;
for (i = 0; i < this.instarCount; i++) {
if (!winners[i] && (result.getData(i) > maxOut)) {
winner = i;
maxOut = result.getData(winner);
}
}
winners[winner] = true;
sumWinners += result.getData(winner);
}
for (i = 0; i < this.instarCount; i++) {
if (winners[i]
&& (Math.abs(sumWinners) > Encog.DEFAULT_DOUBLE_EQUAL)) {
result.getData()[i] /= sumWinners;
} else {
result.getData()[i] = 0;
}
}
return result;
}