/** * {@inheritDoc} */ @Override public int outputSize(ColumnDefinition colDef) { return colDef.getClasses().size(); }
/** * {@inheritDoc} */ @Override public int normalizeColumn(ColumnDefinition colDef, String value, double[] outputData, int outputColumn) { for (int i = 0; i < colDef.getClasses().size(); i++) { double d = this.normalizedLow; if (colDef.getClasses().get(i).equals(value)) { d = this.normalizedHigh; } outputData[outputColumn + i] = d; } return outputColumn + colDef.getClasses().size(); }
/** * {@inheritDoc} */ @Override public int normalizeColumn(ColumnDefinition colDef, String value, double[] outputData, int outputColumn) { if (!colDef.getClasses().contains(value)) { throw new EncogError("Undefined value: " + value); } outputData[outputColumn] = colDef.getClasses().indexOf(value); return outputColumn + 1; }
/** * {@inheritDoc} */ @Override public String denormalizeColumn(ColumnDefinition colDef, MLData data, int dataColumn) { double high = colDef.getClasses().size(); double low = 0; double value = data.getData(dataColumn); final double result = ((low - high) * value - this.normalizedHigh * low + high * this.normalizedLow) / (this.normalizedLow - this.normalizedHigh); // typically caused by a number that should not have been normalized // (i.e. normalization or actual range is infinitely small. if (Double.isNaN(result)) { return colDef.getClasses().get(0); } return colDef.getClasses().get((int) result); } }
/** * {@inheritDoc} */ @Override public String denormalizeColumn(ColumnDefinition colDef, MLData data, int dataColumn) { return colDef.getClasses().get((int) data.getData(dataColumn)); }
/** * {@inheritDoc} */ @Override public int normalizeColumn(ColumnDefinition colDef, String theValue, double[] outputData, int outputColumn) { // Find the index of the ordinal int v = colDef.getClasses().indexOf(theValue); if (v == -1) { throw new EncogError("Unknown ordinal: " + theValue); } double high = colDef.getClasses().size(); double value = v; double result = (value / high) * (this.normalizedHigh - this.normalizedLow) + this.normalizedLow; // typically caused by a number that should not have been normalized // (i.e. normalization or actual range is infinitely small. if (Double.isNaN(result)) { result = ((this.normalizedHigh - this.normalizedLow) / 2) + this.normalizedLow; } outputData[outputColumn] = result; return outputColumn + 1; }
/** * {@inheritDoc} */ @Override public int determineOutputCount(VersatileMLDataSet dataset) { return dataset.getNormHelper().getOutputColumns().get(0).getClasses().size(); } }
/** * {@inheritDoc} */ @Override public String denormalizeColumn(ColumnDefinition colDef, MLData data, int dataColumn) { double bestValue = Double.NEGATIVE_INFINITY; int bestIndex = 0; for (int i = 0; i < data.size(); i++) { double d = data.getData(dataColumn + i); if (d > bestValue) { bestValue = d; bestIndex = i; } } return colDef.getClasses().get(bestIndex); }