Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/main/java/org/encog/neural/flat/FlatNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.encog.Encog;
Expand Down Expand Up @@ -289,19 +290,17 @@ public final void clearContext() {
final boolean hasBias = (this.layerContextCount[i] + this.layerFeedCounts[i]) != this.layerCounts[i];

// fill in regular neurons
for (int j = 0; j < this.layerFeedCounts[i]; j++) {
this.layerOutput[index++] = 0;
}
Arrays.fill(this.layerOutput, index, this.layerFeedCounts[i], 0);
index += this.layerFeedCounts[i];

// fill in the bias
if (hasBias) {
this.layerOutput[index++] = this.biasActivation[i];
}

// fill in context
for (int j = 0; j < this.layerContextCount[i]; j++) {
this.layerOutput[index++] = 0;
}
Arrays.fill(this.layerOutput, index, this.layerContextCount[i], 0);
index += this.layerContextCount[i];
}
}

Expand Down Expand Up @@ -372,9 +371,8 @@ public void compute(final double[] input, final double[] output) {
// update context values
final int offset = this.contextTargetOffset[0];

for (int x = 0; x < this.contextTargetSize[0]; x++) {
this.layerOutput[offset + x] = this.layerOutput[x];
}
EngineArray.arrayCopy(this.layerOutput, 0, layerOutput,
offset, this.contextTargetSize[0]);

EngineArray.arrayCopy(this.layerOutput, 0, output, 0, this.outputCount);
}
Expand Down Expand Up @@ -413,9 +411,8 @@ protected void computeLayer(final int currentLayer) {
// update context values
final int offset = this.contextTargetOffset[currentLayer];

for (int x = 0; x < this.contextTargetSize[currentLayer]; x++) {
this.layerOutput[offset + x] = this.layerOutput[outputIndex + x];
}
EngineArray.arrayCopy(this.layerOutput, outputIndex,
this.layerOutput, offset, this.contextTargetSize[currentLayer]);
}

/**
Expand Down Expand Up @@ -727,11 +724,7 @@ public final void randomize(final double hi, final double lo) {
* @param af The activation functions.
*/
public final void setActivationFunctions(final ActivationFunction[] af) {

this.activationFunctions = new ActivationFunction[af.length];
for (int i = 0; i < af.length; i++) {
this.activationFunctions[i] = af[i];
}
this.activationFunctions = Arrays.copyOf(af, af.length);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/encog/neural/flat/FlatNetworkRBF.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.encog.neural.flat;

import java.io.Serializable;
import java.util.Arrays;

import org.encog.engine.network.activation.ActivationLinear;
import org.encog.mathutil.rbf.RadialBasisFunction;
Expand Down Expand Up @@ -117,10 +118,7 @@ public final void compute(final double[] x, final double[] output) {
* @param rbf The RBF's used.
*/
public final void setRBF(final RadialBasisFunction[] rbf) {
this.rbf = new RadialBasisFunction[rbf.length];
for(int i=0;i<rbf.length;i++) {
this.rbf[i] = rbf[i];
}
this.rbf = Arrays.copyOf(rbf, rbf.length);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ public double calculate(final int maxIterations, final double maxError,
}
fbest = globalMinimum.getY2();
} else {
for (int i = 0; i < n; i++) {
x[i] = base[i];
}
System.arraycopy(base, 0, x, 0, n);
}
break;
}
Expand Down Expand Up @@ -254,8 +252,8 @@ private void findNewDir(final int n, final double gam, final double[] g,
final double[] h, final double[] grad) {
int i;

System.arraycopy(grad, 0, g, 0, n);
for (i = 0; i < n; i++) {
g[i] = grad[i];
grad[i] = h[i] = g[i] + gam * h[i];
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/encog/util/EngineArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ public static double[][] arrayCopy(final double[][] source) {
final double[][] result = new double[source.length][source[0].length];

for (int row = 0; row < source.length; row++) {
for (int col = 0; col < source[0].length; col++) {
result[row][col] = source[row][col];
}
System.arraycopy(source[row], 0, result[row], 0, source[0].length);
}

return result;
Expand Down