protected void setupMetrics() { int lastIndex = n - 1; // metrics= // (MutableTableImpl)DefaultTableFactory.getInstance().createTable(tts[lastIndex].getNumOutputFeatures()); metrics = new MutableTableImpl(tts[lastIndex].getNumOutputFeatures()); for (int i = 0; i < metrics.getNumColumns(); i++) { metrics.setColumn(new DoubleColumn(n), i); metrics.setColumnLabel( tts[lastIndex].getColumnLabel(tts[lastIndex].getOutputFeatures()[i]), i); } }
public void computeError(PredictionTable tt, int m) { int rows = tt.getNumRows(); int columns = tt.getNumOutputFeatures(); // store an rms error for each output feature, make sure to initialize to zero double[] rmse = new double[columns]; for (int i = 0; i < rmse.length; i++) { rmse[i] = 0; } int[] ttOuts = tt.getOutputFeatures(); int[] ttPreds = tt.getPredictionSet(); for (int j = 0; j < columns; j++) { for (int i = 0; i < rows; i++) { double row_error; double prediction = tt.getDouble(i, ttPreds[j]); double target = tt.getDouble(i, ttOuts[j]); if (printResults) { System.out.println("T,P,: " + target + "," + prediction); } row_error = Math.abs(target - prediction); row_error *= row_error; rmse[j] += row_error; } } for (int j = 0; j < rmse.length; j++) { rmse[j] = rmse[j] / rows; rmse[j] = Math.sqrt(rmse[j]); // put the error in the verticalTable metrics.setDouble(rmse[j], m, j); } }