Search in sources :

Example 36 with Vector

use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.

the class MarkovJumpsSubstitutionModelTest method testMarkovJumpsReward.

public void testMarkovJumpsReward() {
    HKY substModel = new HKY(2.0, new FrequencyModel(Nucleotides.INSTANCE, // A,C,G,T
    new double[] { 0.3, 0.2, 0.25, 0.25 }));
    int states = substModel.getDataType().getStateCount();
    double[] j = new double[states * states];
    double[] c = new double[states * states];
    double time = 1.0;
    MarkovJumpsSubstitutionModel markovjumps = new MarkovJumpsSubstitutionModel(substModel, MarkovJumpsType.REWARDS);
    double[] rewards = { 1.0, 1.0, 1.0, 1.0 };
    markovjumps.setRegistration(rewards);
    markovjumps.computeJointStatMarkovJumps(time, j);
    markovjumps.computeCondStatMarkovJumps(time, c);
    System.out.println("Rewards:");
    MarkovJumpsCore.makeComparableToRPackage(rewards);
    System.out.println("R = " + new Vector(rewards));
    MarkovJumpsCore.makeComparableToRPackage(j);
    System.out.println("J = " + new Vector(j));
    assertEquals(rMarkovRewardsJ, j, tolerance);
    MarkovJumpsCore.makeComparableToRPackage(c);
    System.out.println("C = " + new Vector(c));
    assertEquals(rMarkovRewardsC, c, tolerance);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) HKY(dr.evomodel.substmodel.nucleotide.HKY) Vector(dr.math.matrixAlgebra.Vector) MarkovJumpsSubstitutionModel(dr.evomodel.substmodel.MarkovJumpsSubstitutionModel)

Example 37 with Vector

use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.

the class CompleteHistorySimulatorTest method runSimulation.

protected void runSimulation(int N, Tree tree, GammaSiteRateModel siteModel, BranchRateModel branchRateModel, int nSites, double[][] registers, double analyticResult, Parameter variableParam, Parameter valuesParam) {
    CompleteHistorySimulator simulator = new CompleteHistorySimulator(tree, siteModel, branchRateModel, nSites, false, variableParam, valuesParam);
    for (int r = 0; r < registers.length; r++) {
        Parameter registerParameter = new Parameter.Default(registers[r]);
        registerParameter.setId("set" + (r + 1));
        simulator.addRegister(registerParameter, MarkovJumpsType.COUNTS, false);
    }
    int nJumps = simulator.getNumberOfJumpProcess();
    double[] results = new double[nJumps];
    for (int rep = 0; rep < N; rep++) {
        // Generate new history
        simulator.simulate();
        for (int jump = 0; jump < nJumps; jump++) {
            results[jump] += accumulateJumpsOverTree(tree, simulator, jump);
        }
    }
    for (int jump = 0; jump < nJumps; jump++) {
        results[jump] /= (double) N * (double) nSites;
    }
    if (nJumps > 0) {
        System.out.println("simulations = " + new Vector(results));
    } else {
        System.out.println("No jump processes!");
    }
    double simulationResult = accumulate(results);
    assertEquals(analyticResult, simulationResult, 1E-2);
}
Also used : Parameter(dr.inference.model.Parameter) Vector(dr.math.matrixAlgebra.Vector) CompleteHistorySimulator(dr.app.beagle.tools.CompleteHistorySimulator)

Example 38 with Vector

use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.

the class MathTestCase method printSquareMatrix.

protected void printSquareMatrix(double[] A, int dim) {
    double[] row = new double[dim];
    for (int i = 0; i < dim; i++) {
        System.arraycopy(A, i * dim, row, 0, dim);
        System.out.println(new Vector(row));
    }
}
Also used : Vector(dr.math.matrixAlgebra.Vector)

Example 39 with Vector

use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.

the class SpecificEigendecompositionTest method testEigendecomposition.

public void testEigendecomposition() {
    System.out.println("Testing specific eigendecomposition...");
    ComplexSubstitutionModel csm = setupModel(dim, testRates);
    double[] tmp = new double[dim * dim];
    csm.getInfinitesimalMatrix(tmp);
    System.out.println("Rates: " + new Vector(tmp) + "\n");
    EigenDecomposition e = csm.getEigenDecomposition();
    System.out.println("Val: " + new Vector(e.getEigenValues()));
    System.out.println("Vec: " + new Vector(e.getEigenVectors()));
    System.out.println("Inv: " + new Vector(e.getInverseEigenVectors()));
    csm.getTransitionProbabilities(1.0, tmp);
    System.out.println(new Vector(tmp));
    double[] eigenValues = e.getEigenValues();
    Arrays.sort(eigenValues);
    assertEquals(checkEigenvalues, e.getEigenValues(), tolerance);
}
Also used : Vector(dr.math.matrixAlgebra.Vector)

Aggregations

Vector (dr.math.matrixAlgebra.Vector)39 Matrix (dr.math.matrixAlgebra.Matrix)12 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)9 Parameter (dr.inference.model.Parameter)6 NodeRef (dr.evolution.tree.NodeRef)5 WishartSufficientStatistics (dr.math.distributions.WishartSufficientStatistics)5 MarkovJumpsSubstitutionModel (dr.evomodel.substmodel.MarkovJumpsSubstitutionModel)4 HKY (dr.evomodel.substmodel.nucleotide.HKY)4 EigenDecomposition (dr.evomodel.substmodel.EigenDecomposition)3 DataType (dr.evolution.datatype.DataType)2 StateHistory (dr.inference.markovjumps.StateHistory)2 MultivariateNormalDistribution (dr.math.distributions.MultivariateNormalDistribution)2 IllegalDimension (dr.math.matrixAlgebra.IllegalDimension)2 CompleteHistorySimulator (dr.app.beagle.tools.CompleteHistorySimulator)1 ComplexSubstitutionModel (dr.evomodel.substmodel.ComplexSubstitutionModel)1 GeneralSubstitutionModel (dr.evomodel.substmodel.GeneralSubstitutionModel)1 ProductChainFrequencyModel (dr.evomodel.substmodel.ProductChainFrequencyModel)1 UniformizedSubstitutionModel (dr.evomodel.substmodel.UniformizedSubstitutionModel)1 TN93 (dr.evomodel.substmodel.nucleotide.TN93)1 ContinuousDiffusionIntegrator (dr.evomodel.treedatalikelihood.continuous.cdi.ContinuousDiffusionIntegrator)1