/// <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)); }
public void Evaluate(FileInfo networkFile, FileInfo analystFile, FileInfo EvaluationFile) { var network = EncogDirectoryPersistence.LoadObject(networkFile) as BasicNetwork; var analyst = new EncogAnalyst(); analyst.Load(analystFile); var evaluationSet = EncogUtility.LoadCSV2Memory(EvaluationFile.ToString(), network.InputCount, network.OutputCount, true, CSVFormat.English, false); int count = 0; int correctCount = 0; foreach (var item in evaluationSet) { var sepal_l = analyst.Script.Normalize.NormalizedFields[0].DeNormalize(item.Input[0]); var sepal_w = analyst.Script.Normalize.NormalizedFields[1].DeNormalize(item.Input[1]); var petal_l = analyst.Script.Normalize.NormalizedFields[2].DeNormalize(item.Input[2]); var petal_w = analyst.Script.Normalize.NormalizedFields[3].DeNormalize(item.Input[3]); int classCount = analyst.Script.Normalize.NormalizedFields[4].Classes.Count; double normalizationHigh = analyst.Script.Normalize.NormalizedFields[4].NormalizedHigh; double normalizationLow = analyst.Script.Normalize.NormalizedFields[4].NormalizedLow; var output = network.Compute(item.Input); var resulter = new Equilateral(classCount, normalizationHigh, normalizationLow); var predictedClassInt = resulter.Decode(output); var predictedClass = analyst.Script.Normalize.NormalizedFields[4].Classes[predictedClassInt].Name; var idealClassInt = resulter.Decode(item.Ideal); var idealClass = analyst.Script.Normalize.NormalizedFields[4].Classes[idealClassInt].Name; if (predictedClassInt == idealClassInt) { ++correctCount; } Console.WriteLine($"Count: {++count} | Ideal: {idealClass} Predicted:{predictedClass}"); } Console.WriteLine($"Total test count: {count}"); Console.WriteLine($"Total correct test count: {correctCount}"); Console.WriteLine($"% Success: {(correctCount*100.0)/count}"); }
/// <summary> /// Determine what class the specified data belongs to. /// </summary> /// /// <param name="data">The data to analyze.</param> /// <returns>The class the data belongs to.</returns> public ClassItem DetermineClass(double[] data) { int resultIndex = 0; switch (_action) { case NormalizationAction.Equilateral: resultIndex = _eq.Decode(data); break; case NormalizationAction.OneOf: resultIndex = EngineArray.IndexOfLargest(data); break; case NormalizationAction.SingleField: resultIndex = (int)data[0]; break; default: throw new AnalystError("Unknown action: " + _action); } return(_classes[resultIndex]); }
public int DenormalizeSeconds(double[] seconds) { var eq = new Equilateral(60, -1, 1); return(eq.Decode(seconds)); }
public int DenormalizeHour(double[] hour) { var eq = new Equilateral(24, -1, 1); return(eq.Decode(hour)); }
public int DenormalizeDays(double[] days) { var eq = new Equilateral(31, -1, 1); return(eq.Decode(days)); }
public int DenormalizeMonth(double[] montharry) { var eq = new Equilateral(12, -1, 1); return(eq.Decode(montharry)); }
public int DenormalizeYear(double[] days, int MaxYear) { var eq = new Equilateral(MaxYear, -1, 1); return(eq.Decode(days)); }
public static int DenormalizeYear(double[] year) { var eq = new Equilateral(2011, -1, 1); return(eq.Decode(year)); }