Beispiel #1
0
        /// <summary>
        ///     Encode sliding window.
        /// </summary>
        /// <param name="dataset">The dataset.</param>
        /// <param name="inputWindow">The size of the input window.</param>
        /// <param name="predictedWindow">The size of the prediction window.</param>
        /// <param name="inputColumns">The number of input columns.</param>
        /// <param name="predictedColumns">The number of predicted columns.</param>
        /// <returns>The dataset.</returns>
        public static IList<BasicData> SlidingWindow(
            double[][] dataset,
            int inputWindow,
            int predictedWindow,
            int[] inputColumns,
            int[] predictedColumns)
        {
            IList<BasicData> result = new List<BasicData>();

            var totalWindowSize = inputWindow + predictedWindow;

            var datasetIndex = 0;

            while (dataset.Length - datasetIndex >= totalWindowSize)
            {
                var item = new BasicData(
                    inputWindow*inputColumns.Length,
                    predictedWindow*predictedColumns.Length);

                // input columns
                var inputIdx = 0;
                for (var i = 0; i < inputWindow; i++)
                {
                    for (var j = 0; j < inputColumns.Length; j++)
                    {
                        item.Input[inputIdx++] = dataset[datasetIndex + i][inputColumns[j]];
                    }
                }
                // predicted columns
                var predictIdx = 0;
                for (var i = 0; i < predictedWindow; i++)
                {
                    for (var j = 0; j < predictedColumns.Length; j++)
                    {
                        item.Ideal[predictIdx++] = dataset[datasetIndex + inputWindow + i][predictedColumns[j]];
                    }
                }

                datasetIndex++;
                // add the data item
                result.Add(item);
            }

            return result;
        }
Beispiel #2
0
        /// <summary>
        /// Convert two 2D arrays into a List of BasicData elements.  One array holds input and the other ideal 
        /// vectors. 
        /// </summary>
        /// <param name="inputData">An array of input vectors.</param>
        /// <param name="idealData">An array of ideal vectors.</param>
        /// <returns>A list of BasicData elements.</returns>
        public static IList<BasicData> ConvertArrays(double[][] inputData, double[][] idealData)
        {
            // create the list
            var result = new List<BasicData>();

            // get the lengths
            var inputCount = inputData[0].Length;
            var idealCount = idealData[0].Length;

            // build the list
            for (var row = 0; row < inputData.Length; row++)
            {
                var dataRow = new BasicData(inputCount, idealCount);
                Array.Copy(inputData[row], dataRow.Input, inputCount);
                Array.Copy(idealData[row], dataRow.Ideal, idealCount);
                result.Add(dataRow);
            }

            return result;
        }
Beispiel #3
0
        /// <summary>
        ///     Extract a supervised training set.  This has both input and expected (ideal) output.
        /// </summary>
        /// <param name="inputBegin">The first input column.</param>
        /// <param name="inputCount">The number of columns for input.</param>
        /// <param name="idealBegin">The first ideal column.</param>
        /// <param name="idealCount">The number of columns for ideal.</param>
        /// <returns>The training set.</returns>
        public IList<BasicData> ExtractSupervised(int inputBegin, int inputCount, int idealBegin, int idealCount)
        {
            IList<BasicData> result = new List<BasicData>();

            for (var rowIndex = 0; rowIndex < Count; rowIndex++)
            {
                var raw = _data[rowIndex];
                var row = new BasicData(inputCount, idealCount);

                for (var i = 0; i < inputCount; i++)
                {
                    row.Input[i] = ConvertNumeric(raw, inputBegin + i);
                }

                for (var i = 0; i < idealCount; i++)
                {
                    row.Ideal[i] = ConvertNumeric(raw, idealBegin + i);
                }

                result.Add(row);
            }

            return result;
        }
Beispiel #4
0
        /// <summary>
        ///     Extract and label an unsupervised training set.
        /// </summary>
        /// <param name="labelIndex">The column index to use for the label.</param>
        /// <returns>The training set.</returns>
        public IList<BasicData> ExtractUnsupervisedLabeled(int labelIndex)
        {
            IList<BasicData> result = new List<BasicData>();

            var dimensions = HeaderCount - 1;

            for (var rowIndex = 0; rowIndex < Count; rowIndex++)
            {
                var raw = _data[rowIndex];
                var row = new BasicData(dimensions, 0, raw[labelIndex].ToString());

                var colIndex = 0;
                for (var rawColIndex = 0; rawColIndex < HeaderCount; rawColIndex++)
                {
                    if (rawColIndex != labelIndex)
                    {
                        row.Input[colIndex++] = ConvertNumeric(raw, rawColIndex);
                    }
                }

                result.Add(row);
            }

            return result;
        }