| 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.branchmodel; |
| 27 |
|
| 28 |
import dr.evomodel.substmodel.FrequencyModel; |
| 29 |
import dr.evomodel.substmodel.SubstitutionModel; |
| 30 |
import dr.evolution.tree.NodeRef; |
| 31 |
import dr.evomodel.tree.TreeModel; |
| 32 |
import dr.inference.model.AbstractModel; |
| 33 |
import dr.inference.model.Model; |
| 34 |
import dr.inference.model.Variable; |
| 35 |
|
| 36 |
import java.util.ArrayList; |
| 37 |
import java.util.List; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public class ExternalInternalBranchModel extends AbstractModel implements BranchModel { |
| 46 |
public ExternalInternalBranchModel(TreeModel tree, SubstitutionModel externalSubstModel, SubstitutionModel internalSubstModel) { |
| 47 |
super("ExternalInternalBranchModel"); |
| 48 |
|
| 49 |
this.tree = tree; |
| 50 |
this.externalSubstModel = externalSubstModel; |
| 51 |
this.internalSubstModel = internalSubstModel; |
| 52 |
|
| 53 |
addModel(tree); |
| 54 |
addModel(externalSubstModel); |
| 55 |
addModel(internalSubstModel); |
| 56 |
} |
| 57 |
|
| 58 |
public Mapping getBranchModelMapping(final NodeRef node) { |
| 59 |
return new Mapping() { |
| 60 |
public int[] getOrder() { |
| 61 |
return new int[] { tree.isExternal(node) ? 0 : 1 }; |
| 62 |
} |
| 63 |
|
| 64 |
public double[] getWeights() { |
| 65 |
return new double[] { 1.0 }; |
| 66 |
} |
| 67 |
}; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
public List<SubstitutionModel> getSubstitutionModels() { |
| 72 |
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>(); |
| 73 |
substitutionModels.add(externalSubstModel); |
| 74 |
substitutionModels.add(internalSubstModel); |
| 75 |
return substitutionModels; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public SubstitutionModel getRootSubstitutionModel() { |
| 80 |
return internalSubstModel; |
| 81 |
} |
| 82 |
|
| 83 |
public FrequencyModel getRootFrequencyModel() { |
| 84 |
return getRootSubstitutionModel().getFrequencyModel(); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
public boolean requiresMatrixConvolution() { |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 94 |
fireModelChanged(); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
protected void handleVariableChangedEvent(Variable variable, int index, Variable.ChangeType type) { |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
protected void storeState() { |
| 103 |
} |
| 104 |
|
| 105 |
@Override |
| 106 |
protected void restoreState() { |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
protected void acceptState() { |
| 111 |
} |
| 112 |
|
| 113 |
private final TreeModel tree; |
| 114 |
private final SubstitutionModel externalSubstModel; |
| 115 |
private final SubstitutionModel internalSubstModel; |
| 116 |
} |