コード例 #1
0
ファイル: KDTree.cs プロジェクト: ericreg/Supercluster
 /// <summary>
 /// Initializes a new instance of the <see cref="KDTree{TNode}"/> class.
 /// </summary>
 /// <param name="dimensions">The number of dimensions in the data set.</param>
 /// <param name="nodes">The nodes associated with each point.</param>
 /// <param name="metric">The metric function which implicitly defines the metric space in which the KDTree operates in. This should satisfy the triangle inequality.</param>
 public KDTree(
     int dimensions,
     Func <double[], double[], double> metric,
     Func <TNode, double[]> selector = null)
 {
     this.PointSelector = selector ?? CoordinateSelector.CreateDefaultCoordinateSelector <TNode>();
     this.InternalList  = new List <TNode>();
     this.Dimensions    = dimensions;
     this.Metric        = metric;
 }
コード例 #2
0
ファイル: KDTree.cs プロジェクト: ericreg/Supercluster
        public KDTree(int dimensions,
                      IEnumerable <TNode> nodes,
                      Func <double[], double[], double> metric,
                      Func <TNode, double[]> selector = null)
        {
            this.PointSelector = selector ?? CoordinateSelector.CreateDefaultCoordinateSelector <TNode>();
            this.InternalList  = new List <TNode>(nodes);
            this.Dimensions    = dimensions;
            this.Metric        = metric;

            var points = this.InternalList.Select((p, i) => new CoordinateWithIndex(i, this.PointSelector(p))).ToArray();

            this.GenerateTree(ref this.rootNode, null, 0, points);
        }
コード例 #3
0
 private int GetMaxDistance(IEnumerable<Point> points, CoordinateSelector selector)
 {
     var coordinates = points.Select(p => selector(p)).ToList();
     return coordinates.Max() - coordinates.Min();
 }