Skip to content

Commit

Permalink
Fixed issue with TemporalMLData set's index.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffheaton committed Jan 11, 2014
1 parent 14ab58b commit 11bb5ac
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/org/encog/ml/data/temporal/TemporalMLDataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.encog.ml.data.MLDataPair;
import org.encog.ml.data.basic.BasicMLData;
import org.encog.ml.data.basic.BasicMLDataPair;
import org.encog.ml.data.temporal.TemporalDataDescription.Type;
import org.encog.neural.data.basic.BasicNeuralData;
import org.encog.neural.data.basic.BasicNeuralDataSet;
import org.encog.util.time.TimeSpan;
Expand Down Expand Up @@ -329,7 +330,14 @@ public TemporalPoint createPoint(final int sequence) {
private double formatData(final TemporalDataDescription desc,
final int index) {
final double[] result = new double[1];


if( desc.getType()==Type.DELTA_CHANGE || desc.getType()==Type.PERCENT_CHANGE ) {
if (index + this.inputWindowSize > this.points.size()) {
throw new TemporalError("Can't generate input temporal data "
+ "beyond the end of provided data.");
}
}

switch (desc.getType()) {
case DELTA_CHANGE:
result[0] = getDataDeltaChange(desc, index);
Expand All @@ -356,6 +364,7 @@ private double formatData(final TemporalDataDescription desc,
*/
public void generate() {
sortPoints();
// add one to the start index so we are "one ahead", needed to calculate DELTA, if that encoding is chosen.
final int start = calculateStartIndex() + 1;
final int setSize = calculateActualSetSize();
final int range = start + setSize - this.predictWindowSize
Expand All @@ -379,11 +388,6 @@ public void generate() {
* @return The input neural data generated.
*/
public BasicNeuralData generateInputNeuralData(final int index) {
if (index + this.inputWindowSize > this.points.size()) {
throw new TemporalError("Can't generate input temporal data "
+ "beyond the end of provided data.");
}

final BasicNeuralData result = new BasicNeuralData(
this.inputNeuronCount);
int resultIndex = 0;
Expand Down Expand Up @@ -487,7 +491,10 @@ private double getDataPercentChange(final TemporalDataDescription desc,
*/
private double getDataRAW(final TemporalDataDescription desc,
final int index) {
final TemporalPoint point = this.points.get(index);
// Note: The reason that we subtract 1 from the index is because we are always one ahead.
// This allows the DELTA change formatter to work. DELTA change requires two timeslices,
// so we have to be one ahead. RAW only requires one, so we shift backwards.
final TemporalPoint point = this.points.get(index-1);
return point.getData(desc.getIndex());
}

Expand Down

0 comments on commit 11bb5ac

Please sign in to comment.