| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
package dr.evomodel.operators; |
| 30 |
|
| 31 |
import dr.evolution.tree.NodeRef; |
| 32 |
import dr.evomodel.tree.TreeModel; |
| 33 |
import dr.evomodelxml.operators.FNPRParser; |
| 34 |
import dr.math.MathUtils; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
@Deprecated |
| 44 |
public class FNPR extends AbstractTreeOperator { |
| 45 |
|
| 46 |
private TreeModel tree = null; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public FNPR(TreeModel tree, double weight) { |
| 51 |
this.tree = tree; |
| 52 |
setWeight(weight); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
@Override |
| 62 |
public double doOperation() { |
| 63 |
NodeRef iGrandfather, iBrother; |
| 64 |
double heightFather; |
| 65 |
final int tipCount = tree.getExternalNodeCount(); |
| 66 |
|
| 67 |
final int nNodes = tree.getNodeCount(); |
| 68 |
final NodeRef root = tree.getRoot(); |
| 69 |
|
| 70 |
NodeRef i; |
| 71 |
|
| 72 |
int MAX_TRIES = 1000; |
| 73 |
|
| 74 |
for (int tries = 0; tries < MAX_TRIES; ++tries) { |
| 75 |
|
| 76 |
|
| 77 |
do { |
| 78 |
i = tree.getNode(MathUtils.nextInt(nNodes)); |
| 79 |
} while (root == i || tree.getParent(i) == root); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
NodeRef iFather = tree.getParent(i); |
| 86 |
iGrandfather = tree.getParent(iFather); |
| 87 |
iBrother = getOtherChild(tree, iFather, i); |
| 88 |
heightFather = tree.getNodeHeight(iFather); |
| 89 |
|
| 90 |
|
| 91 |
NodeRef newChild = tree.getNode(MathUtils.nextInt(nNodes)); |
| 92 |
|
| 93 |
if (tree.getNodeHeight(newChild) < heightFather |
| 94 |
&& root != newChild |
| 95 |
&& tree.getNodeHeight(tree.getParent(newChild)) > heightFather |
| 96 |
&& newChild != iFather |
| 97 |
&& tree.getParent(newChild) != iFather) { |
| 98 |
NodeRef newGrandfather = tree.getParent(newChild); |
| 99 |
|
| 100 |
tree.beginTreeEdit(); |
| 101 |
|
| 102 |
|
| 103 |
tree.removeChild(iFather, iBrother); |
| 104 |
tree.removeChild(iGrandfather, iFather); |
| 105 |
tree.addChild(iGrandfather, iBrother); |
| 106 |
|
| 107 |
|
| 108 |
tree.removeChild(newGrandfather, newChild); |
| 109 |
tree.addChild(iFather, newChild); |
| 110 |
tree.addChild(newGrandfather, iFather); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
tree.endTreeEdit(); |
| 115 |
|
| 116 |
tree.pushTreeChangedEvent(i); |
| 117 |
|
| 118 |
assert tree.getExternalNodeCount() == tipCount; |
| 119 |
|
| 120 |
return 0.0; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
throw new RuntimeException("Couldn't find valid SPR move on this tree!"); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
@Override |
| 133 |
public String getOperatorName() { |
| 134 |
return FNPRParser.FNPR; |
| 135 |
} |
| 136 |
|
| 137 |
public double getTargetAcceptanceProbability() { |
| 138 |
|
| 139 |
return 0.0234; |
| 140 |
} |
| 141 |
|
| 142 |
public double getMaximumAcceptanceLevel() { |
| 143 |
|
| 144 |
return 0.04; |
| 145 |
} |
| 146 |
|
| 147 |
public double getMaximumGoodAcceptanceLevel() { |
| 148 |
|
| 149 |
return 0.03; |
| 150 |
} |
| 151 |
|
| 152 |
public double getMinimumAcceptanceLevel() { |
| 153 |
|
| 154 |
return 0.005; |
| 155 |
} |
| 156 |
|
| 157 |
public double getMinimumGoodAcceptanceLevel() { |
| 158 |
|
| 159 |
return 0.01; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public String getPerformanceSuggestion() { |
| 168 |
return ""; |
| 169 |
} |
| 170 |
|
| 171 |
} |