Search in sources :

Example 31 with Vector

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

the class ComplexSubstitutionModel method printLastProbabilityMatrix.

public void printLastProbabilityMatrix() {
    getLogLikelihood();
    System.err.println((probability == null) ? "Null probability vector" : "Not null probability vector");
    if (probability == null) {
        boolean test = BayesianStochasticSearchVariableSelection.Utils.connectedAndWellConditioned(probability, this);
        System.err.println("BSSVS valid = " + test);
    }
    System.err.println(new Vector(probability));
}
Also used : Vector(dr.math.matrixAlgebra.Vector)

Example 32 with Vector

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

the class HKY method main.

public static void main(String[] args) {
    //        double kappa = 2.0;
    //        double[] pi = new double[]{0.15,0.30,0.20,0.35};
    //        double time = 0.1;
    double kappa = 1.0;
    double[] pi = new double[] { 0.25, 0.25, 0.25, 0.25 };
    double time = 0.1;
    FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, pi);
    HKY hky = new HKY(kappa, freqModel);
    EigenDecomposition decomp = hky.getEigenDecomposition();
    //        Matrix evec = new Matrix(decomp.getEigenVectors());
    //        Matrix ivec = new Matrix(decomp.getInverseEigenVectors());
    //        System.out.println("Evec =\n"+evec);
    //        System.out.println("Ivec =\n"+ivec);
    Vector eval = new Vector(decomp.getEigenValues());
    System.out.println("Eval = " + eval);
    double[] probs = new double[16];
    hky.getTransitionProbabilities(time, probs);
    System.out.println("new probs = " + new Vector(probs));
    // check against old implementation
    dr.oldevomodel.substmodel.FrequencyModel oldFreq = new dr.oldevomodel.substmodel.FrequencyModel(Nucleotides.INSTANCE, pi);
    dr.oldevomodel.substmodel.HKY oldHKY = new dr.oldevomodel.substmodel.HKY(kappa, oldFreq);
    oldHKY.setKappa(kappa);
    oldHKY.getTransitionProbabilities(time, probs);
    System.out.println("old probs = " + new Vector(probs));
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) EigenDecomposition(dr.evomodel.substmodel.EigenDecomposition) Vector(dr.math.matrixAlgebra.Vector)

Example 33 with Vector

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

the class WishartStatisticsWrapper method simulateMissingTraits.

private void simulateMissingTraits() {
    // Force new sample!
    likelihoodDelegate.fireModelChanged();
    //        ProcessSimulationDelegate.MeanAndVariance mv =
    //                (ProcessSimulationDelegate.MeanAndVariance) tipFullConditionalTrait.getTrait(
    //                        dataLikelihood.getTree(), dataLikelihood.getTree().getExternalNode(1));
    //
    //        System.err.println("DONE");
    //        System.exit(-1);
    double[] sample = (double[]) tipSampleTrait.getTrait(dataLikelihood.getTree(), null);
    if (DEBUG) {
        System.err.println("Attempting to simulate missing traits");
        System.err.println(new Vector(sample));
    }
    final ContinuousDiffusionIntegrator cdi = outerProductDelegate.getIntegrator();
    assert (cdi instanceof ContinuousDiffusionIntegrator.Basic);
    double[] buffer = new double[dimPartial * numTrait];
    for (int trait = 0; trait < numTrait; ++trait) {
        buffer[trait * dimPartial + dimTrait] = Double.POSITIVE_INFINITY;
    }
    for (int tip = 0; tip < tipCount; ++tip) {
        int sampleOffset = tip * dimTrait * numTrait;
        int bufferOffset = 0;
        for (int trait = 0; trait < numTrait; ++trait) {
            System.arraycopy(sample, sampleOffset, buffer, bufferOffset, dimTrait);
            sampleOffset += dimTrait;
            bufferOffset += dimPartial;
        }
        outerProductDelegate.setTipDataDirectly(tip, buffer);
    }
    if (DEBUG) {
        System.err.println("Finished draw");
    }
}
Also used : ContinuousDiffusionIntegrator(dr.evomodel.treedatalikelihood.continuous.cdi.ContinuousDiffusionIntegrator) Vector(dr.math.matrixAlgebra.Vector)

Example 34 with Vector

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

the class KernelDensityEstimator2D method main.

public static void main(String[] arg) {
    double[] x = { 3.4, 1.2, 5.6, 2.2, 3.1 };
    double[] y = { 1.0, 2.0, 1.0, 2.0, 1.0 };
    KernelDensityEstimator2D kde = new KernelDensityEstimator2D(x, y, 4);
    System.out.println(new Vector(kde.getXGrid()));
    System.out.println(new Vector(kde.getYGrid()));
    System.out.println(new Matrix(kde.getKDE()));
    System.exit(-1);
}
Also used : Matrix(dr.math.matrixAlgebra.Matrix) Vector(dr.math.matrixAlgebra.Vector)

Example 35 with Vector

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

the class MarkovJumpsSubstitutionModelTest method testMarkovJumpsCounts.

public void testMarkovJumpsCounts() {
    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();
    MarkovJumpsSubstitutionModel markovjumps = new MarkovJumpsSubstitutionModel(substModel, MarkovJumpsType.COUNTS);
    double[] r = new double[states * states];
    double[] q = new double[states * states];
    double[] j = new double[states * states];
    double[] c = new double[states * states];
    double[] p = new double[states * states];
    double time = 1.0;
    // A
    int from = 0;
    // C
    int to = 1;
    MarkovJumpsCore.fillRegistrationMatrix(r, from, to, states, 1.0);
    markovjumps.setRegistration(r);
    substModel.getInfinitesimalMatrix(q);
    substModel.getTransitionProbabilities(time, p);
    markovjumps.computeJointStatMarkovJumps(time, j);
    markovjumps.computeCondStatMarkovJumps(time, c);
    MarkovJumpsCore.makeComparableToRPackage(q);
    System.out.println("Q = " + new Vector(q));
    MarkovJumpsCore.makeComparableToRPackage(p);
    System.out.println("P = " + new Vector(p));
    System.out.println("Counts:");
    MarkovJumpsCore.makeComparableToRPackage(r);
    System.out.println("R = " + new Vector(r));
    MarkovJumpsCore.makeComparableToRPackage(j);
    System.out.println("J = " + new Vector(j));
    assertEquals(rMarkovJumpsJ, j, tolerance);
    MarkovJumpsCore.makeComparableToRPackage(c);
    System.err.println("C = " + new Vector(c));
    assertEquals(rMarkovJumpsC, 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)

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