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);
}
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);
}
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);
}
Aggregations