private static void ProcessPointsFile(string pointsFile, string clusterNumberFile, XElement clusters, XElement points, out int maxpnum, out int maxcnum, Hashtable pointsTable, List <Color> matlab50Colors) { using (StreamReader preader = new StreamReader(pointsFile), creader = new StreamReader(clusterNumberFile)) { HashSet <int> clusterNumbers = new HashSet <int>(); maxpnum = -1; while (!preader.EndOfStream) { string pline = preader.ReadLine(); string cline = creader.ReadLine(); if (!string.IsNullOrEmpty(pline) && !string.IsNullOrEmpty(cline)) { PlotVizPoint p = ReadPointLine(pline.Trim()); if (maxpnum < p.Index) { maxpnum = p.Index; } pointsTable.Add(p.Index, p); int cnum = ReadCnum(cline); p.Cluster = cnum; if (!clusterNumbers.Contains(p.Cluster)) { clusterNumbers.Add(p.Cluster); clusters.Add(CreateClusterElement(p.Cluster, p.Cluster.ToString(CultureInfo.InvariantCulture), matlab50Colors[p.Cluster % matlab50Colors.Count], true, 0.1, Glyphs.Hexagon2D)); } points.Add(CreatePointElement(p.Index, p.Cluster, string.Empty, p.X, p.Y, p.Z)); } } maxcnum = clusterNumbers.Max(); } }
private static PlotVizPoint ReadPointLine(string line) { char[] sep = new[] { ' ', '\t' }; string[] splits = line.Split(sep, StringSplitOptions.RemoveEmptyEntries); PlotVizPoint p = new PlotVizPoint(double.Parse(splits[1]), double.Parse(splits[2]), double.Parse(splits[3]), int.Parse(splits[0]), int.Parse(splits[4])); return(p); }
private static void CreatePlotWithCentersInternal(string centerPlotFile, string plotDescription, XElement clustersElement, XElement pointsElement, int maxpnum, Hashtable existingPointsTable, int maxcnum, List <Color> matlab50Colors, Hashtable groupTable, int numberOfCenterPointsToIncludeInEachCenterType) { ++maxcnum; foreach (DictionaryEntry groupToMethodTable in groupTable) { var group = (int)groupToMethodTable.Key; // group is the original cluster number var methodTable = (Hashtable)groupToMethodTable.Value; int methodCount = methodTable.Count; int tempCount = methodCount; foreach (DictionaryEntry methodToCenterPoints in methodTable) { var method = (string)methodToCenterPoints.Key; // method is one of smallest distance mean, smallest MDS mean, etc. // cluster number to be used in PlotViz for this center type int methodNumber = methodCount - tempCount--; var clusterNumberForCenterType = group * methodCount + methodNumber + maxcnum; // cluster name to be used in PlotViz for this center type var centerTypeName = group + "." + method + ".centerpoints"; // add an XML element to represent this center type as a cluster in PlotViz clustersElement.Add(CreateClusterElement(clusterNumberForCenterType, centerTypeName, matlab50Colors[group % matlab50Colors.Count], false, 2.0, methodNumber)); var cps = (List <CenterInfo>)methodToCenterPoints.Value; // Picking the topmost n point for each method for (int i = 0; i < numberOfCenterPointsToIncludeInEachCenterType; i++) { CenterInfo cp = cps[i]; PlotVizPoint p = (PlotVizPoint)existingPointsTable[cp.Pnum]; pointsElement.Add(CreatePointElement(++maxpnum, clusterNumberForCenterType, ("cluster:" + group + "-idx:" + p.Index + "method:" + method), p.X, p.Y, p.Z)); } } } XElement plotElement = CreatePlotElement(plotDescription, true); XElement plotvizElement = new XElement("plotviz"); plotvizElement.Add(plotElement); plotvizElement.Add(clustersElement); plotvizElement.Add(pointsElement); plotvizElement.Save(centerPlotFile); }