コード例 #1
0
ファイル: SimpleLearn.cs プロジェクト: yuvarajan1212/aifh
        /// <summary>
        /// Query a regression algorithm using one-of-n encoding.
        /// </summary>
        /// <param name="alg">The algorithm being used.</param>
        /// <param name="theTrainingData">The training data.</param>
        /// <param name="items">The category items classified.</param>
        public static void QueryOneOfN(
            IRegressionAlgorithm alg,
            IList <BasicData> theTrainingData,
            IDictionary <String, int> items)
        {
            // first, we need to invert the items.  Right now it maps from category to index.  We need index to category.
            IDictionary <int, String> invMap = new Dictionary <int, string>();

            foreach (string key in items.Keys)
            {
                int value = items[key];
                invMap[value] = key;
            }

            // now we can query
            foreach (BasicData data in theTrainingData)
            {
                double[] output      = alg.ComputeRegression(data.Input);
                int      idealIndex  = VectorUtil.MaxIndex(data.Ideal);
                int      actualIndex = VectorUtil.MaxIndex(output);
                Console.WriteLine(VectorUtil.DoubleArrayToString(data.Input) + " -> "
                                  + invMap[actualIndex]
                                  + ", Ideal: " + invMap[idealIndex]);
            }
        }
コード例 #2
0
        /// <summary>
        ///     Query a regression algorithm using equilateral encoding.
        /// </summary>
        /// <param name="alg">The algorithm being used.</param>
        /// <param name="theTrainingData">The training data.</param>
        /// <param name="items">The category items classified.</param>
        /// <param name="high">The high value.</param>
        /// <param name="low">The low value.</param>
        public static void QueryEquilateral(
            IRegressionAlgorithm alg,
            IList <BasicData> theTrainingData,
            IDictionary <string, int> items,
            double high, double low)
        {
            // first, we need to invert the items.  Right now it maps from category to index.  We need index to category.
            IDictionary <int, string> invMap = new Dictionary <int, string>();

            foreach (var key in items.Keys)
            {
                var value = items[key];
                invMap[value] = key;
            }

            // now we can query
            var eq = new Equilateral(items.Count, high, low);

            foreach (var data in theTrainingData)
            {
                var output      = alg.ComputeRegression(data.Input);
                var idealIndex  = eq.Decode(data.Ideal);
                var actualIndex = eq.Decode(output);
                Console.WriteLine(VectorUtil.DoubleArrayToString(data.Input) + " -> " + invMap[actualIndex]
                                  + ", Ideal: " + invMap[idealIndex]);
            }
        }
コード例 #3
0
ファイル: SimpleLearn.cs プロジェクト: yuvarajan1212/aifh
 /// <summary>
 /// Query a regression algorithm and see how close it matches the training data.
 /// </summary>
 /// <param name="alg">The algorithm to evaluate.</param>
 /// <param name="theTrainingData">The training data.</param>
 public static void Query(IRegressionAlgorithm alg, IList <BasicData> theTrainingData)
 {
     foreach (BasicData data in theTrainingData)
     {
         double[] output = alg.ComputeRegression(data.Input);
         Console.WriteLine(VectorUtil.DoubleArrayToString(data.Input) + " -> " + VectorUtil.DoubleArrayToString(output) + ", Ideal: " + VectorUtil.DoubleArrayToString(data.Ideal));
     }
 }
コード例 #4
0
ファイル: Cluster.cs プロジェクト: yuvarajan1212/aifh
        /// <inheritdoc/>
        public override string ToString()
        {
            var result = new StringBuilder();

            result.Append("[Cluster: dimensions=");
            result.Append(Dimensions);
            result.Append(", observations=");
            result.Append(_observations.Count);
            result.Append(", center=");
            result.Append(VectorUtil.DoubleArrayToString(_center));
            result.Append("]");
            return(result.ToString());
        }
コード例 #5
0
        /// <inheritdoc/>
        public override string ToString()
        {
            var result = new StringBuilder();

            result.Append("[BasicData: input:");
            result.Append(VectorUtil.DoubleArrayToString(_input));
            result.Append(", ideal:");
            result.Append(VectorUtil.DoubleArrayToString(_ideal));
            result.Append(", label:");
            result.Append(Label);
            result.Append("]");

            return(result.ToString());
        }