this.source.rewind();
int c = 0;
while ((line = this.source.readLine()) != null) {
c++;
for (int i = 0; i < this.helper.getSourceColumns().size(); i++) {
ColumnDefinition colDef = this.helper.getSourceColumns().get(i);
int index = findIndex(colDef);
String value = line[index];
colDef.analyze(value);
}
}
this.analyzedRows = c;
// Calculate the means, and reset for sd calc.
for (ColumnDefinition colDef : this.helper.getSourceColumns()) {
// Only calculate mean/sd for continuous columns.
if (colDef.getDataType() == ColumnType.continuous) {
colDef.setMean(colDef.getMean() / colDef.getCount());
colDef.setSd(0);
}
}
// Sum the standard deviation
this.source.rewind();
while ((line = this.source.readLine()) != null) {
for (int i = 0; i < this.helper.getSourceColumns().size(); i++) {
ColumnDefinition colDef = this.helper.getSourceColumns().get(i);
String value = line[i];
if (colDef.getDataType() == ColumnType.continuous) {
double d = this.helper.parseDouble(value);
d = colDef.getMean() - d;
d = d * d;
colDef.setSd(colDef.getSd() + d);
}
}
}
// Calculate the standard deviations.
for (ColumnDefinition colDef : this.helper.getSourceColumns()) {
// Only calculate sd for continuous columns.
if (colDef.getDataType() == ColumnType.continuous) {
colDef.setSd(Math.sqrt(colDef.getSd() / colDef.getCount()));
}
}
}