/// <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 (string key in items.Keys) { int value = items[key]; invMap[value] = key; } // now we can query Equilateral eq = new Equilateral(items.Count, high, low); foreach (BasicData data in theTrainingData) { double[] output = alg.ComputeRegression(data.Input); int idealIndex = eq.Decode(data.Ideal); int actualIndex = eq.Decode(output); Console.WriteLine(VectorUtil.DoubleArrayToString(data.Input) + " -> " + invMap[actualIndex] + ", Ideal: " + invMap[idealIndex]); } }
public void TestDecode() { var eq = new Equilateral(3, -1, 1); double[] d0 = { 0.866, 0.5 }; double[] d1 = { -0.866, 0.5 }; double[] d2 = { 0, -1 }; Assert.AreEqual(2, eq.Decode(d0)); Assert.AreEqual(2, eq.Decode(d1)); Assert.AreEqual(0, eq.Decode(d2)); }