| 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 |
package dr.evomodel.operators; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evomodel.tree.MicrosatelliteSamplerTreeModel; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.evomodelxml.operators.RandomWalkIntegerNodeHeightWeightedOperatorParser; |
| 33 |
import dr.inference.operators.RandomWalkIntegerOperator; |
| 34 |
import dr.math.MathUtils; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class RandomWalkIntegerSetSizeWeightedOperator extends RandomWalkIntegerOperator { |
| 43 |
|
| 44 |
private MicrosatelliteSamplerTreeModel msatSampleTreeModel; |
| 45 |
private double[] weights; |
| 46 |
private double baseSetSize; |
| 47 |
public RandomWalkIntegerSetSizeWeightedOperator( |
| 48 |
Parameter parameter, |
| 49 |
int windowSize, |
| 50 |
double weight, |
| 51 |
MicrosatelliteSamplerTreeModel msatSampleTreeModel, |
| 52 |
double baseIntervalSize){ |
| 53 |
super(parameter, windowSize, weight); |
| 54 |
this.msatSampleTreeModel = msatSampleTreeModel; |
| 55 |
this.baseSetSize = baseIntervalSize; |
| 56 |
|
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
private void computeSampleWeights(){ |
| 61 |
TreeModel tree = msatSampleTreeModel.getTreeModel(); |
| 62 |
int intNodeCount = tree.getInternalNodeCount(); |
| 63 |
int extNodeCount = tree.getExternalNodeCount(); |
| 64 |
weights = new double[intNodeCount]; |
| 65 |
for(int i = 0 ; i < intNodeCount; i++){ |
| 66 |
NodeRef node = tree.getNode(i+extNodeCount); |
| 67 |
int lcState = msatSampleTreeModel.getNodeValue(tree.getChild(node, 0)); |
| 68 |
int rcState = msatSampleTreeModel.getNodeValue(tree.getChild(node, 1)); |
| 69 |
weights[i] = Math.abs(lcState-rcState)+baseSetSize; |
| 70 |
|
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
public double doOperation() { |
| 75 |
computeSampleWeights(); |
| 76 |
|
| 77 |
int index = MathUtils.randomChoicePDF(weights); |
| 78 |
|
| 79 |
int newValue = calculateNewValue(index); |
| 80 |
parameter.setValue(index, newValue); |
| 81 |
|
| 82 |
return 0.0; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
public String getOperatorName() { |
| 87 |
return "randomWalkIntegerSetSizeWeighted(" + parameter.getId() + ")"; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
public double getTargetAcceptanceProbability() { |
| 92 |
return 0.234; |
| 93 |
} |
| 94 |
|
| 95 |
public double getMinimumAcceptanceLevel() { |
| 96 |
return 0.1; |
| 97 |
} |
| 98 |
|
| 99 |
public double getMaximumAcceptanceLevel() { |
| 100 |
return 0.4; |
| 101 |
} |
| 102 |
|
| 103 |
public double getMinimumGoodAcceptanceLevel() { |
| 104 |
return 0.20; |
| 105 |
} |
| 106 |
|
| 107 |
public double getMaximumGoodAcceptanceLevel() { |
| 108 |
return 0.30; |
| 109 |
} |
| 110 |
|
| 111 |
public String toString() { |
| 112 |
return RandomWalkIntegerNodeHeightWeightedOperatorParser.RANDOM_WALK_INT_NODE_HEIGHT_WGT_OP + "(" + parameter.getId() + ", " + windowSize + ", " + getWeight() + ")"; |
| 113 |
} |
| 114 |
|
| 115 |
} |