public void TestVITwoTokens() { var n1 = new SimpleNode() { Name = new[] { "n", "Yellow" } }; var n2 = new SimpleNode() { Name = new[] { "n", "Red" } }; var n3 = new SimpleNode() { Name = new[] { "n", "Yellow" } }; var b1 = new SimpleNode() { Name = new[] { "b", } }; var b2 = new SimpleNode() { Name = new[] { "b", } }; var b3 = new SimpleNode() { Name = new[] { "b", } }; var root = new SimpleNode() { Name = new[] { "root" } }; var rels = new Dictionary <SimpleNode, HashSet <SimpleNode> >() { { n1, new HashSet <SimpleNode>() { n2, n3 } }, { n2, new HashSet <SimpleNode>() { n3 } }, { n3, new HashSet <SimpleNode>() }, { b1, new HashSet <SimpleNode>() { b2 } }, { b2, new HashSet <SimpleNode>() { b3 } }, { b3, new HashSet <SimpleNode>() }, { root, new HashSet <SimpleNode>() { n1, b1 } }, }; var viLattice = new MockVariationOfInformationColoredLattice(); var nodeMap = viLattice.Add(rels, n => new NodeName(n.Name)); viLattice.CacheInfo(); var grouping1 = new List <HashSet <LatticeNode <NodeName> > >() { new HashSet <LatticeNode <NodeName> >() { nodeMap[n1], nodeMap[n2], nodeMap[n3], nodeMap[b1], nodeMap[b2], nodeMap[b3], nodeMap[root] } }; var viAllTogether = viLattice.ComputeVariationOfInformation(grouping1); var grouping2 = new List <HashSet <LatticeNode <NodeName> > >() { new HashSet <LatticeNode <NodeName> >() { nodeMap[n1], nodeMap[n2], nodeMap[n3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[b1], nodeMap[b2], nodeMap[b3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[root] } }; var viSplit = viLattice.ComputeVariationOfInformation(grouping2); Assert.IsTrue(viSplit < viAllTogether); var groupingSpurious = new List <HashSet <LatticeNode <NodeName> > >() { new HashSet <LatticeNode <NodeName> >() { nodeMap[n1], nodeMap[n2] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[n3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[b1], nodeMap[b2], nodeMap[b3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[root] } }; var viSpuriousSplit = viLattice.ComputeVariationOfInformation(groupingSpurious); Assert.IsTrue(viSplit < viSpuriousSplit); var grouping3 = new List <HashSet <LatticeNode <NodeName> > >() { new HashSet <LatticeNode <NodeName> >() { nodeMap[n1], nodeMap[b1] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[n2], nodeMap[b2] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[n3], nodeMap[b3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[root] } }; var viSplitWeird = viLattice.ComputeVariationOfInformation(grouping3); Assert.IsTrue(viSplit < viSplitWeird, "{0}<{1}", viSplit, viSplitWeird); var grouping4 = new List <HashSet <LatticeNode <NodeName> > >() { new HashSet <LatticeNode <NodeName> >() { nodeMap[n1] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[n2], }, new HashSet <LatticeNode <NodeName> >() { nodeMap[n3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[b1] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[b2] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[b3] }, new HashSet <LatticeNode <NodeName> >() { nodeMap[root] } }; var viSplitTooMuch2 = viLattice.ComputeVariationOfInformation(grouping4); Assert.IsTrue(viSplit < viSplitTooMuch2); }
public void TestSimpleVeeSplit() { var n1 = new SimpleNode() { Name = new[] { "n", "Yellow" } }; var n2 = new SimpleNode() { Name = new[] { "n", "Red" } }; var n3 = new SimpleNode() { Name = new[] { "n", "Yellow" } }; var b1 = new SimpleNode() { Name = new[] { "b", } }; var b2 = new SimpleNode() { Name = new[] { "b", } }; var b3 = new SimpleNode() { Name = new[] { "b", } }; var root = new SimpleNode() { Name = new[] { "root" } }; var rels = new Dictionary <SimpleNode, HashSet <SimpleNode> >() { { n1, new HashSet <SimpleNode>() { n2, n3 } }, { n2, new HashSet <SimpleNode>() { n3 } }, { n3, new HashSet <SimpleNode>() }, { b1, new HashSet <SimpleNode>() { b2 } }, { b2, new HashSet <SimpleNode>() { b3 } }, { b3, new HashSet <SimpleNode>() }, { root, new HashSet <SimpleNode>() { n1, b1 } }, }; var viLattice = new MockVariationOfInformationColoredLattice(); var nodeMap = viLattice.Add(rels, n => new NodeName(n.Name)); var singleGroupParents = new HashSet <LatticeNode <NodeName> >() { nodeMap[root] }; var typeGroup = new HashSet <LatticeNode <NodeName> >() { nodeMap[n1], nodeMap[n2], nodeMap[n3], nodeMap[b1], nodeMap[b2], nodeMap[b3], nodeMap[root] }; var split = SplitClusterOnNode.SplitOn(typeGroup, singleGroupParents, nodeMap[b1]); Assert.AreEqual(split.Before.Count, 1); Assert.AreEqual(split.BeforeParent.Count, 1); Assert.AreEqual(split.Before[0], typeGroup); Assert.AreEqual(split.BeforeParent[0], singleGroupParents); viLattice.AssertColoringValid(split.Before, split.BeforeParent); var parentsAsHashSet = new HashSet <LatticeNode <NodeName> >(split.AfterParents.SelectMany(n => n)); Assert.IsTrue(parentsAsHashSet.Contains(nodeMap[root])); Assert.IsTrue(parentsAsHashSet.Contains(nodeMap[b1])); Assert.IsTrue(split.After[0].Contains(nodeMap[root])); Assert.IsTrue(split.After[0].Contains(nodeMap[n1])); Assert.IsTrue(split.After[0].Contains(nodeMap[n2])); Assert.IsTrue(split.After[0].Contains(nodeMap[n3])); Assert.IsTrue(split.After[1].Contains(nodeMap[b1])); Assert.IsTrue(split.After[1].Contains(nodeMap[b2])); Assert.IsTrue(split.After[1].Contains(nodeMap[b3])); viLattice.AssertColoringValid(split.After, split.AfterParents); split = SplitClusterOnNode.SplitOn(typeGroup, singleGroupParents, nodeMap[b2]); Assert.AreEqual(split.Before.Count, 1); Assert.AreEqual(split.BeforeParent.Count, 1); Assert.AreEqual(split.Before[0], typeGroup); Assert.AreEqual(split.BeforeParent[0], singleGroupParents); parentsAsHashSet = new HashSet <LatticeNode <NodeName> >(split.AfterParents.SelectMany(n => n)); Assert.IsTrue(parentsAsHashSet.Contains(nodeMap[root])); Assert.IsTrue(parentsAsHashSet.Contains(nodeMap[b2])); Assert.IsTrue(split.After[0].Contains(nodeMap[root])); Assert.IsTrue(split.After[0].Contains(nodeMap[n1])); Assert.IsTrue(split.After[0].Contains(nodeMap[n2])); Assert.IsTrue(split.After[0].Contains(nodeMap[n3])); Assert.IsTrue(split.After[0].Contains(nodeMap[b1])); Assert.IsTrue(split.After[1].Contains(nodeMap[b2])); Assert.IsTrue(split.After[1].Contains(nodeMap[b3])); viLattice.AssertColoringValid(split.After, split.AfterParents); split = SplitClusterOnNode.SplitOn(typeGroup, singleGroupParents, nodeMap[n1]); Assert.AreEqual(split.Before.Count, 1); Assert.AreEqual(split.BeforeParent.Count, 1); Assert.AreEqual(split.Before[0], typeGroup); Assert.AreEqual(split.BeforeParent[0], singleGroupParents); parentsAsHashSet = new HashSet <LatticeNode <NodeName> >(split.AfterParents.SelectMany(n => n)); Assert.IsTrue(parentsAsHashSet.Contains(nodeMap[root])); Assert.IsTrue(parentsAsHashSet.Contains(nodeMap[n1])); Assert.IsTrue(split.After[0].Contains(nodeMap[root])); Assert.IsTrue(split.After[0].Contains(nodeMap[b1])); Assert.IsTrue(split.After[0].Contains(nodeMap[b2])); Assert.IsTrue(split.After[0].Contains(nodeMap[b3])); Assert.IsTrue(split.After[1].Contains(nodeMap[n1])); Assert.IsTrue(split.After[1].Contains(nodeMap[n2])); Assert.IsTrue(split.After[1].Contains(nodeMap[n3])); viLattice.AssertColoringValid(split.After, split.AfterParents); }