Search in sources :

Example 26 with DefaultBranchRateModel

use of dr.evomodel.branchratemodel.DefaultBranchRateModel in project beast-mcmc by beast-dev.

the class DiffusionGradientTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    delta = 1E-2;
    dimTrait = 6;
    Parameter offDiagonal = new Parameter.Default(new double[] { 0.12, -0.13, 0.14, -0.15, 0.16, -0.12, 0.13, -0.14, 0.15, 0.12, -0.13, 0.14, -0.12, 0.13, 0.12 });
    offDiagonal.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, dimTrait * (dimTrait - 1) / 2));
    Parameter diagonal = new Parameter.Default(new double[] { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 });
    precisionMatrix = new CompoundSymmetricMatrix(diagonal, offDiagonal, true, true);
    Parameter diagonalVar = new Parameter.Default(new double[] { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 });
    precisionMatrixInv = new CachedMatrixInverse("var", new CompoundSymmetricMatrix(diagonalVar, offDiagonal, true, false));
    diffusionModel = new MultivariateDiffusionModel(precisionMatrix);
    diffusionModelVar = new MultivariateDiffusionModel(precisionMatrixInv);
    // Data
    Parameter[] dataTraits = new Parameter[6];
    dataTraits[0] = new Parameter.Default("human", new double[] { -1.0, 2.0, 3.0, 4.0, 5.0, -6.0 });
    dataTraits[1] = new Parameter.Default("chimp", new double[] { 10.0, 12.0, 14.0, 16.0, 18.0, 20.0 });
    dataTraits[2] = new Parameter.Default("bonobo", new double[] { 0.5, -2.0, 5.5, -5.2, 3.1, 1.1 });
    dataTraits[3] = new Parameter.Default("gorilla", new double[] { 2.0, 5.0, -8.0, -4.0, 3.2, 3.4 });
    dataTraits[4] = new Parameter.Default("orangutan", new double[] { 11.0, 1.0, -1.5, 2.4, -4.2, 6.0 });
    dataTraits[5] = new Parameter.Default("siamang", new double[] { 1.0, 2.5, 4.0, 4.0, -5.2, 1.0 });
    traitParameter = new CompoundParameter("trait", dataTraits);
    traitParameter.setParameterValue(2, 0);
    missingIndices.add(6);
    missingIndices.add(7);
    missingIndices.add(8);
    missingIndices.add(9);
    missingIndices.add(10);
    missingIndices.add(11);
    missingIndices.add(13);
    missingIndices.add(15);
    missingIndices.add(25);
    missingIndices.add(29);
    // Tree
    createAlignment(PRIMATES_TAXON_SEQUENCE, Nucleotides.INSTANCE);
    treeModel = createPrimateTreeModel();
    // Rates
    rateTransformation = new ContinuousRateTransformation.Default(treeModel, false, false);
    rateModel = new DefaultBranchRateModel();
    // // Standard Model //// ***************************************************************************************
    PrecisionType precisionType = PrecisionType.FULL;
    // Root prior
    final double rootVal = fixedRoot ? Double.POSITIVE_INFINITY : 0.1;
    Parameter rootVar = new Parameter.Default("rootVar", rootVal);
    Parameter[] meanRootList = new Parameter[dimTrait];
    double[] meanRootVal = new double[] { -1.0, -3.0, 2.5, -2.5, 1.3, 4.0 };
    for (int i = 0; i < dimTrait; i++) {
        meanRootList[i] = new Parameter.Default("meanRoot." + (i + 1), meanRootVal[i]);
    }
    meanRoot = new CompoundParameter("rootMean", meanRootList);
    rootPrior = new ConjugateRootTraitPrior(meanRoot, rootVar);
    // Data Model
    dataModelMissing = new ContinuousTraitDataModel("dataModel", traitParameter, missingIndices, true, 6, precisionType);
    dataModel = new ContinuousTraitDataModel("dataModel", traitParameter, missingIndices, false, 6, precisionType);
    // // Factor Model //// *****************************************************************************************
    // Error model
    Parameter factorPrecisionParameters = new Parameter.Default("factorPrecision", new double[] { 1.0, 5.0, 0.5, 0.1, 0.2, 0.3 });
    // Loadings
    Parameter[] loadingsParameters = new Parameter[2];
    loadingsParameters[0] = new Parameter.Default(new double[] { 1.0, 2.0, 3.0, 0.0, 0.0, 0.0 });
    loadingsParameters[1] = new Parameter.Default(new double[] { 0.0, 0.0, 0.0, 0.0, 0.5, 1.0 });
    MatrixParameterInterface loadingsMatrixParameters = new MatrixParameter("loadings", loadingsParameters);
    dataModelFactor = new IntegratedFactorAnalysisLikelihood("dataModelFactors", traitParameter, missingIndices, loadingsMatrixParameters, factorPrecisionParameters, 0.0, null);
    // // Repeated Measures Model //// *****************************************************************************************
    Parameter offDiagonalSampling = new Parameter.Default(new double[] { 0.16, -0.15, 0.14, -0.13, 0.12, -0.15, 0.14, -0.13, 0.12, 0.0, 0.0, 0.0, -0.13, 0.12, 0.0 });
    offDiagonalSampling.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, dimTrait * (dimTrait - 1) / 2));
    Parameter diagonalSampling = new Parameter.Default(new double[] { 0.1, 0.2, 0.3, 0.2, 0.1, 0.01 });
    samplingPrecision = new CompoundSymmetricMatrix(diagonalSampling, offDiagonalSampling, true, true);
    Parameter diagonalVarSampling = new Parameter.Default(new double[] { 10.0, 20.0, 30.0, 20.0, 10.0, 100.0 });
    samplingPrecisionInv = new CachedMatrixInverse("samplingVar", new CompoundSymmetricMatrix(diagonalVarSampling, offDiagonalSampling, true, false));
    dataModelRepeatedMeasures = new RepeatedMeasuresTraitDataModel("dataModelRepeatedMeasures", traitParameter, missingIndices, true, dimTrait, samplingPrecision);
    dataModelRepeatedMeasuresInv = new RepeatedMeasuresTraitDataModel("dataModelRepeatedMeasuresInv", traitParameter, missingIndices, true, dimTrait, samplingPrecisionInv);
}
Also used : PrecisionType(dr.evomodel.treedatalikelihood.continuous.cdi.PrecisionType) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) MultivariateDiffusionModel(dr.evomodel.continuous.MultivariateDiffusionModel) DerivationParameter(dr.evomodel.treedatalikelihood.continuous.ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter)

