/** * Normalize a single column to the input vector. * * @param colDef The column to normalize. * @param outputColumn The current position in the vector. * @param output The vector to output to. * @param isInput Is this an input column. * @param value The value to normalize. * @return The new current position in the vector. */ public int normalizeToVector( ColumnDefinition colDef, int outputColumn, double[] output, boolean isInput, String value) { MissingHandler handler = null; if (this.unknownValues.contains(value)) { if (!this.missingHandlers.containsKey(colDef)) { throw new EncogError( "Do not know how to process missing value \"" + value + "\" in field: " + colDef.getName()); } handler = this.missingHandlers.get(colDef); } if (colDef.getDataType() == ColumnType.continuous) { double d = parseDouble(value); if (handler != null) { d = handler.processDouble(colDef); } return this.normStrategy.normalizeColumn(colDef, isInput, d, output, outputColumn); } else { if (handler != null) { value = handler.processString(colDef); } return this.normStrategy.normalizeColumn(colDef, isInput, value, output, outputColumn); } }
/** * Calculate the error for the given method and dataset. * * @param method The method to use. * @param data The data to use. * @return The error. */ public double calculateError(MLMethod method, MLDataSet data) { if (this.dataset.getNormHelper().getOutputColumns().size() == 1) { ColumnDefinition cd = this.dataset.getNormHelper().getOutputColumns().get(0); if (cd.getDataType() == ColumnType.nominal) { return EncogUtility.calculateClassificationError((MLClassification) method, data); } } return EncogUtility.calculateRegressionError((MLRegression) method, data); }
/** {@inheritDoc} */ public String toString() { StringBuilder result = new StringBuilder(); result.append("[NormalizationHelper:\n"); for (ColumnDefinition colDef : this.sourceColumns) { result.append(colDef.toString()); result.append("\n"); } result.append("]"); return result.toString(); }
/** {@inheritDoc} */ @Override public String denormalizeColumn(ColumnDefinition colDef, MLData data, int dataColumn) { double value = data.getData(dataColumn); final double result = ((colDef.getLow() - colDef.getHigh()) * value - this.normalizedHigh * colDef.getLow() + colDef.getHigh() * 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 "" + (((this.normalizedHigh - this.normalizedLow) / 2) + this.normalizedLow); } return "" + result; }
/** {@inheritDoc} */ @Override public int normalizeColumn( ColumnDefinition colDef, double value, double[] outputData, int outputColumn) { double result = ((value - colDef.getLow()) / (colDef.getHigh() - colDef.getLow())) * (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; }
/** * Define a source column. These define the raw input. Use this function if you know the index of * the column in a non-header file. * * @param name The name of the column. * @param index The index of the column, needed for non-headered files. * @param colType The column type. * @return The column definition */ public ColumnDefinition defineSourceColumn(String name, int index, ColumnType colType) { ColumnDefinition result = new ColumnDefinition(name, colType); result.setIndex(index); addSourceColumn(result); return result; }
/** * Add a source column. These define the raw input. * * @param def The column definition. */ public void addSourceColumn(ColumnDefinition def) { this.sourceColumns.add(def); def.setOwner(this); }