private void btnRecognize_Click(object sender, EventArgs e) { var ds = new DownSample(_entryImage); _downSampled = ds.DoDownSampling(_downSampleWidth, _downSampleHeight); pnlSample.Invalidate(); char bestChar = '?'; double bestDistance = double.MaxValue; foreach (char c in _letterDictionary.Keys) { double[] data = _letterDictionary[c]; double dist = _distCalc.Calculate(data, _downSampled); if (dist < bestDistance) { bestDistance = dist; bestChar = c; } } MessageBox.Show(@"The letter closely matches: " + bestChar, @"Recognize"); ClearEntry(); }
/// <summary> /// Calculate the growth potential for a candidate cell. Evaluates the distance between the candidate cell's info /// vector and the two growth vectors in the genome. The minimum of these two vectors will be returned if /// it is below a specified minimum threshold. /// </summary> /// <param name="universe">The universe to evaluate.</param> /// <param name="row">The row to evaluate.</param> /// <param name="col">The column to evaluate.</param> /// <param name="genome">The genome.</param> /// <returns>The minimum distance.</returns> private double GetGrowthPotential(PlantUniverse universe, int row, int col, double[] genome) { double[] cellVec = universe.GetCellInfoVector(row, col); double d1 = _dist.Calculate(cellVec, 0, genome, PlantUniverse.CellVectorLength * 2, PlantUniverse.CellVectorLength); double d2 = _dist.Calculate(cellVec, 0, genome, PlantUniverse.CellVectorLength * 3, PlantUniverse.CellVectorLength); double result = Math.Min(d1, d2); if (result > PlantUniverse.MinGrowthDist) { result = -1; } return(result); }
public void TestDistanceCalc() { ICalculateDistance calc = new EuclideanDistance(); double[] pos1 = { 0.5, 1.0, 2.5 }; double[] pos2 = { 0.1, 2.0, -2.5 }; Assert.AreEqual(5.1146, calc.Calculate(pos1, pos2), 0.001); }
public void TestRun() { var anneal = new DiscreteAnnealSubclass(1000, 400, 1); while (!anneal.Done) { anneal.Iteration(); } ICalculateDistance dist = new EuclideanDistance(); Assert.AreEqual(1000, anneal.K); Assert.AreEqual(0, dist.Calculate(anneal.Best, DiscreteAnnealSubclass.Ideal), AIFH.DefaultPrecision); Assert.AreEqual(0, anneal.BestScore, AIFH.DefaultPrecision); }