| 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; |
| 27 |
|
| 28 |
import dr.evolution.coalescent.DemographicFunction; |
| 29 |
import dr.evolution.coalescent.PiecewiseConstantPopulation; |
| 30 |
import dr.evolution.coalescent.PiecewiseLinearPopulation; |
| 31 |
import dr.evomodel.tree.TreeModel; |
| 32 |
import dr.evomodelxml.coalescent.ScaledPiecewiseModelParser; |
| 33 |
import dr.inference.model.Model; |
| 34 |
import dr.inference.model.Parameter; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class ScaledPiecewiseModel extends DemographicModel { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public ScaledPiecewiseModel(Parameter N0Parameter, TreeModel treeModel, boolean linear, Type units) { |
| 49 |
|
| 50 |
this(ScaledPiecewiseModelParser.PIECEWISE_POPULATION, N0Parameter, treeModel, linear, units); |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public ScaledPiecewiseModel(String name, Parameter N0Parameter, TreeModel treeModel, boolean linear, Type units) { |
| 58 |
|
| 59 |
super(name); |
| 60 |
|
| 61 |
if (N0Parameter.getDimension() < 2) { |
| 62 |
throw new IllegalArgumentException("Must have at least 2 epochs"); |
| 63 |
} |
| 64 |
|
| 65 |
this.N0Parameter = N0Parameter; |
| 66 |
this.treeModel = treeModel; |
| 67 |
addVariable(N0Parameter); |
| 68 |
N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, N0Parameter.getDimension())); |
| 69 |
|
| 70 |
setUnits(units); |
| 71 |
|
| 72 |
int epochs = N0Parameter.getDimension(); |
| 73 |
|
| 74 |
if (linear) { |
| 75 |
piecewiseFunction = new PiecewiseLinearPopulation(new double[epochs - 1], new double[epochs], units); |
| 76 |
} else { |
| 77 |
piecewiseFunction = new PiecewiseConstantPopulation(new double[epochs - 1], new double[epochs], units); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public DemographicFunction getDemographicFunction() { |
| 85 |
|
| 86 |
double height = treeModel.getNodeHeight(treeModel.getRoot()); |
| 87 |
int epochs = N0Parameter.getDimension(); |
| 88 |
|
| 89 |
for (int i = 0; i < N0Parameter.getDimension(); i++) { |
| 90 |
piecewiseFunction.setArgument(i, N0Parameter.getParameterValue(i)); |
| 91 |
if (i < epochs - 1) piecewiseFunction.setEpochDuration(i, height / (double) epochs); |
| 92 |
} |
| 93 |
|
| 94 |
return piecewiseFunction; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
protected void handleParameterChangedEvent(Parameter parameter, int index) { |
| 106 |
|
| 107 |
if (parameter == N0Parameter) { |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
protected void storeState() { |
| 115 |
} |
| 116 |
|
| 117 |
protected void restoreState() { |
| 118 |
} |
| 119 |
|
| 120 |
protected void acceptState() { |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
Parameter N0Parameter; |
| 128 |
TreeModel treeModel; |
| 129 |
PiecewiseConstantPopulation piecewiseFunction = null; |
| 130 |
} |