Example #1
0
        public void TestArray()
        {
            double[] a = { 1.0, 2.0 };
            var d = new BasicData(a);
            Assert.AreEqual(2, d.Input.Length);
            Assert.AreEqual(0, d.Ideal.Length);

            Assert.AreEqual(1.0, d.Input[0], AIFH.DefaultPrecision);
            Assert.AreEqual(2.0, d.Input[1], AIFH.DefaultPrecision);
        }
Example #2
0
        public IList<BasicData> GenerateTrainingData()
        {
            IList<BasicData> result = new List<BasicData>();

            for (double x = -50; x < 50; x++)
            {
                double y = (2 * Math.Pow(x, 2)) + (4 * x) + 6;
                var pair = new BasicData(1, 1);
                pair.Input[0] = x;
                pair.Ideal[0] = y;
                result.Add(pair);
            }

            return result;
        }
Example #3
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;
        }
Example #4
0
 public void TestSupervised()
 {
     var data = new BasicData(2, 1);
     Assert.AreEqual(2, data.Input.Length);
     Assert.AreEqual(1, data.Ideal.Length);
 }
Example #5
0
 public void TestLabel()
 {
     var data = new BasicData(2) {Label = "label"};
     Assert.AreEqual("label", data.Label);
 }
Example #6
0
 public void TestToString()
 {
     var data = new BasicData(2);
     Assert.AreEqual("[BasicData: input:0,0, ideal:, label:]", data.ToString());
 }
Example #7
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>();

            int dimensions = HeaderCount - 1;

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

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

                result.Add(row);
            }

            return result;
        }
Example #8
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 (int rowIndex = 0; rowIndex < Count; rowIndex++)
            {
                object[] raw = _data[rowIndex];
                var row = new BasicData(inputCount, idealCount);

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

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

                result.Add(row);
            }

            return result;
        }