/// <inheritdoc />
 public int NormalizeColumn(ColumnDefinition colDef, double value,
     double[] outputData, int outputColumn)
 {
     throw new EncogError(
         "Can't use an indexed normalizer on a continuous value: "
         + value);
 }
        /// <inheritdoc />
        public int NormalizeColumn(ColumnDefinition colDef, String theValue,
            double[] outputData, int outputColumn)
        {
            // Find the index of the ordinal
            int v = colDef.Classes.IndexOf(theValue);
            if (v == -1)
            {
                throw new EncogError("Unknown ordinal: " + theValue);
            }

            double high = colDef.Classes.Count;
            double value = v;

            double result = (value/high)
                            *(_normalizedHigh - _normalizedLow)
                            + _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 = ((_normalizedHigh - _normalizedLow)/2)
                         + _normalizedLow;
            }

            outputData[outputColumn] = result;

            return outputColumn + 1;
        }
        /// <inheritdoc />
        public int NormalizeColumn(ColumnDefinition colDef, String value,
            double[] outputData, int outputColumn)
        {
            if (!colDef.Classes.Contains(value))
            {
                throw new EncogError("Undefined value: " + value);
            }

            outputData[outputColumn] = colDef.Classes.IndexOf(value);
            return outputColumn + 1;
        }
        /// <inheritdoc />
        public int NormalizeColumn(ColumnDefinition colDef, String value,
            double[] outputData, int outputColumn)
        {
            for (int i = 0; i < colDef.Classes.Count; i++)
            {
                double d = _normalizedLow;

                if (colDef.Classes[i].Equals(value))
                {
                    d = _normalizedHigh;
                }

                outputData[outputColumn + i] = d;
            }
            return outputColumn + colDef.Classes.Count;
        }
        /// <inheritdoc />
        public String DenormalizeColumn(ColumnDefinition colDef, IMLData data,
            int dataColumn)
        {
            double value = data[dataColumn];
            double result = ((colDef.Low - colDef.High)*value
                             - _normalizedHigh*colDef.Low + colDef.High
                             *_normalizedLow)
                            /(_normalizedLow - _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 "" + (((_normalizedHigh - _normalizedLow)/2) + _normalizedLow);
            }
            return "" + result;
        }
        /// <summary>
        ///     Find the index of a column.
        /// </summary>
        /// <param name="colDef">The column.</param>
        /// <returns>The column index.</returns>
        private int FindIndex(ColumnDefinition colDef)
        {
            if (colDef.Index != -1)
            {
                return colDef.Index;
            }

            int index = _source.ColumnIndex(colDef.Name);
            colDef.Index = index;

            if (index == -1)
            {
                throw new EncogError("Can't find column");
            }

            return index;
        }
        /// <inheritdoc />
        public String DenormalizeColumn(ColumnDefinition colDef, IMLData data,
            int dataColumn)
        {
            double bestValue = Double.NegativeInfinity;
            int bestIndex = 0;

            for (int i = 0; i < data.Count; i++)
            {
                double d = data[dataColumn + i];
                if (d > bestValue)
                {
                    bestValue = d;
                    bestIndex = i;
                }
            }

            return colDef.Classes[bestIndex];
        }
        /// <inheritdoc />
        public int NormalizeColumn(ColumnDefinition colDef, double value,
            double[] outputData, int outputColumn)
        {
            double result = ((value - colDef.Low)/(colDef.High - colDef.Low))
                            *(_normalizedHigh - _normalizedLow)
                            + _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 = ((_normalizedHigh - _normalizedLow)/2) + _normalizedLow;
            }

            outputData[outputColumn] = result;

            return outputColumn + 1;
        }
