double GetSilhouette(Element e) { if (Structuring.HaveUnassignedElements() && Structuring.IsUnassigned(e)) { return(0); } EuclideanDistance ed = new EuclideanDistance(); ed.AttributesToCalculateProximity = Set.Attributes.Values; Cluster actual = Structuring.GetCluster(e)[0]; double ai = ed.CalculateProximity(e, actual.Centroid); double bi = double.MaxValue; foreach (var cluster in Structuring.Clusters.Values) { if (actual.Name != cluster.Name) { double aux = ed.CalculateProximity(e, cluster.Centroid); if (aux < bi) { bi = aux; } } } return((bi - ai) / Math.Max(bi, ai)); }
public void FillHeaps() { if (Set == null) { throw new NullReferenceException("Error conjunto NULL en la Medida Dunn"); } lh = new List <HeapArray <Container> >(Set.ElementsCount); for (int i = 0; i < Set.Elements.Count; i++) { lh.Add(new HeapArray <Container>(Set.Elements.Count - 1));//No se pone la diss de un elemento con el mismo } EuclideanDistance ed = new EuclideanDistance(); ed.AttributesToCalculateProximity = Set.Attributes.Values; for (int i = 0; i < Set.ElementsCount; i++) { for (int j = i + 1; j < Set.ElementsCount; j++) { double distance = ed.CalculateProximity(Set.Elements[i], Set.Elements[j]); lh[i].Add(new Container() { Rank = distance, Name = i, Cluster = j }); lh[j].Add(new Container() { Rank = distance, Name = j, Cluster = i }); } } }
/// <summary> /// /// </summary> /// <returns></returns> public override double EvaluatePartition() { UpdatesCentroids(); EuclideanDistance ed = new EuclideanDistance(); ed.AttributesToCalculateProximity = Set.Attributes.Values; double result = 0; foreach (var cluster in Structuring.Clusters.Values) { foreach (var item in cluster.Elements) { result += ed.CalculateProximity(item, cluster.Centroid); } } return(Math.Sqrt(result / Set.ElementsCount)); }