Debian Codegraph @

src/dr/evomodel/operators/FNPR.java

raw symbols SCIP
1 /*
2 * FNPR.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * This is an implementation of the Subtree Prune and Regraft (SPR) operator for
38 * trees. It assumes explicitely bifurcating rooted trees.
39 *
40 * @author Sebastian Hoehna
41 * @version 1.0
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 // distances = new int[tree.getNodeCount()];
54 }
55
56 /*
57 * (non-Javadoc)
58 *
59 * @see dr.inference.operators.SimpleMCMCOperator#doOperation()
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 // get a random node whose father is not the root - otherwise
76 // the operation is not possible
77 do {
78 i = tree.getNode(MathUtils.nextInt(nNodes));
79 } while (root == i || tree.getParent(i) == root);
80
81 // int childIndex = (MathUtils.nextDouble() >= 0.5 ? 1 : 0);
82 // int otherChildIndex = 1 - childIndex;
83 // NodeRef iOtherChild = tree.getChild(i, otherChildIndex);
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 // NodeRef newChild = getRandomNode(possibleChilds, iFather);
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 // prune
103 tree.removeChild(iFather, iBrother);
104 tree.removeChild(iGrandfather, iFather);
105 tree.addChild(iGrandfather, iBrother);
106
107 // reattach
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 * (non-Javadoc)
129 *
130 * @see dr.inference.operators.SimpleMCMCOperator#getOperatorName()
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 * (non-Javadoc)
164 *
165 * @see dr.inference.operators.MCMCOperator#getPerformanceSuggestion()
166 */
167 public String getPerformanceSuggestion() {
168 return "";
169 }
170
171 }