Search in sources :

Example 1 with CovarionHKY

use of dr.oldevomodel.substmodel.CovarionHKY in project beast-mcmc by beast-dev.

the class CovarionHKYParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter kappaParam;
    Parameter switchingRates;
    Parameter hiddenClassRates;
    FrequencyModel freqModel;
    kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
    switchingRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.SWITCHING_RATES);
    hiddenClassRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.HIDDEN_CLASS_RATES);
    freqModel = (FrequencyModel) xo.getElementFirstChild(AbstractCovarionDNAModel.FREQUENCIES);
    if (!(freqModel.getDataType() instanceof OldHiddenNucleotides)) {
        throw new IllegalArgumentException("Datatype must be hidden nucleotides!!");
    }
    OldHiddenNucleotides dataType = (OldHiddenNucleotides) freqModel.getDataType();
    int hiddenStateCount = dataType.getHiddenClassCount();
    int switchingRatesCount = hiddenStateCount * (hiddenStateCount - 1) / 2;
    if (switchingRates.getDimension() != switchingRatesCount) {
        throw new IllegalArgumentException("switching rates parameter must have " + switchingRatesCount + " dimensions, for " + hiddenStateCount + " hidden categories");
    }
    CovarionHKY model = new CovarionHKY(dataType, kappaParam, hiddenClassRates, switchingRates, freqModel);
    System.out.println(model);
    return model;
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) OldHiddenNucleotides(dr.evolution.datatype.OldHiddenNucleotides) Parameter(dr.inference.model.Parameter) CovarionHKY(dr.oldevomodel.substmodel.CovarionHKY)

Example 2 with CovarionHKY

use of dr.oldevomodel.substmodel.CovarionHKY in project beast-mcmc by beast-dev.

the class CovarionHKYTest method transitionProbabilitiesTester.

public void transitionProbabilitiesTester(double[] freqs, double[] expectedP) {
    Parameter frequencies = new Parameter.Default(freqs);
    FrequencyModel freqModel = new FrequencyModel(dataType, frequencies);
    model = new CovarionHKY(dataType, kappa, alpha, switchingRate, freqModel);
    alpha.setParameterValue(0, 0.0);
    switchingRate.setParameterValue(0, 1.0);
    kappa.setParameterValue(0, 2.0);
    model.setupMatrix();
    System.out.println(SubstitutionModelUtils.toString(model.getQ(), dataType, 2));
    double[] matrix = new double[64];
    double[] pi = model.getFrequencyModel().getFrequencies();
    int index = 0;
    for (double distance = 0.01; distance <= 1.005; distance += 0.01) {
        model.getTransitionProbabilities(distance, matrix);
        double pChange = 0.0;
        double pNoOrHiddenChange = 0.0;
        int k = 0;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if ((i % 4) != (j % 4)) {
                    pChange += matrix[k] * pi[i];
                } else {
                    pNoOrHiddenChange += matrix[k] * pi[i];
                }
                k += 1;
            }
        }
        double totalP = pChange + pNoOrHiddenChange;
        assertEquals(1.0, totalP, 1e-10);
        System.out.print(distance + "\t" + "\t" + pChange + "\t");
        if (index < 100)
            System.out.print(expectedP[index]);
        System.out.println();
        //assertEquals(expectedP[index], pChange, 1e-14);
        index += 1;
    }
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Parameter(dr.inference.model.Parameter) CovarionHKY(dr.oldevomodel.substmodel.CovarionHKY)

Aggregations

Parameter (dr.inference.model.Parameter)2 CovarionHKY (dr.oldevomodel.substmodel.CovarionHKY)2 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)2 OldHiddenNucleotides (dr.evolution.datatype.OldHiddenNucleotides)1