| 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.branchratemodel; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.evomodel.tree.TreeParameterModel; |
| 32 |
import dr.evomodelxml.branchratemodel.ArbitraryBranchRatesParser; |
| 33 |
import dr.inference.model.Model; |
| 34 |
import dr.inference.model.Parameter; |
| 35 |
import dr.inference.model.Variable; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class ArbitraryBranchRates extends AbstractBranchRateModel { |
| 45 |
|
| 46 |
|
| 47 |
final TreeParameterModel rates; |
| 48 |
final Parameter rateParameter; |
| 49 |
final boolean reciprocal; |
| 50 |
final boolean exp; |
| 51 |
|
| 52 |
public ArbitraryBranchRates(TreeModel tree, Parameter rateParameter, boolean reciprocal, boolean exp, boolean setRates) { |
| 53 |
|
| 54 |
super(ArbitraryBranchRatesParser.ARBITRARY_BRANCH_RATES); |
| 55 |
|
| 56 |
if (setRates) { |
| 57 |
double value = exp ? 0.0 : 1.0; |
| 58 |
for (int i = 0; i < rateParameter.getDimension(); i++) { |
| 59 |
rateParameter.setValue(i, value); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
Parameter.DefaultBounds bounds = exp ? |
| 64 |
new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, |
| 65 |
rateParameter.getDimension()) : |
| 66 |
new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0, |
| 67 |
rateParameter.getDimension()); |
| 68 |
rateParameter.addBounds(bounds); |
| 69 |
|
| 70 |
this.rates = new TreeParameterModel(tree, rateParameter, false); |
| 71 |
this.rateParameter = rateParameter; |
| 72 |
|
| 73 |
addModel(rates); |
| 74 |
|
| 75 |
this.reciprocal = reciprocal; |
| 76 |
this.exp = exp; |
| 77 |
} |
| 78 |
|
| 79 |
public void setBranchRate(Tree tree, NodeRef node, double value) { |
| 80 |
rates.setNodeValue(tree, node, value); |
| 81 |
} |
| 82 |
|
| 83 |
public double getBranchRate(final Tree tree, final NodeRef node) { |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
double rate = rates.getNodeValue(tree, node); |
| 88 |
|
| 89 |
if (exp) { |
| 90 |
rate = Math.exp(rate); |
| 91 |
} |
| 92 |
|
| 93 |
if (reciprocal) { |
| 94 |
rate = 1.0 / rate; |
| 95 |
} |
| 96 |
|
| 97 |
return rate; |
| 98 |
} |
| 99 |
|
| 100 |
public boolean usingReciprocal() { |
| 101 |
return reciprocal; |
| 102 |
} |
| 103 |
|
| 104 |
public void handleModelChangedEvent(Model model, Object object, int index) { |
| 105 |
|
| 106 |
fireModelChanged(object, index); |
| 107 |
} |
| 108 |
|
| 109 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
protected void storeState() { |
| 114 |
} |
| 115 |
|
| 116 |
protected void restoreState() { |
| 117 |
} |
| 118 |
|
| 119 |
protected void acceptState() { |
| 120 |
} |
| 121 |
|
| 122 |
} |