Search in sources :

Example 1 with MarkovModulatedSubstitutionModel

use of dr.evomodel.substmodel.MarkovModulatedSubstitutionModel in project beast-mcmc by beast-dev.

the class MarkovModulatedHiddenClassRewardParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    MarkovModulatedSubstitutionModel substitutionModel = (MarkovModulatedSubstitutionModel) xo.getChild(MarkovModulatedSubstitutionModel.class);
    HiddenDataType hiddenDataType = (HiddenDataType) substitutionModel.getDataType();
    int classNumber = xo.getIntegerAttribute(CLASS_NUMBER);
    int hiddenClassCount = hiddenDataType.getHiddenClassCount();
    if (classNumber < 1 || classNumber > hiddenClassCount) {
        throw new XMLParseException("Invalid class number in " + xo.getId());
    }
    // Use zero-indexed number
    classNumber--;
    int stateCount = hiddenDataType.getStateCount() / hiddenClassCount;
    // Construct reward parameter
    Parameter parameter = new Parameter.Default(stateCount * hiddenClassCount, 0.0);
    for (int i = 0; i < stateCount; ++i) {
        parameter.setParameterValue(i + classNumber * stateCount, 1.0);
    }
    if (xo.hasAttribute(NAME)) {
        parameter.setId((String) xo.getAttribute(NAME));
    } else {
        parameter.setId(substitutionModel.getId() + "_" + Integer.toString(classNumber + 1));
    }
    return parameter;
}
Also used : MarkovModulatedSubstitutionModel(dr.evomodel.substmodel.MarkovModulatedSubstitutionModel) HiddenDataType(dr.evolution.datatype.HiddenDataType) Parameter(dr.inference.model.Parameter)

Example 2 with MarkovModulatedSubstitutionModel

use of dr.evomodel.substmodel.MarkovModulatedSubstitutionModel in project beast-mcmc by beast-dev.

the class MarkovModulatedSubstitutionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    DataType dataType = DataTypeUtils.getDataType(xo);
    if (!(dataType instanceof HiddenDataType)) {
        throw new XMLParseException("Must construct " + MARKOV_MODULATED_MODEL + " with hidden data types. " + "You may need to provide the `-universal` extension to your hidden code type.");
    }
    Parameter switchingRates = (Parameter) xo.getElementFirstChild(SWITCHING_RATES);
    List<SubstitutionModel> substModels = new ArrayList<SubstitutionModel>();
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object cxo = xo.getChild(i);
        if (cxo instanceof SubstitutionModel) {
            substModels.add((SubstitutionModel) cxo);
        }
    }
    boolean geometricRates = xo.getAttribute(GEOMETRIC_RATES, false);
    Parameter rateScalar = xo.hasChildNamed(RATE_SCALAR) ? (Parameter) xo.getChild(RATE_SCALAR).getChild(Parameter.class) : null;
    SiteRateModel siteRateModel = (SiteRateModel) xo.getChild(SiteRateModel.class);
    if (siteRateModel != null) {
        if (siteRateModel.getCategoryCount() != substModels.size() && substModels.size() % siteRateModel.getCategoryCount() != 0) {
            throw new XMLParseException("Number of gamma categories must equal number of substitution models in " + xo.getId());
        }
    }
    MarkovModulatedSubstitutionModel mmsm = new MarkovModulatedSubstitutionModel(xo.getId(), substModels, switchingRates, dataType, null, rateScalar, geometricRates, siteRateModel);
    if (xo.getAttribute(RENORMALIZE, false)) {
        mmsm.setNormalization(true);
    }
    return mmsm;
}
Also used : MarkovModulatedSubstitutionModel(dr.evomodel.substmodel.MarkovModulatedSubstitutionModel) ArrayList(java.util.ArrayList) HiddenDataType(dr.evolution.datatype.HiddenDataType) DataType(dr.evolution.datatype.DataType) HiddenDataType(dr.evolution.datatype.HiddenDataType) Parameter(dr.inference.model.Parameter) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) MarkovModulatedSubstitutionModel(dr.evomodel.substmodel.MarkovModulatedSubstitutionModel) SiteRateModel(dr.evomodel.siteratemodel.SiteRateModel)

Aggregations

HiddenDataType (dr.evolution.datatype.HiddenDataType)2 MarkovModulatedSubstitutionModel (dr.evomodel.substmodel.MarkovModulatedSubstitutionModel)2 Parameter (dr.inference.model.Parameter)2 DataType (dr.evolution.datatype.DataType)1 SiteRateModel (dr.evomodel.siteratemodel.SiteRateModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 ArrayList (java.util.ArrayList)1