Search in sources :

Example 11 with XMLObject

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);
}
Also used : TransformedRandomWalkOperator(dr.inference.operators.TransformedRandomWalkOperator) XMLObject(dr.xml.XMLObject) AdaptationMode(dr.inference.operators.AdaptationMode) Parameter(dr.inference.model.Parameter) XMLObject(dr.xml.XMLObject) Transform(dr.util.Transform)

Example 12 with XMLObject

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);
}
Also used : AlloppNetworkPriorModel(dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) XMLObject(dr.xml.XMLObject) Parameter(dr.inference.model.Parameter) Units(dr.evolution.util.Units) XMLUnits(dr.evoxml.util.XMLUnits)

Example 13 with XMLObject

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;
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) Partition(dr.app.beagle.tools.Partition) ArrayList(java.util.ArrayList) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) Sequence(dr.evolution.sequence.Sequence) BranchModel(dr.evomodel.branchmodel.BranchModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) DataType(dr.evolution.datatype.DataType) XMLObject(dr.xml.XMLObject) XMLParseException(dr.xml.XMLParseException)

Aggregations

XMLObject (dr.xml.XMLObject)13 Parameter (dr.inference.model.Parameter)7 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)6 TreeModel (dr.evomodel.tree.TreeModel)6 ArrayList (java.util.ArrayList)5 XMLParseException (dr.xml.XMLParseException)4 DataType (dr.evolution.datatype.DataType)2 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)2 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)2 Partition (dr.app.beagle.tools.Partition)1 Sequence (dr.evolution.sequence.Sequence)1 MutableTreeModel (dr.evolution.tree.MutableTreeModel)1 Units (dr.evolution.util.Units)1 AlloppNetworkPriorModel (dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel)1 MulSpeciesTreeModel (dr.evomodel.alloppnet.speciation.MulSpeciesTreeModel)1 MulSpeciesTreePrior (dr.evomodel.alloppnet.speciation.MulSpeciesTreePrior)1 BranchAssignmentModel (dr.evomodel.branchmodel.BranchAssignmentModel)1 BranchModel (dr.evomodel.branchmodel.BranchModel)1 EpochBranchModel (dr.evomodel.branchmodel.EpochBranchModel)1 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)1