示例#9
0
        /// <inheritdoc />
        public String DenormalizeColumn(ColumnDefinition colDef, IMLData data,
            int dataColumn)
        {
            double high = colDef.Classes.Count;
            double low = 0;

            double value = data[dataColumn];
            double result = ((low - high)*value - _normalizedHigh*low + high
                             *_normalizedLow)
                            /(_normalizedLow - _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.Classes[0];
            }
            return colDef.Classes[(int) result];
        }
 /// <summary>
 ///     Add a source column. These define the raw input.
 /// </summary>
 /// <param name="def">The column definition.</param>
 public void AddSourceColumn(ColumnDefinition def)
 {
     _sourceColumns.Add(def);
     def.Owner = this;
 }
 /// <inheritdoc />
 public int NormalizeColumn(ColumnDefinition colDef, String value,
     double[] outputData, int outputColumn)
 {
     throw new EncogError("Can't range-normalize a string value: " + value);
 }
 /// <inheritdoc />
 public String DenormalizeColumn(ColumnDefinition colDef, IMLData data,
     int dataColumn)
 {
     return colDef.Classes[(int) data[dataColumn]];
 }
 /// <inheritdoc />
 public int NormalizedSize(ColumnDefinition colDef, bool isInput)
 {
     INormalizer norm = FindNormalizer(colDef, isInput);
     return norm.OutputSize(colDef);
 }
 /// <summary>
 ///     Define an input column.
 /// </summary>
 /// <param name="col">The input column.</param>
 public void DefineInput(ColumnDefinition col)
 {
     NormHelper.InputColumns.Add(col);
 }
 /// <inheritdoc />
 public String DenormalizeColumn(ColumnDefinition colDef, bool isInput,
     IMLData data, int dataColumn)
 {
     INormalizer norm = FindNormalizer(colDef, isInput);
     return norm.DenormalizeColumn(colDef, data, dataColumn);
 }
 /// <inheritdoc/>
 public String ProcessString(ColumnDefinition colDef)
 {
     throw new EncogError("The mean missing handler only accepts continuous numeric values.");
 }
 /// <inheritdoc />
 public int NormalizeColumn(ColumnDefinition colDef, double value,
     double[] outputData, int outputColumn)
 {
     outputData[outputColumn] = value;
     return outputColumn + 1;
 }
 /// <inheritdoc />
 public String DenormalizeColumn(ColumnDefinition colDef, IMLData data,
     int dataColumn)
 {
     return "" + data[dataColumn];
 }
        /// <summary>
        ///     Define a single column as an output column, all others as inputs.
        /// </summary>
        /// <param name="outputColumn">The output column.</param>
        public void DefineSingleOutputOthersInput(ColumnDefinition outputColumn)
        {
            NormHelper.ClearInputOutput();

            foreach (ColumnDefinition colDef in NormHelper.SourceColumns)
            {
                if (colDef == outputColumn)
                {
                    DefineOutput(colDef);
                }
                else if (colDef.DataType != ColumnType.Ignore)
                {
                    DefineInput(colDef);
                }
            }
        }
 /// <inheritdoc />
 public int NormalizeColumn(ColumnDefinition colDef, String value,
     double[] outputData, int outputColumn)
 {
     throw new EncogError("Can't use a pass-through normalizer on a string value: " + value);
 }
 /// <summary>
 ///     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.
 /// </summary>
 /// <param name="name">The name of the column.</param>
 /// <param name="index">The index of the column, needed for non-headered files.</param>
 /// <param name="colType">The column type.</param>
 /// <returns>The column definition</returns>
 public ColumnDefinition DefineSourceColumn(string name, int index,
     ColumnType colType)
 {
     var result = new ColumnDefinition(name, colType) {Index = index};
     AddSourceColumn(result);
     return result;
 }
 /// <inheritdoc />
 public int OutputSize(ColumnDefinition colDef)
 {
     return 1;
 }
        /// <summary>
        ///     Normalize a single column to the input vector.
        /// </summary>
        /// <param name="colDef">The column to normalize.</param>
        /// <param name="outputColumn">The current position in the vector.</param>
        /// <param name="output">The vector to output to.</param>
        /// <param name="isInput">Is this an input column.</param>
        /// <param name="value">The value to normalize.</param>
        /// <returns>The new current position in the vector.</returns>
        public int NormalizeToVector(ColumnDefinition colDef, int outputColumn,
            double[] output, bool isInput, String value)
        {
            IMissingHandler handler = null;

            if (_unknownValues.Contains(value))
            {
                if (!_missingHandlers.ContainsKey(colDef))
                {
                    throw new EncogError(
                        "Do not know how to process missing value \"" + value
                        + "\" in field: " + colDef.Name);
                }
                handler = _missingHandlers[colDef];
            }

            if (colDef.DataType == ColumnType.Continuous)
            {
                double d = ParseDouble(value);
                if (handler != null)
                {
                    d = handler.ProcessDouble(colDef);
                }
                return NormStrategy.NormalizeColumn(colDef, isInput, d,
                    output, outputColumn);
            }
            if (handler != null)
            {
                value = handler.ProcessString(colDef);
            }
            return NormStrategy.NormalizeColumn(colDef, isInput, value,
                output, outputColumn);
        }
 /// <inheritdoc/>
 public double ProcessDouble(ColumnDefinition colDef)
 {
     return colDef.Mean;
 }
 /// <summary>
 ///     Define a missing value handler.
 /// </summary>
 /// <param name="colDef">The column this handler applies to.</param>
 /// <param name="handler">The handler.</param>
 public void DefineMissingHandler(ColumnDefinition colDef,
     IMissingHandler handler)
 {
     _missingHandlers[colDef] = handler;
     handler.Init(this);
 }
        /// <summary>
        ///     Find a normalizer for the specified column definition, and if it is input or output.
        /// </summary>
        /// <param name="colDef">The column definition.</param>
        /// <param name="isInput">True if the column is input.</param>
        /// <returns>The normalizer to use.</returns>
        private INormalizer FindNormalizer(ColumnDefinition colDef, bool isInput)
        {
            INormalizer norm = null;

            if (isInput)
            {
                if (_inputNormalizers.ContainsKey(colDef.DataType))
                {
                    norm = _inputNormalizers[colDef.DataType];
                }
            }
            else
            {
                if (_outputNormalizers.ContainsKey(colDef.DataType))
                {
                    norm = _outputNormalizers[colDef.DataType];
                }
            }

            if (norm == null)
            {
                throw new EncogError("No normalizer defined for input=" + isInput + ", type=" + colDef.DataType);
            }
            return norm;
        }
示例#27
0
 /// <inheritdoc />
 public int NormalizeColumn(ColumnDefinition colDef, double value,
     double[] outputData, int outputColumn)
 {
     throw new EncogError(
         "Can't ordinal range-normalize a continuous value: " + value);
 }
 /// <inheritdoc />
 public int NormalizeColumn(ColumnDefinition colDef, bool isInput,
     String value, double[] outputData, int outputColumn)
 {
     INormalizer norm = FindNormalizer(colDef, isInput);
     return norm.NormalizeColumn(colDef, value, outputData, outputColumn);
 }
 /// <inheritdoc />
 public int OutputSize(ColumnDefinition colDef)
 {
     return colDef.Classes.Count;
 }