private static void AddToGroupTable(Hashtable groupTable, CenterInfo cp) { if (groupTable.ContainsKey(cp.Cluster)) { Hashtable methodTable = (Hashtable)groupTable[cp.Cluster]; if (methodTable.ContainsKey(cp.Method)) { // Need a list to maintain the order of points List <CenterInfo> cps = (List <CenterInfo>)methodTable[cp.Method]; cps.Add(cp); } else { // Need a list to maintain the order of points List <CenterInfo> cps = new List <CenterInfo> { cp }; methodTable[cp.Method] = cps; } } else { // Need a list to maintain the order of points List <CenterInfo> cps = new List <CenterInfo> { cp }; Hashtable methodTable = new Hashtable(); methodTable[cp.Method] = cps; groupTable[cp.Cluster] = methodTable; } }
private static Hashtable ProcessCenterFile(string centerFile) { using (StreamReader reader = new StreamReader(centerFile)) { Hashtable groupTable = new Hashtable(); while (!reader.EndOfStream) { CenterInfo cp = ReadCenterLine(reader.ReadLine()); AddToGroupTable(groupTable, cp); } return(groupTable); } }
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); }