Search in sources :

Example 11 with FrequencyModel

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

the class LikelihoodTest method testLikelihoodGTR.

public void testLikelihoodGTR() {
    System.out.println("\nTest Likelihood using GTR:");
    // Sub model
    Parameter freqs = new Parameter.Default(alignment.getStateFrequencies());
    FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs);
    Variable<Double> rateACValue = new Parameter.Default(GTRParser.A_TO_C, 1.0, 1.0E-8, Double.POSITIVE_INFINITY);
    Variable<Double> rateAGValue = new Parameter.Default(GTRParser.A_TO_G, 1.0, 1.0E-8, Double.POSITIVE_INFINITY);
    Variable<Double> rateATValue = new Parameter.Default(GTRParser.A_TO_T, 1.0, 1.0E-8, Double.POSITIVE_INFINITY);
    Variable<Double> rateCGValue = new Parameter.Default(GTRParser.C_TO_G, 1.0, 1.0E-8, Double.POSITIVE_INFINITY);
    Variable<Double> rateCTValue = new Parameter.Default(GTRParser.C_TO_T, 1.0, 1.0E-8, Double.POSITIVE_INFINITY);
    Variable<Double> rateGTValue = new Parameter.Default(GTRParser.G_TO_T, 1.0, 1.0E-8, Double.POSITIVE_INFINITY);
    GTR gtr = new GTR(rateACValue, rateAGValue, rateATValue, rateCGValue, rateCTValue, rateGTValue, f);
    //siteModel
    Parameter mu = new Parameter.Default(GammaSiteModelParser.MUTATION_RATE, 1.0, 0, Double.POSITIVE_INFINITY);
    GammaSiteModel siteModel = new GammaSiteModel(gtr, mu, null, 4, null);
    //treeLikelihood
    SitePatterns patterns = new SitePatterns(alignment, null, 0, -1, 1, true);
    TreeLikelihood treeLikelihood = new TreeLikelihood(patterns, treeModel, siteModel, null, null, false, false, true, false, false);
    assertEquals("treeLikelihoodGTR", format.format(-1969.14584), format.format(treeLikelihood.getLogLikelihood()));
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) SitePatterns(dr.evolution.alignment.SitePatterns) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) GTR(dr.oldevomodel.substmodel.GTR) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Parameter(dr.inference.model.Parameter)

Example 12 with FrequencyModel

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

the class LikelihoodTest method testLikelihoodHKY85I.

public void testLikelihoodHKY85I() {
    System.out.println("\nTest Likelihood using HKY85I:");
    // Sub model
    Parameter freqs = new Parameter.Default(alignment.getStateFrequencies());
    Parameter kappa = new Parameter.Default(HKYParser.KAPPA, 38.564672, 0, 100);
    FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs);
    HKY hky = new HKY(kappa, f);
    //siteModel
    Parameter mu = new Parameter.Default(GammaSiteModelParser.MUTATION_RATE, 1.0, 0, Double.POSITIVE_INFINITY);
    Parameter invar = new Parameter.Default(GammaSiteModelParser.PROPORTION_INVARIANT, 0.701211, 0, 1.0);
    GammaSiteModel siteModel = new GammaSiteModel(hky, mu, null, 4, invar);
    //treeLikelihood
    SitePatterns patterns = new SitePatterns(alignment, null, 0, -1, 1, true);
    TreeLikelihood treeLikelihood = new TreeLikelihood(patterns, treeModel, siteModel, null, null, false, false, true, false, false);
    assertEquals("treeLikelihoodHKY85I", format.format(-1789.91240), format.format(treeLikelihood.getLogLikelihood()));
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) SitePatterns(dr.evolution.alignment.SitePatterns) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) HKY(dr.oldevomodel.substmodel.HKY) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Parameter(dr.inference.model.Parameter)

Example 13 with FrequencyModel

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

the class LikelihoodTest method testLikelihoodJC69.

public void testLikelihoodJC69() {
    System.out.println("\nTest Likelihood using JC69:");
    // Sub model
    Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
    Parameter kappa = new Parameter.Default(HKYParser.KAPPA, 1.0, 0, 100);
    FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs);
    HKY hky = new HKY(kappa, f);
    //siteModel
    GammaSiteModel siteModel = new GammaSiteModel(hky);
    Parameter mu = new Parameter.Default(GammaSiteModelParser.MUTATION_RATE, 1.0, 0, Double.POSITIVE_INFINITY);
    siteModel.setMutationRateParameter(mu);
    //treeLikelihood
    SitePatterns patterns = new SitePatterns(alignment, null, 0, -1, 1, true);
    TreeLikelihood treeLikelihood = new TreeLikelihood(patterns, treeModel, siteModel, null, null, false, false, true, false, false);
    assertEquals("treeLikelihoodJC69", format.format(-1992.20564), format.format(treeLikelihood.getLogLikelihood()));
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) SitePatterns(dr.evolution.alignment.SitePatterns) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) HKY(dr.oldevomodel.substmodel.HKY) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Parameter(dr.inference.model.Parameter)

