training.getRecord(r, pair);
this.network.setExclude(this.network.getExclude() - 1);
err = 0.0;
final MLData input = pair.getInput();
final MLData target = pair.getIdeal();
if (this.network.getOutputMode() == PNNOutputMode.Unsupervised) {
if (deriv) {
final MLData output = computeDeriv(input, target);
for (int z = 0; z < this.network.getOutputCount(); z++) {
out[z] = output.getData(z);
}
} else {
final MLData output = this.network.compute(input);
for (int z = 0; z < this.network.getOutputCount(); z++) {
out[z] = output.getData(z);
}
}
for (int i = 0; i < this.network.getOutputCount(); i++) {
diff = input.getData(i) - out[i];
err += diff * diff;
}
} else if (this.network.getOutputMode() == PNNOutputMode.Classification) {
final int tclass = (int) target.getData(0);
MLData output;
if (deriv) {
output = computeDeriv(input, pair.getIdeal());
output.getData(0);
} else {
output = this.network.compute(input);
output.getData(0);
}
out[0] = output.getData(0);
for (int i = 0; i < out.length; i++) {
if (i == tclass) {
diff = 1.0 - out[i];
err += diff * diff;
} else {
err += out[i] * out[i];
}
}
}
else if (this.network.getOutputMode() == PNNOutputMode.Regression) {
if (deriv) {
final MLData output = this.network.compute(input);
for (int z = 0; z < this.network.getOutputCount(); z++) {
out[z] = output.getData(z);
}
} else {
final MLData output = this.network.compute(input);
for (int z = 0; z < this.network.getOutputCount(); z++) {
out[z] = output.getData(z);
}
}
for (int i = 0; i < this.network.getOutputCount(); i++) {
diff = target.getData(i) - out[i];
err += diff * diff;