public WindowToDraw(DataClustering clustering) { InitializeComponent(); dataClustering = clustering; SetTitle(); DrawStart(); DrawPoints(); DrawFinish(); }
void DrawPoints() { List <GeometryDrawing> pointsDrawingList = new List <GeometryDrawing>(); List <GeometryGroup> pointsGeometryList = new List <GeometryGroup>(); foreach (Cluster cluster in dataClustering.Clusters) { if (cluster.ColorOnChart == Colors.White) { cluster.SetColor(); } foreach (DataPoint point in cluster.Points) { point.ChartPoint = ToChartPoint(point); } } int listcounter = 0; foreach (Cluster cluster in dataClustering.Clusters) { pointsDrawingList.Add(new GeometryDrawing()); pointsGeometryList.Add(new GeometryGroup()); foreach (DataPoint point in cluster.Points) { pointsGeometryList[listcounter].Children.Add(new EllipseGeometry(point.ChartPoint, 3, 3)); } pointsDrawingList[listcounter].Geometry = pointsGeometryList[listcounter]; pointsDrawingList[listcounter].Brush = new SolidColorBrush(cluster.ColorOnChart); pointsDrawingList[listcounter].Pen = new Pen(Brushes.Black, 1); pointsDrawingList[listcounter].Freeze(); drawingGroup.Children.Add(pointsDrawingList[listcounter]); listcounter++; } //centroidy DataClustering tmp = dataClustering as KMeans; if (tmp != null) { pointsDrawingList.Add(new GeometryDrawing()); pointsGeometryList.Add(new GeometryGroup()); foreach (Cluster cluster in dataClustering.Clusters) { cluster.Centroid.ChartPoint = ToChartPoint(cluster.Centroid); pointsGeometryList[listcounter].Children.Add(new LineGeometry(new Point(cluster.Centroid.ChartPoint.X - 5, cluster.Centroid.ChartPoint.Y - 5), new Point(cluster.Centroid.ChartPoint.X + 5, cluster.Centroid.ChartPoint.Y + 5))); pointsGeometryList[listcounter].Children.Add(new LineGeometry(new Point(cluster.Centroid.ChartPoint.X - 5, cluster.Centroid.ChartPoint.Y + 5), new Point(cluster.Centroid.ChartPoint.X + 5, cluster.Centroid.ChartPoint.Y - 5))); } pointsDrawingList[listcounter].Geometry = pointsGeometryList[listcounter]; pointsDrawingList[listcounter].Brush = new SolidColorBrush(Colors.Black); pointsDrawingList[listcounter].Pen = new Pen(Brushes.Black, 1); drawingGroup.Children.Add(pointsDrawingList[listcounter]); } }
private void NextStepButton_Click(object sender, RoutedEventArgs e) { if (!dataClustering.Finished) { dataClustering.ClusteringStep(); DataClustering hierarchical = dataClustering as Hierarchical; //if (hierarchical != null) //WriteToFile.Algorithm(dataClustering); DrawAndDisplay(); } //if (dataClustering.Finished) //{ // NextStepButton.Visibility = Visibility.Collapsed; // SkipButton.Visibility = Visibility.Collapsed; //} }
void DrawStart() { MyColors.Counter = 0; GeometryGroup coordinates = new GeometryGroup(); coordinates.Children.Add(new LineGeometry(new Point(0, 600), new Point(620, 600))); coordinates.Children.Add(new LineGeometry(new Point(20, 0), new Point(20, 620))); coordinates.Children.Add(new LineGeometry(new Point(620, 600), new Point(615, 595))); coordinates.Children.Add(new LineGeometry(new Point(620, 600), new Point(615, 605))); coordinates.Children.Add(new LineGeometry(new Point(20, 0), new Point(25, 5))); coordinates.Children.Add(new LineGeometry(new Point(20, 0), new Point(15, 5))); Point from, to; for (int i = 0; i < 600; i += 25) { from = ToChartPoint(-5, i); to = ToChartPoint(0, i); coordinates.Children.Add(new LineGeometry(from, to)); from = ToChartPoint(i, 0); to = ToChartPoint(i, -5); coordinates.Children.Add(new LineGeometry(from, to)); } coordinatesDrawing.Geometry = coordinates; coordinatesDrawing.Brush = new SolidColorBrush(Colors.Black); coordinatesDrawing.Pen = new Pen(Brushes.Black, 1); coordinatesDrawing.Freeze(); drawingGroup.Children.Add(coordinatesDrawing); DataClustering data = dataClustering as Hierarchical; if (data == null) { SkipButton.Visibility = Visibility.Collapsed; HowManyToSkipTextBox.Visibility = Visibility.Collapsed; } }
public static void Algorithm(DataClustering clustering) { DataClustering[] algorithms = { clustering as KMeans, clustering as JarvisPatrick, clustering as SingleLinkageHierarchical, clustering as AverageLinkageHierarchical, clustering as CompleteLinkageHierarchical, clustering as Hierarchical }; using (StreamWriter sw = File.AppendText(Path)) { if (algorithms[0] != null) { sw.WriteLine("Algorytm k-średnich"); } else if (algorithms[1] != null) { sw.WriteLine("Algorytm Jarvisa-Patricka"); } else if (algorithms[1] != null) { sw.WriteLine("Algorytm hierarchiczny aglomeracyjny z miarą odległości single-linkage"); } else if (algorithms[1] != null) { sw.WriteLine("Algorytm hierarchiczny aglomeracyjny z miarą odległości average-linkage"); } else { sw.WriteLine("Algorytm hierarchiczny aglomeracyjny z miarą odległości complete-linkage"); } int index = 0; if (algorithms[5] == null) { foreach (Cluster cluster in clustering.Clusters) { sw.WriteLine("Cluster {0}:", index++); if (algorithms[0] != null) { sw.Write("Centroid: "); foreach (double number in cluster.Centroid.Coordinates) { sw.Write("{0} ", number); } sw.WriteLine(); } sw.Write("Points:"); foreach (DataPoint point in cluster.Points) { sw.Write("[{0}] ", point.Index); } sw.WriteLine(); } } else { int iterCounter = 0; Hierarchical hierarchical = (Hierarchical)clustering; foreach (List <Cluster> list in hierarchical.clusterHistory) { sw.WriteLine("Iteracja: {0}", iterCounter); foreach (Cluster cluster in list) { sw.WriteLine("Cluster {0}:", index++); sw.Write("Points:"); foreach (DataPoint point in cluster.Points) { sw.Write("[{0}] ", point.Index); } sw.WriteLine(); } sw.WriteLine(); index = 0; iterCounter++; } } sw.WriteLine(); sw.WriteLine(); } }