예제 #1
0
        public void ClusterNoDataObjects()
        {
            var upgma = new UpgmaClusterer <char>((o1, o2) => 0);
            IBidirectionalGraph <Cluster <char>, ClusterEdge <char> > tree = upgma.GenerateClusters(Enumerable.Empty <char>());

            Assert.That(tree.IsEdgesEmpty);
        }
예제 #2
0
 public void ClusterOneDataObject()
 {
     var upgma = new UpgmaClusterer<char>((o1, o2) => 0);
     IBidirectionalGraph<Cluster<char>, ClusterEdge<char>> tree = upgma.GenerateClusters(new[] {'A'});
     Assert.That(tree.VertexCount, Is.EqualTo(1));
     Assert.That(tree.IsEdgesEmpty);
 }
예제 #3
0
        public void ClusterTwoDataObjects()
        {
            var upgma = new UpgmaClusterer <char>((o1, o2) => 1);
            IBidirectionalGraph <Cluster <char>, ClusterEdge <char> > tree = upgma.GenerateClusters(new[] { 'A', 'B' });

            var vertices = new Dictionary <string, Cluster <char> >
            {
                { "root", new Cluster <char> {
                      Description = "root"
                  } },
                { "A", new Cluster <char>('A')
                  {
                      Description = "A"
                  } },
                { "B", new Cluster <char>('B')
                  {
                      Description = "B"
                  } }
            };

            var edges = new[]
            {
                new ClusterEdge <char>(vertices["root"], vertices["A"], 0.5),
                new ClusterEdge <char>(vertices["root"], vertices["B"], 0.5)
            };

            AssertTreeEqual(tree, edges.ToBidirectionalGraph <Cluster <char>, ClusterEdge <char> >());
        }
예제 #4
0
        public void ClusterOneDataObject()
        {
            var upgma = new UpgmaClusterer <char>((o1, o2) => 0);
            IBidirectionalGraph <Cluster <char>, ClusterEdge <char> > tree = upgma.GenerateClusters(new[] { 'A' });

            Assert.That(tree.VertexCount, Is.EqualTo(1));
            Assert.That(tree.IsEdgesEmpty);
        }
예제 #5
0
        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);
        }
예제 #6
0
        public void Cluster()
        {
            var matrix = new double[,]
                {
                    {0, 2, 4, 6, 6, 8},
                    {2, 0, 4, 6, 6, 8},
                    {4, 4, 0, 6, 6, 8},
                    {6, 6, 6, 0, 4, 8},
                    {6, 6, 6, 4, 0, 8},
                    {8, 8, 8, 8, 8, 0}
                };
            var upgma = new UpgmaClusterer<char>((o1, o2) => matrix[o1 - 'A', o2 - 'A']);
            IBidirectionalGraph<Cluster<char>, ClusterEdge<char>> tree = upgma.GenerateClusters(new[] {'A', 'B', 'C', 'D', 'E', 'F'});

            var vertices = new Dictionary<string, Cluster<char>>
                {
                    {"root", new Cluster<char> {Description = "root"}},
                    {"A", new Cluster<char>('A') {Description = "A"}},
                    {"B", new Cluster<char>('B') {Description = "B"}},
                    {"C", new Cluster<char>('C') {Description = "C"}},
                    {"D", new Cluster<char>('D') {Description = "D"}},
                    {"E", new Cluster<char>('E') {Description = "E"}},
                    {"F", new Cluster<char>('F') {Description = "F"}},
                    {"ABCDE", new Cluster<char> {Description = "ABCDE"}},
                    {"ABC", new Cluster<char> {Description = "ABC"}},
                    {"AB", new Cluster<char> {Description = "AB"}},
                    {"DE", new Cluster<char> {Description = "DE"}}
                };

            var edges = new[]
                {
                    new ClusterEdge<char>(vertices["root"], vertices["ABCDE"], 1),
                    new ClusterEdge<char>(vertices["root"], vertices["F"], 4),
                    new ClusterEdge<char>(vertices["ABCDE"], vertices["ABC"], 1),
                    new ClusterEdge<char>(vertices["ABCDE"], vertices["DE"], 1),
                    new ClusterEdge<char>(vertices["ABC"], vertices["AB"], 1),
                    new ClusterEdge<char>(vertices["ABC"], vertices["C"], 2),
                    new ClusterEdge<char>(vertices["AB"], vertices["A"], 1),
                    new ClusterEdge<char>(vertices["AB"], vertices["B"], 1),
                    new ClusterEdge<char>(vertices["DE"], vertices["D"], 2),
                    new ClusterEdge<char>(vertices["DE"], vertices["E"], 2)
                };
            AssertTreeEqual(tree, edges.ToBidirectionalGraph<Cluster<char>, ClusterEdge<char>>());
        }
