public void UnbalancedTreeIsHandledCorrectly() { this.CreateUnbalancedTree(); var competitive = new double[] { 0, 0, 0 }; var nonCompetitive = new double[] { 1, 1, 1 }; var parents = new ParentGenomesConverted(competitive, nonCompetitive); var reachableLeaves = TargetLeafComputation.ComputeReachableTargetLeavesForTree(this.Tree, parents, new Dictionary <int, HashSet <int> >()) .OrderBy(l => l.CurrentNode.Value).ToArray(); Assert.Equal(3, reachableLeaves.Length); for (var i = 0; i < reachableLeaves.Length; i++) { Assert.True(i == reachableLeaves[i].CurrentNode.Value, $"Leaf should have label {i}"); Assert.True(reachableLeaves[i].FixedIndicesInDoubleRepresentation.ContainsKey(0), "First feature should always be fixed"); Assert.False(reachableLeaves[i].FixedIndicesInDoubleRepresentation.ContainsKey(2), "Third feature should never be fixed"); if (i == 0) { Assert.False( reachableLeaves[i].FixedIndicesInDoubleRepresentation.ContainsKey(1), "2nd Feature should not be fixed in first leaf."); } else { Assert.True(reachableLeaves[i].FixedIndicesInDoubleRepresentation.ContainsKey(1), "2nd feature should be fixed in other leaves."); } } }
public void DuplicateFeatureReducesReachableLeavesVersionB() { // This can only produce 2 possible offspring // (Feature 2 is not used for splits!) var competitive = new double[] { 0, 1, 1 }; var nonCompetitive = new double[] { 1, 1, 1 }; var parents = new ParentGenomesConverted(competitive, nonCompetitive); var reachedLeaves = TargetLeafComputation.ComputeReachableTargetLeavesForTree(this.Tree, parents, new Dictionary <int, HashSet <int> >(0)); var orderedResult = reachedLeaves.OrderBy(l => l.CurrentNode.Value).ToArray(); Assert.Equal(2, orderedResult.Length); Assert.Equal(1, orderedResult[0].CurrentNode.Value); Assert.True(orderedResult[0].FixedIndicesInDoubleRepresentation.ContainsKey(0), "Feature 0 should be fixed."); Assert.Equal(TargetLeafGenomeFixation.FixedToCompetitiveParent, orderedResult[0].FixedIndicesInDoubleRepresentation[0]); Assert.False(orderedResult[0].FixedIndicesInDoubleRepresentation.ContainsKey(1), "Feature 1 should not be fixed."); Assert.False(orderedResult[0].FixedIndicesInDoubleRepresentation.ContainsKey(2), "Feature 2 should not be fixed."); Assert.Equal(3, orderedResult[1].CurrentNode.Value); Assert.True(orderedResult[1].FixedIndicesInDoubleRepresentation.ContainsKey(0), "Feature 0 should be fixed."); Assert.Equal(TargetLeafGenomeFixation.FixedToNonCompetitiveParent, orderedResult[1].FixedIndicesInDoubleRepresentation[0]); Assert.False(orderedResult[1].FixedIndicesInDoubleRepresentation.ContainsKey(1), "Feature 1 should not be fixed."); Assert.False(orderedResult[1].FixedIndicesInDoubleRepresentation.ContainsKey(2), "Feature 2 should not be fixed."); }
public void UnbalancedTreeWithDuplicateFeature() { this.CreateUnbalancedTree(); var competitive = new double[] { 0, 0, 0 }; var nonCompetitive = new double[] { 0, 1, 1 }; var parents = new ParentGenomesConverted(competitive, nonCompetitive); var reachableLeaves = TargetLeafComputation.ComputeReachableTargetLeavesForTree(this.Tree, parents, new Dictionary <int, HashSet <int> >()) .OrderBy(l => l.CurrentNode.Value).ToArray(); Assert.Single(reachableLeaves); Assert.Equal(0, reachableLeaves[0].CurrentNode.Value); Assert.Empty(reachableLeaves[0].FixedIndicesInDoubleRepresentation); }
public void DuplicateFeatureReducesReachableLeavesVersionC() { // This can only produce 1 possible offspring // (Feature 2 is not used for splits!) var competitive = new double[] { 0, 1, 0 }; var nonCompetitive = new double[] { 0, 1, 1 }; var parents = new ParentGenomesConverted(competitive, nonCompetitive); var reachedLeaves = TargetLeafComputation.ComputeReachableTargetLeavesForTree(this.Tree, parents, new Dictionary <int, HashSet <int> >(0)); var orderedResult = reachedLeaves.OrderBy(l => l.CurrentNode.Value).ToArray(); Assert.Single(orderedResult); Assert.Equal(1, orderedResult[0].CurrentNode.Value); Assert.Empty(orderedResult[0].FixedIndicesInDoubleRepresentation); }
public void AllTargetLeavesAreFound() { // This can produce 4 possible offspring (Feature 2 is not used for splits!) var competitive = new double[] { 0, 1, 1 }; var nonCompetitive = new double[] { 1, 0, 1 }; var parents = new ParentGenomesConverted(competitive, nonCompetitive); var reachedLeaves = TargetLeafComputation.ComputeReachableTargetLeavesForTree(this.Tree, parents, new Dictionary <int, HashSet <int> >(0)); var orderedResult = reachedLeaves.OrderBy(l => l.CurrentNode.Value).ToArray(); Assert.Equal(this.AllLeaves.Length, orderedResult.Length); for (var reachedLeafIndex = 0; reachedLeafIndex < orderedResult.Length; reachedLeafIndex++) { var reachedLeafAndFixation = orderedResult[reachedLeafIndex]; Assert.Equal( reachedLeafIndex, reachedLeafAndFixation.CurrentNode.Value); Assert.True(reachedLeafAndFixation.FixedIndicesInDoubleRepresentation.ContainsKey(0), "Feature 0 should always be fixed."); Assert.True(reachedLeafAndFixation.FixedIndicesInDoubleRepresentation.ContainsKey(1), "Feature 1 should always be fixed."); Assert.False(reachedLeafAndFixation.FixedIndicesInDoubleRepresentation.ContainsKey(2), "Feature 2 should not be fixed."); } }