Example 14 with FrequencyModel

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

the class LewisMkSubstitutionModelParser method parseXMLObject.

//public static XMLObjectParser PARSER=new LewisMkSubstitutionModelParser();
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    DataType dataType = freqModel.getDataType();
    int k = dataType.getStateCount();
    System.err.println("Number of states " + k);
    Parameter ratesParameter;
    if (xo.hasAttribute(TOTAL_ORDER) && xo.getBooleanAttribute(TOTAL_ORDER)) {
        //TOTAL ORDERING OF THE STATES BASED ON DATATYPE
        ratesParameter = new Parameter.Default(k * (k - 1) / 2, 0);
        int j = k - 1;
        for (int i = 0; i < (k - 1) * k / 2; i = i + j + 1) {
            ratesParameter.setParameterValue(i, 1);
            j -= 1;
        }
    } else if (xo.hasChildNamed(ORDER)) {
        // USER-SPECIFIED ORDERING OF THE STATES
        ratesParameter = new Parameter.Default(k * (k - 1) / 2, 0);
        for (int i = 0; i < xo.getChildCount(); ++i) {
            if (xo.getChildName(i).equals(ORDER)) {
                cxo = (XMLObject) xo.getChild(i);
                if (cxo.getName().equals(ORDER)) {
                    int from = dataType.getState(cxo.getStringAttribute(STATE).charAt(0));
                    int to = dataType.getState(cxo.getStringAttribute(ADJACENT).charAt(0));
                    if (from > to) {
                        //SWAP: from should have the smaller state number
                        to += from;
                        from = to - from;
                        to -= from;
                    }
                    int ratesIndex = (from * (2 * k - 3) - from * from) / 2 + to - 1;
                    ratesParameter.setParameterValue(ratesIndex, 1);
                }
            }
        }
    } else {
        ratesParameter = new Parameter.Default(k * (k - 1) / 2, 1);
    }
    System.err.println(ratesParameter.toString());
    System.err.println("Infinitesimal matrix:");
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
            int from, to;
            if (i < j) {
                from = i;
                to = j;
            } else {
                from = j;
                to = i;
            }
            //This is right now!!! Thanks, Marc!
            int ratesIndex = (from * (2 * k - 3) - from * from) / 2 + to - 1;
            if (i != j)
                System.err.print(Double.toString(ratesParameter.getValue(ratesIndex)) + "\t(" + ratesIndex + ")\t");
            else
                System.err.print("-\t\t");
        }
        //newline
        System.err.println("");
    }
    System.err.println("");
    if (!checkConnected(ratesParameter.getValues(), k)) {
        throw (new XMLParseException("The state transitions form a disconnected graph! This model is not suited for this case."));
    }
    return new GeneralSubstitutionModel(dataType, freqModel, ratesParameter, 0);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) GeneralSubstitutionModel(dr.oldevomodel.substmodel.GeneralSubstitutionModel)

Example 15 with FrequencyModel

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

the class MkModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(GeneralSubstitutionModelParser.FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    DataType dataType = freqModel.getDataType();
    int rateCount = ((dataType.getStateCount() - 1) * dataType.getStateCount()) / 2 - 1;
    Parameter ratesParameter = new Parameter.Default(rateCount, 1.0);
    Logger.getLogger("dr.evolution").info("Creating an Mk substitution model with data type: " + dataType.getType() + "on " + dataType.getStateCount() + " states.");
    int relativeTo = 1;
    return new GeneralSubstitutionModel(dataType, freqModel, ratesParameter, relativeTo);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) GeneralSubstitutionModel(dr.oldevomodel.substmodel.GeneralSubstitutionModel)

Aggregations

FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)59 Parameter (dr.inference.model.Parameter)44 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)20 HKY (dr.oldevomodel.substmodel.HKY)18 SitePatterns (dr.evolution.alignment.SitePatterns)16 TreeLikelihood (dr.oldevomodel.treelikelihood.TreeLikelihood)16 DataType (dr.evolution.datatype.DataType)11 GeneralSubstitutionModel (dr.oldevomodel.substmodel.GeneralSubstitutionModel)6 ExchangeOperator (dr.evomodel.operators.ExchangeOperator)5 SubtreeSlideOperator (dr.evomodel.operators.SubtreeSlideOperator)5 WilsonBalding (dr.evomodel.operators.WilsonBalding)5 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)5 MCLogger (dr.inference.loggers.MCLogger)5 TabDelimitedFormatter (dr.inference.loggers.TabDelimitedFormatter)5 MCMC (dr.inference.mcmc.MCMC)5 MCMCOptions (dr.inference.mcmc.MCMCOptions)5 ArrayTraceList (dr.inference.trace.ArrayTraceList)5 Trace (dr.inference.trace.Trace)5 TraceCorrelation (dr.inference.trace.TraceCorrelation)5 GTR (dr.oldevomodel.substmodel.GTR)5