use of dr.xml.XMLObject in project beast-mcmc by beast-dev.
the class TransformedRandomWalkOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
AdaptationMode mode = AdaptationMode.parseMode(xo);
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double windowSize = xo.getDoubleAttribute(WINDOW_SIZE);
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
int dim = parameter.getDimension();
Transform[] transformations = new Transform[dim];
for (int i = 0; i < dim; i++) {
transformations[i] = Transform.NONE;
}
for (int i = 0; i < xo.getChildCount(); i++) {
Object child = xo.getChild(i);
if (child instanceof Transform.ParsedTransform) {
Transform.ParsedTransform thisObject = (Transform.ParsedTransform) child;
System.err.println("Transformations:");
for (int j = thisObject.start; j < thisObject.end; ++j) {
transformations[j] = thisObject.transform;
System.err.print(transformations[j].getTransformName() + " ");
}
System.err.println();
}
}
Double lower = null;
Double upper = null;
if (xo.hasAttribute(LOWER)) {
lower = xo.getDoubleAttribute(LOWER);
}
if (xo.hasAttribute(UPPER)) {
upper = xo.getDoubleAttribute(UPPER);
}
TransformedRandomWalkOperator.BoundaryCondition condition = TransformedRandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, TransformedRandomWalkOperator.BoundaryCondition.reflecting.name()));
if (xo.hasChildNamed(UPDATE_INDEX)) {
XMLObject cxo = xo.getChild(UPDATE_INDEX);
Parameter updateIndex = (Parameter) cxo.getChild(Parameter.class);
if (updateIndex.getDimension() != parameter.getDimension())
throw new RuntimeException("Parameter to update and missing indices must have the same dimension");
return new TransformedRandomWalkOperator(parameter, transformations, updateIndex, windowSize, condition, weight, mode, lower, upper);
}
return new TransformedRandomWalkOperator(parameter, transformations, null, windowSize, condition, weight, mode, lower, upper);
}
use of dr.xml.XMLObject in project beast-mcmc by beast-dev.
the class AlloppNetworkPriorModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
final XMLObject erXo = xo.getChild(EVENTRATE);
final Parameter eventrate = (Parameter) erXo.getChild(Parameter.class);
final XMLObject psfXo = xo.getChild(POPULATION_SCALING_FACTOR);
final Parameter popscalingfactor = (Parameter) psfXo.getChild(Parameter.class);
final XMLObject tpdXo = xo.getChild(TIP_POPULATION_DISTRIBUTION);
ParametricDistributionModel tippopmodel = (ParametricDistributionModel) tpdXo.getChild(ParametricDistributionModel.class);
final XMLObject rpdXo = xo.getChild(ROOT_POPULATION_DISTRIBUTION);
ParametricDistributionModel rootpopmodel = (ParametricDistributionModel) rpdXo.getChild(ParametricDistributionModel.class);
final XMLObject hpdXo = xo.getChild(HYBRID_POPULATION_DISTRIBUTION);
ParametricDistributionModel hybpopmodel = (ParametricDistributionModel) hpdXo.getChild(ParametricDistributionModel.class);
return new AlloppNetworkPriorModel(eventrate, popscalingfactor, tippopmodel, rootpopmodel, hybpopmodel, units);
}
use of dr.xml.XMLObject in project beast-mcmc by beast-dev.
the class PartitionParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
int from = 0;
int to = -1;
int every = xo.getAttribute(EVERY, 1);
DataType dataType = null;
if (xo.hasAttribute(FROM)) {
from = xo.getIntegerAttribute(FROM) - 1;
if (from < 0) {
throw new XMLParseException("Illegal 'from' attribute in patterns element");
}
}
if (xo.hasAttribute(TO)) {
to = xo.getIntegerAttribute(TO) - 1;
if (to < 0 || to < from) {
throw new XMLParseException("Illegal 'to' attribute in patterns element");
}
}
if (every <= 0) {
throw new XMLParseException("Illegal 'every' attribute in patterns element");
}
if (xo.hasAttribute(DATA_TYPE)) {
dataType = DataTypeUtils.getDataType(xo);
}
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
GammaSiteRateModel siteModel = (GammaSiteRateModel) xo.getChild(GammaSiteRateModel.class);
// FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
FrequencyModel freqModel;
List<FrequencyModel> freqModels = new ArrayList<FrequencyModel>();
for (int i = 0; i < xo.getChildCount(); i++) {
Object cxo = xo.getChild(i);
if (cxo instanceof FrequencyModel) {
freqModels.add((FrequencyModel) cxo);
}
}
if (freqModels.size() == 1) {
freqModel = freqModels.get(0);
} else {
double[] freqParameter = new double[freqModels.size() * freqModels.get(0).getFrequencyCount()];
int index = 0;
for (int i = 0; i < freqModels.size(); i++) {
for (int j = 0; j < freqModels.get(i).getFrequencyCount(); j++) {
freqParameter[index] = (freqModels.get(i).getFrequency(j)) / freqModels.size();
index++;
}
}
freqModel = new FrequencyModel(dataType, freqParameter);
}
Sequence rootSequence = (Sequence) xo.getChild(Sequence.class);
BranchRateModel rateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
if (rateModel == null) {
rateModel = new DefaultBranchRateModel();
}
BranchModel branchModel = (BranchModel) xo.getChild(BranchModel.class);
if (branchModel == null) {
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
branchModel = new HomogeneousBranchModel(substitutionModel);
}
Partition partition = new Partition(tree, branchModel, siteModel, rateModel, freqModel, from, to, every, dataType);
if (rootSequence != null) {
partition.setRootSequence(rootSequence);
}
return partition;
}
Aggregations