* @param method The method to use.
*/
public final void process(final File outputFile,
final MLRegression method) {
final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
isExpectInputHeaders(), getInputFormat());
if (method.getInputCount() != this.inputCount) {
throw new AnalystError("This machine learning method has "
+ method.getInputCount()
+ " inputs, however, the data has " + this.inputCount
+ " inputs.");
}
MLData output = null;
final MLData input = new BasicMLData(method.getInputCount());
final PrintWriter tw = analystPrepareOutputFile(outputFile);
resetStatus();
while (csv.next()) {
updateStatus(false);
final LoadedRow row = new LoadedRow(csv, this.idealCount);
int dataIndex = 0;
// load the input data
for (int i = 0; i < this.inputCount; i++) {
final String str = row.getData()[i];
final double d = getInputFormat().parse(str);
input.setData(i, d);
dataIndex++;
}
// do we need to skip the ideal values?
dataIndex += this.idealCount;
// compute the result
output = method.compute(input);
// display the computed result
for (int i = 0; i < this.outputCount; i++) {
final double d = output.getData(i);
row.getData()[dataIndex++] = getInputFormat().format(d,
getPrecision());
}
writeRow(tw, row);
}
reportDone(false);
tw.close();
csv.close();
}