| 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.app.beauti.components.hpm; |
| 27 |
|
| 28 |
import dr.app.beauti.options.*; |
| 29 |
import dr.app.beauti.priorspanel.PriorsPanel; |
| 30 |
import dr.app.beauti.types.PriorScaleType; |
| 31 |
import dr.app.beauti.types.PriorType; |
| 32 |
|
| 33 |
import javax.swing.*; |
| 34 |
import java.util.ArrayList; |
| 35 |
import java.util.List; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class HierarchicalModelComponentOptions implements ComponentOptions { |
| 42 |
|
| 43 |
public HierarchicalModelComponentOptions(final BeautiOptions options) { |
| 44 |
this.options = options; |
| 45 |
hpmList = new ArrayList<HierarchicalPhylogeneticModel>(); |
| 46 |
} |
| 47 |
|
| 48 |
public void createParameters(final ModelOptions modelOptions) { |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
public void selectParameters(final ModelOptions modelOptions, final List<Parameter> params) { |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
public void selectStatistics(final ModelOptions modelOptions, final List<Parameter> stats) { |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
public void selectOperators(final ModelOptions modelOptions, final List<Operator> ops) { |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
public boolean modelExists(String name) { |
| 76 |
boolean found = false; |
| 77 |
for (HierarchicalPhylogeneticModel hpm : hpmList) { |
| 78 |
if (hpm.getName().compareTo(name) == 0) { |
| 79 |
found = true; |
| 80 |
break; |
| 81 |
} |
| 82 |
} |
| 83 |
return found; |
| 84 |
} |
| 85 |
|
| 86 |
public HierarchicalPhylogeneticModel addHPM(String text, List<Parameter> parameterList, PriorType priorType) { |
| 87 |
List<Parameter> argumentList = new ArrayList<Parameter>(); |
| 88 |
|
| 89 |
|
| 90 |
String meanName = text + HierarchicalModelComponentGenerator.MEAN_SUFFIX; |
| 91 |
Parameter mean = options.parameterExists(meanName) ? |
| 92 |
options.getParameter(meanName) : |
| 93 |
options.createParameterNormalPrior(meanName, "Unknown mean of HPM", |
| 94 |
PriorScaleType.NONE, 0.0, 0.0, 1.0, 0.0); |
| 95 |
argumentList.add(mean); |
| 96 |
|
| 97 |
String precisionName = text + HierarchicalModelComponentGenerator.PRECISION_SUFFIX; |
| 98 |
Parameter precision = options.parameterExists(precisionName) ? |
| 99 |
options.getParameter(precisionName) : |
| 100 |
options.createParameterGammaPrior(precisionName, "Unknown precision of HPM", |
| 101 |
PriorScaleType.NONE, 1.0, 0.001, 1000.0, true); |
| 102 |
argumentList.add(precision); |
| 103 |
|
| 104 |
HierarchicalPhylogeneticModel hpm = new HierarchicalPhylogeneticModel(text, parameterList, argumentList, priorType); |
| 105 |
hpmList.add(hpm); |
| 106 |
|
| 107 |
for (Parameter parameter : parameterList) { |
| 108 |
parameter.linkedName = hpm.getName(); |
| 109 |
} |
| 110 |
return hpm; |
| 111 |
} |
| 112 |
|
| 113 |
public boolean isHierarchicalParameter(Parameter parameter) { |
| 114 |
boolean found = false; |
| 115 |
for (HierarchicalPhylogeneticModel hpm : hpmList) { |
| 116 |
if (hpm.getArgumentParameterList().contains(parameter)) { |
| 117 |
found = true; |
| 118 |
break; |
| 119 |
} |
| 120 |
} |
| 121 |
return found; |
| 122 |
} |
| 123 |
|
| 124 |
public int removeParameter(PriorsPanel priorsPanel, Parameter parameter, boolean caution) { |
| 125 |
HierarchicalPhylogeneticModel toRemove = null; |
| 126 |
for (HierarchicalPhylogeneticModel hpm : hpmList) { |
| 127 |
List<Parameter> parameterList = hpm.getArgumentParameterList(); |
| 128 |
if (parameterList.contains(parameter)) { |
| 129 |
if (caution && parameterList.size() == 2 && priorsPanel != null) { |
| 130 |
String modelName = hpm.getName(); |
| 131 |
|
| 132 |
int option = JOptionPane.showConfirmDialog(priorsPanel, |
| 133 |
"Removing this parameter from HPM '" + modelName + "' will result in only one\n" + |
| 134 |
"parameter remaining the HPM. Single parameter models are not recommended.\n" + |
| 135 |
"Continue?", |
| 136 |
"HPM warning", |
| 137 |
JOptionPane.YES_NO_OPTION, |
| 138 |
JOptionPane.WARNING_MESSAGE); |
| 139 |
if (option == JOptionPane.NO_OPTION) { |
| 140 |
return JOptionPane.NO_OPTION; |
| 141 |
} |
| 142 |
} |
| 143 |
parameterList.remove(parameter); |
| 144 |
} |
| 145 |
if (hpm.isEmpty()) { |
| 146 |
toRemove = hpm; |
| 147 |
} |
| 148 |
} |
| 149 |
if (toRemove != null) { |
| 150 |
hpmList.remove(toRemove); |
| 151 |
} |
| 152 |
return JOptionPane.YES_OPTION; |
| 153 |
} |
| 154 |
|
| 155 |
public List<HierarchicalPhylogeneticModel> getHPMList() { |
| 156 |
return hpmList; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
final private BeautiOptions options; |
| 166 |
final private List<HierarchicalPhylogeneticModel> hpmList; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public boolean isEmpty() { |
| 176 |
return hpmList.isEmpty(); |
| 177 |
} |
| 178 |
} |