@Override protected Double modifyARG() throws InvalidParameterValueException, IllegalModificationException, ModificationImpossibleException { List<ARGNode> internalNodes = arg.getInternalNodes(); int nodeNum = RandomSource.getNextIntFromTo(0, internalNodes.size() - 1); ARGNode node = internalNodes.get(nodeNum); if (internalNodes.size() == 1) // Must be two tips, no recomb nodes throw new ModificationImpossibleException("No internal nodes to modify"); // Pick a node that is not the root while (node.getParent(0) == null) { node = internalNodes.get(RandomSource.getNextIntFromTo(0, internalNodes.size() - 1)); } double hr; if (node instanceof CoalNode) { hr = swapCoalNode((CoalNode) node); } else { hr = swapRecombNode((RecombNode) node); } return hr; }
protected double swapCoalNode(CoalNode node) throws ModificationImpossibleException, IllegalModificationException { List<ARGNode> branches = arg.getBranchesCrossingTime(node.getHeight()); ARGNode newChild = branches.get( RandomSource.getNextIntFromTo( 0, branches.size() - 1)); // This will be new child of coal node ARGNode newParent = findDisplaceableParent(newChild, node.getHeight()); // New parent of node int oldChildIndex = RandomSource.getNextIntFromTo(0, 1); ARGNode oldChild = node.getOffspring(oldChildIndex); // Child that will be attached to node's parent ARGNode oldParent = node.getParent(); // Attach the old child we are leaving to the old parent int pIndex = whichChild(node, oldParent); oldChild.proposeParent(whichParent(oldChild, node), oldParent); oldParent.proposeOffspring(pIndex, oldChild); // Insert the new node between newChild and newParent int cIndex = whichParent(newChild, newParent); int cpIndex = whichChild(newChild, newParent); node.proposeParent(newParent); newParent.proposeOffspring(cpIndex, node); newChild.proposeParent(cIndex, node); node.proposeOffspring(oldChildIndex, newChild); propogateRangeProposals(oldChild); propogateRangeProposals(node); if (verbose) System.out.println( "Swapping coal node " + node + " to branch connecting parent " + newParent + " to offspring " + newChild); return 1.0; }