Пример #1
0
        /// <summary>
        /// Calculates the distance.
        /// </summary>
        /// <param name="metric">The metric.</param>
        /// <param name="bmu">The bmu.</param>
        /// <param name="gridNeuron">The grid neuron.</param>
        /// <returns>System.Double.</returns>
        public double CalculateDistance(IMetric metric, IBestMatchingUnit bmu, IGridNeuron gridNeuron)
        {
            var distanceToBmu = metric.CalculateDistance(bmu.GridCoordinates, gridNeuron.GridCoordinates);

            if (!IsToroidal)
            {
                return(distanceToBmu);
            }

            // on spherical grids, check the wrap-around distances
            //
            //
            //   X 1 2 2 1
            //   1 2 3 3 2
            //   2 3 4 4 3
            //   1 2 3 3 2

            var coordinates   = gridNeuron.GridCoordinates;
            var coordinatesX  = new[] { coordinates[0] - Width + 2, coordinates[1] };
            var coordinatesY  = new[] { coordinates[0], coordinates[1] - Height + 2 };
            var coordinatesXy = new[] { coordinatesX[0], coordinatesY[1] };

            distanceToBmu = Math.Min(distanceToBmu, metric.CalculateDistance(bmu.GridCoordinates, coordinatesX));
            distanceToBmu = Math.Min(distanceToBmu, metric.CalculateDistance(bmu.GridCoordinates, coordinatesY));
            distanceToBmu = Math.Min(distanceToBmu, metric.CalculateDistance(bmu.GridCoordinates, coordinatesXy));
            return(distanceToBmu);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BestMatchingUnit"/> class.
 /// </summary>
 /// <param name="bmu">The bmu.</param>
 /// <param name="distance">The distance.</param>
 public BestMatchingUnit(IGridNeuron bmu, double distance)
 {
     Distance = distance;
     _bmu     = bmu;
 }