jeffheaton / encog-java-core

http://www.heatonresearch.com/encog
Other
744 stars 268 forks source link

ColumnDefinition: default index should be -1 #192

Closed andrewthomas28 closed 7 years ago

andrewthomas28 commented 9 years ago

Observed in Encog 3.3.0.

The constructor for the ColumnDefinition class does not set the field index. Consequently, its value after construction is zero - a valid index but probably the wrong value.

If any code fails to call ColumnDefinition.setIndex() after construction, then VersatileDataSet.findIndex() happily returns that usually wrong value, instead of searching for the correct value with VersatileDataSource.columnIndex().

The default value of the field ColumnDefinition.index should be -1. This can be accomplished either with a field initialization:

private int index = -1;

Or an explicit initialization in the constructor, just like this.count:

public ColumnDefinition(String theName, ColumnType theDataType) {
    this.name = theName;
    this.dataType = theDataType;
    this.count = -1;
    this.index = -1;   // <<<<< NEW LINE
    this.low = this.high = this.mean = this.sd = Double.NaN;
}
andrewthomas28 commented 9 years ago

Addressed by pull request https://github.com/encog/encog-java-core/pull/195 .

jeffheaton commented 7 years ago

Thanks!