private static void clusterizeAndSave(ClusteringMethod <Triplet <Word> > method, Metrica <Triplet <Word> > metrica, int count) { Console.WriteLine("Clustering method " + method.ToString()); Console.WriteLine("Metrica " + metrica.ToString()); var path = "..\\" + method.ToString() + "\\" + metrica.ToString() + "\\"; Directory.CreateDirectory(path); var result = method.clusterize(data, metrica, count); var format = new XmlSerializer(typeof(List <Triplet <Word> >)); var statFormat = new BinaryFormatter(); resultItemsCount = 0; FileStream stream; for (int i = 0; i < result.Count; i++) { resultItemsCount += result[i].Count; var fileName = path + "clustersResult" + i + ".xml"; stream = File.Create(fileName); format.Serialize(stream, result[i]); stream.Close(); var fs = File.OpenWrite(path + "clusterStat" + i + ".txt"); var stat = getStatForCluster(result[i], fs); fs.Close(); } var dataStat = getStatForCluster(data, File.OpenWrite(path + "dataStat.txt")); }
private void ClusteringMethodChanged(object sender, RoutedEventArgs e) { string text = (sender as ComboBox).SelectedValue as string; ClusteringMethod m = (ClusteringMethod)Enum.Parse(typeof(ClusteringMethod), text); (this.DataContext as ViewModel).MyBatchDesignView.BatchDesign.Method = m; (this.DataContext as ViewModel).MyBatchDesignView.DisplayAllClusters(); }
/// <summary> /// Cluster the data set into groups of similar instances. /// </summary> /// <param name="matrix">Input matrix</param> /// <param name="clusteringMethod">Algorithm to use for clustering</param> /// <returns>Results of the cluster analysis</returns> public static IClusteringResults Cluster(this InsightMatrix matrix, ClusteringMethod clusteringMethod) { switch(clusteringMethod) { case ClusteringMethod.KMeans: return new KMeansClustering().Cluster(matrix); default: return new MetaKMeansClustering().Cluster(matrix); } }
/// <summary> /// Cluster the data set into groups of similar instances. /// </summary> /// <param name="matrix">Input matrix</param> /// <param name="clusteringMethod">Algorithm to use for clustering</param> /// <param name="distanceMethod">Distance measure used to compare instances</param> /// <param name="clusters">Number of desired clusters</param> /// <returns>Results of the cluster analysis</returns> public static IClusteringResults Cluster(this InsightMatrix matrix, ClusteringMethod clusteringMethod, DistanceMethod comparisonMethod, int clusters) { switch (clusteringMethod) { case ClusteringMethod.KMeans: return new KMeansClustering().Cluster(matrix, comparisonMethod, clusters); default: return new MetaKMeansClustering().Cluster(matrix, comparisonMethod, clusters); } }
public bool ExportHierarchicalGraph(object ownerViewModel, HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { FileDialogResult result = _dialogService.ShowSaveFileDialog("Export Hierarchical Graph", ownerViewModel, new FileType("PNG image", ".png")); if (result.IsValid) { IBidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> graph = _graphService.GenerateHierarchicalGraph(graphType, clusteringMethod, similarityMetric); Action <double> scaleUpdate = null; FrameworkElement graphLayout = null; switch (graphType) { case HierarchicalGraphType.Dendrogram: graphLayout = new DendrogramLayout { Graph = graph, Background = Brushes.White }; break; case HierarchicalGraphType.Tree: var hgl = new HierarchicalGraphLayout { IsAnimationEnabled = false, CreationTransition = null, DestructionTransition = null, LayoutAlgorithmType = "RadialTree", LayoutParameters = new RadialTreeLayoutParameters { BranchLengthScaling = BranchLengthScaling.MinimizeLabelOverlapMinimum }, Graph = graph, Background = Brushes.White, ScaleLabelsToZoom = 1.0 }; hgl.Resources[typeof(VertexControl)] = System.Windows.Application.Current.Resources["HierarchicalVertexControlStyle"]; hgl.Resources[typeof(EdgeControl)] = System.Windows.Application.Current.Resources["HierarchicalEdgeControlStyle"]; graphLayout = hgl; scaleUpdate = scale => hgl.ScaleLabelsToZoom = scale; break; } Debug.Assert(graphLayout != null); SaveElement(graphLayout, result.FileName, scaleUpdate); return(true); } return(false); }
/// <summary> /// Cluster the data set into groups of similar instances. /// </summary> /// <param name="matrix">Input matrix</param> /// <param name="clusteringMethod">Algorithm to use for clustering</param> /// <param name="distanceMethod">Distance measure used to compare instances</param> /// <param name="clusters">Number of desired clusters</param> /// <param name="iterations">Number of times to run the algorithm</param> /// <returns>Results of the cluster analysis</returns> public static IClusteringResults Cluster(this InsightMatrix matrix, ClusteringMethod clusteringMethod, DistanceMethod comparisonMethod, int clusters, int iterations) { return new MetaKMeansClustering().Cluster(matrix, comparisonMethod, clusters, iterations); }
public IBidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge> GenerateHierarchicalGraph(HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { switch (clusteringMethod) { case ClusteringMethod.Upgma: Func<Variety, Variety, double> upgmaGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var upgma = new UpgmaClusterer<Variety>(upgmaGetDistance); IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> upgmaTree = upgma.GenerateClusters(_projectService.Project.Varieties); return BuildHierarchicalGraph(upgmaTree); case ClusteringMethod.NeighborJoining: Func<Variety, Variety, double> njGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var nj = new NeighborJoiningClusterer<Variety>(njGetDistance); IUndirectedGraph<Cluster<Variety>, ClusterEdge<Variety>> njTree = nj.GenerateClusters(_projectService.Project.Varieties); switch (graphType) { case HierarchicalGraphType.Dendrogram: IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> rootedTree = njTree.ToRootedTree(); return BuildHierarchicalGraph(rootedTree); case HierarchicalGraphType.Tree: return BuildHierarchicalGraph(njTree); } break; } return null; }
public IBidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> GenerateHierarchicalGraph(HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { switch (clusteringMethod) { case ClusteringMethod.Upgma: Func <Variety, Variety, double> upgmaGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var upgma = new UpgmaClusterer <Variety>(upgmaGetDistance); IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > upgmaTree = upgma.GenerateClusters(_projectService.Project.Varieties); return(BuildHierarchicalGraph(upgmaTree)); case ClusteringMethod.NeighborJoining: Func <Variety, Variety, double> njGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var nj = new NeighborJoiningClusterer <Variety>(njGetDistance); IUndirectedGraph <Cluster <Variety>, ClusterEdge <Variety> > njTree = nj.GenerateClusters(_projectService.Project.Varieties); switch (graphType) { case HierarchicalGraphType.Dendrogram: IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > rootedTree = njTree.ToRootedTree(); return(BuildHierarchicalGraph(rootedTree)); case HierarchicalGraphType.Tree: return(BuildHierarchicalGraph(njTree)); } break; } return(null); }