Skip to content

Commit

Permalink
fix the bug in CalibratedYule #497
Browse files Browse the repository at this point in the history
  • Loading branch information
EvaLiyt committed Aug 14, 2024
1 parent 148e0dd commit 70a5157
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private void coalesce(double lambda, double t) {
// if there is only one node in activeNodes and is not from inactiveNodes
// then add the youngest node from inactiveNodes to activeNodes
if (activeNodes.size() == 1 && !activeNodes.contains(getYoungestNode(inactiveNodes))) {
t = getYoungestNode(inactiveNodes).getAge();
activeNodes.add(getYoungestNode(inactiveNodes));
inactiveNodes.remove(getYoungestNode(inactiveNodes));
t = getYoungestNode(inactiveNodes).getAge();
}
}
} else coalesceNodes(activeNodes, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,28 @@ void test3() { // test same clade names
assert observe.getRoot().getAllLeafNodes().stream().anyMatch(node -> node.getId().equals("clade1_taxa3"));
assert observe.getRoot().getAllLeafNodes().stream().anyMatch(node -> node.getId().equals("clade0_taxa10"));
}

@Test
void coalesceTest() {
double birthRate = 0.1;
int n = 20;
String[] taxa = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
Number[] cladeAge = new Number[]{29};

Value<Number> birthRateValue = new Value<>("birthRate", birthRate);
Value<Integer> nValue = new Value<>("n", n);
Value taxaValue = new Value("taxa", taxa);
Value<Number[]> cladeAgeValue = new Value<>("cladeAge", cladeAge);
Value<Number> rootAgeValue = new Value<>("rootAge", 31);

CalibratedYule instance = new CalibratedYule(birthRateValue, nValue, taxaValue, cladeAgeValue, null, rootAgeValue);
TimeTree observe = instance.sample().value();

// node number should be same
assertEquals(n , observe.getRoot().getAllLeafNodes().size());
// randomly check the names for clade taxa
assert observe.getRoot().getAllLeafNodes().stream().anyMatch(node -> node.getId().equals("clade_1"));
assert observe.getRoot().getAllLeafNodes().stream().anyMatch(node -> node.getId().equals("clade_3"));
assert observe.getRoot().getAllLeafNodes().stream().anyMatch(node -> node.getId().equals("clade_10"));
}
}

0 comments on commit 70a5157

Please sign in to comment.