Example #1
0
 private static void ProcessPointsFile(string pointsFile, XElement clusters, XElement points, out int maxpnum, out int maxcnum, Hashtable pointsTable, List <Color> matlab50Colors)
 {
     using (StreamReader reader = new StreamReader(pointsFile))
     {
         HashSet <int> clusterNumbers = new HashSet <int>();
         maxpnum = -1;
         while (!reader.EndOfStream)
         {
             string line = reader.ReadLine();
             if (!string.IsNullOrEmpty(line))
             {
                 PlotVizPoint p = ReadPointLine(line.Trim());
                 if (maxpnum < p.Index)
                 {
                     maxpnum = p.Index;
                 }
                 pointsTable.Add(p.Index, p);
                 if (!clusterNumbers.Contains(p.Cluster))
                 {
                     clusterNumbers.Add(p.Cluster);
                     clusters.Add(CreateClusterElement(p.Cluster,
                                                       p.Cluster.ToString(CultureInfo.InvariantCulture),
                                                       matlab50Colors[p.Cluster % matlab50Colors.Count], false, 0.1));
                 }
                 points.Add(CreatePointElement(p.Index, p.Cluster, string.Empty, p.X, p.Y, p.Z));
             }
         }
         maxcnum = clusterNumbers.Max();
     }
 }
Example #2
0
        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);
        }
Example #3
0
        private static void CreatePlotWithCenters(string outDir, string outNamePrefix, 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
                    var clusterNumberForCenterType = group * methodCount + (methodCount - tempCount--) + 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));

                    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));
                    }
                }
            }

            string   pvizName       = outNamePrefix + "_with_" + numberOfCenterPointsToIncludeInEachCenterType + "_center(s)_for_each_center_type";
            XElement plotElement    = CreatePlotElement(pvizName, true);
            XElement plotvizElement = new XElement("plotviz");

            plotvizElement.Add(plotElement);
            plotvizElement.Add(clustersElement);
            plotvizElement.Add(pointsElement);
            string pvizFile = Path.Combine(outDir, pvizName + ".pviz");

            plotvizElement.Save(pvizFile);
        }