| 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.coalescent.structure; |
| 27 |
|
| 28 |
import dr.evolution.colouring.ColourChangeMatrix; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.inference.model.Variable; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@Deprecated |
| 41 |
public class ConstantMigrationModel extends MigrationModel { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static String CONSTANT_MIGRATION_MODEL = "constantMigrationModel"; |
| 47 |
public static String MIGRATION_RATES = "migrationRates"; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public ConstantMigrationModel(int demeCount, Parameter migrationParameter) { |
| 53 |
|
| 54 |
this(CONSTANT_MIGRATION_MODEL, demeCount, migrationParameter); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public ConstantMigrationModel(String name, int demeCount, Parameter migrationParameter) { |
| 61 |
|
| 62 |
super(name); |
| 63 |
|
| 64 |
this.demeCount = demeCount; |
| 65 |
this.migrationParameter = migrationParameter; |
| 66 |
addVariable(migrationParameter); |
| 67 |
migrationParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, migrationParameter.getDimension())); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public ColourChangeMatrix getMigrationMatrix() { |
| 73 |
if (colourChangeMatrix == null) { |
| 74 |
colourChangeMatrix = new ColourChangeMatrix(migrationParameter.getParameterValues(), demeCount); |
| 75 |
} |
| 76 |
return colourChangeMatrix; |
| 77 |
} |
| 78 |
|
| 79 |
public double[] getMigrationRates(double time) { |
| 80 |
return migrationParameter.getParameterValues(); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 85 |
colourChangeMatrix = null; |
| 86 |
} |
| 87 |
|
| 88 |
protected void restoreState() { |
| 89 |
colourChangeMatrix = null; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 96 |
|
| 97 |
public String getParserName() { |
| 98 |
return CONSTANT_MIGRATION_MODEL; |
| 99 |
} |
| 100 |
|
| 101 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 102 |
|
| 103 |
int demeCount = 2; |
| 104 |
|
| 105 |
XMLObject cxo = xo.getChild(MIGRATION_RATES); |
| 106 |
Parameter migrationParameter = (Parameter) cxo.getChild(Parameter.class); |
| 107 |
|
| 108 |
|
| 109 |
return new ConstantMigrationModel(demeCount, migrationParameter); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public String getParserDescription() { |
| 117 |
return "A migration model representing constant migration rates through time."; |
| 118 |
} |
| 119 |
|
| 120 |
public Class getReturnType() { |
| 121 |
return ConstantMigrationModel.class; |
| 122 |
} |
| 123 |
|
| 124 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 125 |
return rules; |
| 126 |
} |
| 127 |
|
| 128 |
private final XMLSyntaxRule[] rules = { |
| 129 |
new ElementRule(MIGRATION_RATES, |
| 130 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}) |
| 131 |
}; |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
private int demeCount; |
| 139 |
private Parameter migrationParameter; |
| 140 |
private ColourChangeMatrix colourChangeMatrix = null; |
| 141 |
} |