Beispiel #1
0
        public DendrogramForm(Dendrogram dendrogram)
        {
            InitializeComponent();

            foreach (TreeNode node in GetTree(dendrogram).Nodes)
            {
                this.treeView1.Nodes.Add(node);
            }
        }
Beispiel #2
0
 private TreeNode GetTree(Dendrogram dendrogram)
 {
     if (dendrogram is LeafNode)
     {
         return(new TreeNode(((LeafNode)dendrogram).Place.name));
     }
     else
     {
         TreeNode toRet = new TreeNode();
         toRet.Nodes.Add(GetTree(((InternalNode)dendrogram).Child1));
         toRet.Nodes.Add(GetTree(((InternalNode)dendrogram).Child2));
         toRet.Text = dendrogram.Name;
         return(toRet);
     }
 }
Beispiel #3
0
        public List <Place> FitTrnaform(List <Place> places, DistanceMetric metric)
        {
            List <Dendrogram> tempDendrograms = places.Select(place => new LeafNode(place)).ToList().ConvertAll(leaf => (Dendrogram)leaf);

            while (tempDendrograms.Count > 1)
            {
                double     minDist = double.MaxValue;
                Dendrogram minDend1 = null, minDend2 = null;
                foreach (Dendrogram dend1 in tempDendrograms)
                {
                    foreach (Dendrogram dend2 in tempDendrograms)
                    {
                        if (dend1 == dend2)
                        {
                            continue;
                        }
                        double tempDist = dend1.DistanceTo(dend2, metric);
                        if (tempDist < minDist)
                        {
                            minDist  = tempDist;
                            minDend1 = dend1;
                            minDend2 = dend2;
                        }
                    }
                }

                if (minDend1 is LeafNode)
                {
                    this.placesByRemoteness.Add(minDend1.Places[0]);
                }
                if (minDend2 is LeafNode)
                {
                    this.placesByRemoteness.Add(minDend2.Places[0]);
                }

                Dendrogram combinedDend = new InternalNode(minDend1, minDend2, minDist);
                tempDendrograms.Remove(minDend1);
                tempDendrograms.Remove(minDend2);
                tempDendrograms.Add(combinedDend);
            }
            this.Dendrogram = tempDendrograms[0];
            this.placesByRemoteness.Reverse();
            return(this.placesByRemoteness);
        }
Beispiel #4
0
 public abstract double DistanceTo(Dendrogram dst, DistanceMetric metric);
Beispiel #5
0
        public override double DistanceTo(Dendrogram dst, DistanceMetric metric)
        {
            // check if the requested calculation was computed previously
            if (distCache.ContainsKey(dst))
            {
                return(distCache[dst]);
            }

            double toRet;

            if (metric == DistanceMetric.SingleLink)
            {
                double minDist = double.MaxValue;
                foreach (Place srcPlace in this.Places)
                {
                    foreach (Place dstPlace in dst.Places)
                    {
                        double distance = srcPlace.DistanceTo(dstPlace);
                        if (distance < minDist)
                        {
                            minDist = distance;
                        }
                    }
                }
                toRet = minDist;
            }
            else if (metric == DistanceMetric.CompleteLink)
            {
                double maxDist = double.MinValue;
                foreach (Place srcPlace in this.Places)
                {
                    foreach (Place dstPlace in dst.Places)
                    {
                        double distance = srcPlace.DistanceTo(dstPlace);
                        if (distance > maxDist)
                        {
                            maxDist = distance;
                        }
                    }
                }
                toRet = maxDist;
            }
            else if (metric == DistanceMetric.AverageLink)
            {
                double distsSum = 0;
                foreach (Place srcPlace in this.Places)
                {
                    foreach (Place dstPlace in dst.Places)
                    {
                        distsSum += srcPlace.DistanceTo(dstPlace);
                    }
                }
                toRet = distsSum / (this.Places.Count * dst.Places.Count);
            }
            else if (metric == DistanceMetric.CentroidToCentroid)
            {
                toRet = this.Centroid.GetDistanceTo(dst.Centroid);
            }
            else
            {
                throw new NotImplementedException();
            }

            distCache.Add(dst, toRet);
            return(toRet);
        }
Beispiel #6
0
 public InternalNode(Dendrogram child1, Dendrogram child2, double distance)
 {
     this.Child1   = child1;
     this.Child2   = child2;
     this.Distance = distance;
 }