*/
private void randomizeNeuron(final int targetLayer, final int neuron,
final boolean useRange, final double low, final double high,
final boolean usePercent, final double percent) {
final Randomizer d;
if (useRange) {
d = new RangeRandomizer(low, high);
} else {
d = new Distort(percent);
}
// check for errors
this.network.validateNeuron(targetLayer, neuron);
// access the flat network
final FlatNetwork flat = this.network.getStructure().getFlat();
// allocate new weights now that we know how big the new weights will be
final double[] newWeights = new double[flat.getWeights().length];
// construct the new weights
int weightsIndex = 0;
for (int fromLayer = flat.getLayerCounts().length - 2; fromLayer >= 0; fromLayer--) {
final int fromNeuronCount = this.network
.getLayerTotalNeuronCount(fromLayer);
final int toNeuronCount = this.network
.getLayerNeuronCount(fromLayer + 1);
final int toLayer = fromLayer + 1;
for (int toNeuron = 0; toNeuron < toNeuronCount; toNeuron++) {
for (int fromNeuron = 0; fromNeuron < fromNeuronCount; fromNeuron++) {
boolean randomize = false;
if ((toLayer == targetLayer) && (toNeuron == neuron)) {
randomize = true;
} else if ((fromLayer == targetLayer)
&& (fromNeuron == neuron)) {
randomize = true;
}
double weight = this.network.getWeight(fromLayer,
fromNeuron, toNeuron);
if (randomize) {
weight = d.randomize(weight);
}
newWeights[weightsIndex++] = weight;
}
}