Example 27 with DefaultBranchRateModel

use of dr.evomodel.branchratemodel.DefaultBranchRateModel in project beast-mcmc by beast-dev.

the class VariableBranchCompleteHistorySimulatorTest method testHKYVariableSimulation.

public void testHKYVariableSimulation() {
    System.out.println("Starting HKY variable branch simulation");
    Parameter kappa = new Parameter.Default(1, 2.0);
    double[] pi = { 0.45, 0.05, 0.25, 0.25 };
    Parameter freqs = new Parameter.Default(pi);
    FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs);
    HKY hky = new HKY(kappa, f);
    int stateCount = hky.getDataType().getStateCount();
    Parameter mu = new Parameter.Default(1, 0.5);
    Parameter alpha = new Parameter.Default(1, 0.5);
    GammaSiteRateModel siteModel = new GammaSiteRateModel("gammaModel", mu, alpha, 4, null);
    siteModel.setSubstitutionModel(hky);
    BranchRateModel branchRateModel = new DefaultBranchRateModel();
    double analyticResult = TreeUtils.getTreeLength(tree, tree.getRoot()) * mu.getParameterValue(0);
    int nSites = 200;
    double[] register1 = new double[stateCount * stateCount];
    double[] register2 = new double[stateCount * stateCount];
    // Count all jumps
    MarkovJumpsCore.fillRegistrationMatrix(register1, stateCount);
    // Move some jumps from 1 to 2
    register1[1 * stateCount + 2] = 0;
    register2[1 * stateCount + 2] = 1;
    register1[1 * stateCount + 3] = 0;
    register2[1 * stateCount + 3] = 1;
    register1[2 * stateCount + 3] = 0;
    register2[2 * stateCount + 3] = 1;
    double[] branchValues = { 10.0, 10.0, 10.0, 10.0, 10.0 };
    Parameter branchValuesParam = new Parameter.Default(branchValues);
    runSimulation(N, tree, siteModel, branchRateModel, nSites, new double[][] { register1, register2 }, analyticResult, kappa, branchValuesParam);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) HKY(dr.evomodel.substmodel.nucleotide.HKY) Parameter(dr.inference.model.Parameter) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel)