예제 #7
0
        public void ClusterTwoDataObjects()
        {
            var upgma = new UpgmaClusterer<char>((o1, o2) => 1);
            IBidirectionalGraph<Cluster<char>, ClusterEdge<char>> tree = upgma.GenerateClusters(new[] {'A', 'B'});

            var vertices = new Dictionary<string, Cluster<char>>
                {
                    {"root", new Cluster<char> {Description = "root"}},
                    {"A", new Cluster<char>('A') {Description = "A"}},
                    {"B", new Cluster<char>('B') {Description = "B"}}
                };

            var edges = new[]
                {
                    new ClusterEdge<char>(vertices["root"], vertices["A"], 0.5),
                    new ClusterEdge<char>(vertices["root"], vertices["B"], 0.5)
                };

            AssertTreeEqual(tree, edges.ToBidirectionalGraph<Cluster<char>, ClusterEdge<char>>());
        }
예제 #8
0
 public void ClusterNoDataObjects()
 {
     var upgma = new UpgmaClusterer<char>((o1, o2) => 0);
     IBidirectionalGraph<Cluster<char>, ClusterEdge<char>> tree = upgma.GenerateClusters(Enumerable.Empty<char>());
     Assert.That(tree.IsEdgesEmpty);
 }
예제 #9
0
        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;
        }
예제 #10
0
        public void Cluster()
        {
            var matrix = new double[, ]
            {
                { 0, 2, 4, 6, 6, 8 },
                { 2, 0, 4, 6, 6, 8 },
                { 4, 4, 0, 6, 6, 8 },
                { 6, 6, 6, 0, 4, 8 },
                { 6, 6, 6, 4, 0, 8 },
                { 8, 8, 8, 8, 8, 0 }
            };
            var upgma = new UpgmaClusterer <char>((o1, o2) => matrix[o1 - 'A', o2 - 'A']);
            IBidirectionalGraph <Cluster <char>, ClusterEdge <char> > tree = upgma.GenerateClusters(new[] { 'A', 'B', 'C', 'D', 'E', 'F' });

            var vertices = new Dictionary <string, Cluster <char> >
            {
                { "root", new Cluster <char> {
                      Description = "root"
                  } },
                { "A", new Cluster <char>('A')
                  {
                      Description = "A"
                  } },
                { "B", new Cluster <char>('B')
                  {
                      Description = "B"
                  } },
                { "C", new Cluster <char>('C')
                  {
                      Description = "C"
                  } },
                { "D", new Cluster <char>('D')
                  {
                      Description = "D"
                  } },
                { "E", new Cluster <char>('E')
                  {
                      Description = "E"
                  } },
                { "F", new Cluster <char>('F')
                  {
                      Description = "F"
                  } },
                { "ABCDE", new Cluster <char> {
                      Description = "ABCDE"
                  } },
                { "ABC", new Cluster <char> {
                      Description = "ABC"
                  } },
                { "AB", new Cluster <char> {
                      Description = "AB"
                  } },
                { "DE", new Cluster <char> {
                      Description = "DE"
                  } }
            };

            var edges = new[]
            {
                new ClusterEdge <char>(vertices["root"], vertices["ABCDE"], 1),
                new ClusterEdge <char>(vertices["root"], vertices["F"], 4),
                new ClusterEdge <char>(vertices["ABCDE"], vertices["ABC"], 1),
                new ClusterEdge <char>(vertices["ABCDE"], vertices["DE"], 1),
                new ClusterEdge <char>(vertices["ABC"], vertices["AB"], 1),
                new ClusterEdge <char>(vertices["ABC"], vertices["C"], 2),
                new ClusterEdge <char>(vertices["AB"], vertices["A"], 1),
                new ClusterEdge <char>(vertices["AB"], vertices["B"], 1),
                new ClusterEdge <char>(vertices["DE"], vertices["D"], 2),
                new ClusterEdge <char>(vertices["DE"], vertices["E"], 2)
            };

            AssertTreeEqual(tree, edges.ToBidirectionalGraph <Cluster <char>, ClusterEdge <char> >());
        }