Example 28 with DefaultBranchRateModel

use of dr.evomodel.branchratemodel.DefaultBranchRateModel in project beast-mcmc by beast-dev.

the class ContinuousTraitTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    dimTrait = 3;
    format.setMaximumFractionDigits(5);
    // Tree
    createAlignment(PRIMATES_TAXON_SEQUENCE, Nucleotides.INSTANCE);
    treeModel = createPrimateTreeModel();
    // Rates
    rateTransformation = new ContinuousRateTransformation.Default(treeModel, false, false);
    rateModel = new DefaultBranchRateModel();
    // Data
    nTips = 6;
    Parameter[] dataTraits = new Parameter[6];
    dataTraits[0] = new Parameter.Default("human", new double[] { -1.0, 2.0, 3.0 });
    dataTraits[1] = new Parameter.Default("chimp", new double[] { 10.0, 12.0, 14.0 });
    dataTraits[2] = new Parameter.Default("bonobo", new double[] { 0.5, -2.0, 5.5 });
    dataTraits[3] = new Parameter.Default("gorilla", new double[] { 2.0, 5.0, -8.0 });
    dataTraits[4] = new Parameter.Default("orangutan", new double[] { 11.0, 1.0, -1.5 });
    dataTraits[5] = new Parameter.Default("siamang", new double[] { 1.0, 2.5, 4.0 });
    traitParameter = new CompoundParameter("trait", dataTraits);
    List<Integer> missingIndices = new ArrayList<Integer>();
    traitParameter.setParameterValue(2, 0);
    missingIndices.add(3);
    missingIndices.add(4);
    missingIndices.add(5);
    missingIndices.add(7);
    // // Standard Model //// ***************************************************************************************
    // Diffusion
    Parameter[] precisionParameters = new Parameter[dimTrait];
    precisionParameters[0] = new Parameter.Default(new double[] { 1.0, 0.1, 0.2 });
    precisionParameters[1] = new Parameter.Default(new double[] { 0.1, 2.0, 0.0 });
    precisionParameters[2] = new Parameter.Default(new double[] { 0.2, 0.0, 3.0 });
    MatrixParameterInterface diffusionPrecisionMatrixParameter = new MatrixParameter("precisionMatrix", precisionParameters);
    diffusionModel = new MultivariateDiffusionModel(diffusionPrecisionMatrixParameter);
    PrecisionType precisionType = PrecisionType.FULL;
    // Root prior
    Parameter rootMean = new Parameter.Default(new double[] { -1.0, -3.0, 2.5 });
    Parameter rootSampleSize = new Parameter.Default(10.0);
    rootPrior = new ConjugateRootTraitPrior(rootMean, rootSampleSize);
    // Root prior Inf
    Parameter rootMeanInf = new Parameter.Default(new double[] { -1.0, -3.0, 2.0 });
    Parameter rootSampleSizeInf = new Parameter.Default(Double.POSITIVE_INFINITY);
    rootPriorInf = new ConjugateRootTraitPrior(rootMeanInf, rootSampleSizeInf);
    // Data Model
    dataModel = new ContinuousTraitDataModel("dataModel", traitParameter, missingIndices, true, dimTrait, precisionType);
    // // Factor Model //// *****************************************************************************************
    // Diffusion
    Parameter offDiagonal = new Parameter.Default(new double[] { 0.08164966 });
    offDiagonal.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1));
    Parameter diagonal = new Parameter.Default(new double[] { 1.0, 1.5 });
    precisionMatrixFactor = new CompoundSymmetricMatrix(diagonal, offDiagonal, true, true);
    diffusionModelFactor = new MultivariateDiffusionModel(precisionMatrixFactor);
    // Root prior
    rootMeanFactor = new Parameter.Default(new double[] { -1.0, 2.0 });
    Parameter rootSampleSizeFac = new Parameter.Default(10.0);
    rootPriorFactor = new ConjugateRootTraitPrior(rootMeanFactor, rootSampleSizeFac);
    // Error model
    Parameter factorPrecisionParameters = new Parameter.Default("factorPrecision", new double[] { 1.0, 5.0, 0.5 });
    // Loadings
    Parameter[] loadingsParameters = new Parameter[2];
    loadingsParameters[0] = new Parameter.Default(new double[] { 1.0, 2.0, 3.0 });
    loadingsParameters[1] = new Parameter.Default(new double[] { 0.0, 0.5, 1.0 });
    MatrixParameterInterface loadingsMatrixParameters = new MatrixParameter("loadings", loadingsParameters);
    dataModelFactor = new IntegratedFactorAnalysisLikelihood("dataModelFactors", traitParameter, missingIndices, loadingsMatrixParameters, factorPrecisionParameters, 0.0, null);
    // // Integrated Process //// ***********************************************************************************
    // Data Model
    dataModelIntegrated = new IntegratedProcessTraitDataModel("dataModelIntegrated", traitParameter, missingIndices, true, dimTrait, precisionType);
    // Root prior
    String sI = "<beast>\n" + "    <conjugateRootPrior>\n" + "        <meanParameter>\n" + "            <parameter id=\"meanRoot\"  value=\"0.0 1.2 -0.5 -1.0 -3.0 2.5\"/>\n" + "        </meanParameter>\n" + "        <priorSampleSize>\n" + "            <parameter id=\"sampleSizeRoot\" value=\"10.0\"/>\n" + "        </priorSampleSize>\n" + "    </conjugateRootPrior>\n" + "</beast>";
    XMLParser parserI = new XMLParser(true, true, true, null);
    parserI.addXMLObjectParser(new AttributeParser());
    parserI.addXMLObjectParser(new ParameterParser());
    parserI.parse(new StringReader(sI), true);
    rootPriorIntegrated = ConjugateRootTraitPrior.parseConjugateRootTraitPrior(parserI.getRoot(), 2 * dimTrait);
}
Also used : ArrayList(java.util.ArrayList) PrecisionType(dr.evomodel.treedatalikelihood.continuous.cdi.PrecisionType) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) MultivariateDiffusionModel(dr.evomodel.continuous.MultivariateDiffusionModel) StringReader(java.io.StringReader) XMLParser(dr.xml.XMLParser) AttributeParser(dr.xml.AttributeParser)

Aggregations

DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)28 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)26 Parameter (dr.inference.model.Parameter)19 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)16 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)16 ArrayList (java.util.ArrayList)15 Tree (dr.evolution.tree.Tree)11 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)11 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)11 Partition (dr.app.beagle.tools.Partition)9 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)8 NewickImporter (dr.evolution.io.NewickImporter)8 HKY (dr.evomodel.substmodel.nucleotide.HKY)8 ImportException (dr.evolution.io.Importer.ImportException)7 IOException (java.io.IOException)7 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)6 TreeModel (dr.evomodel.tree.TreeModel)6 BranchModel (dr.evomodel.branchmodel.BranchModel)5 TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)5 Sequence (dr.evolution.sequence.Sequence)4