Search in sources :

Example 21 with SymmetricMatrix

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

the class LKJTransformTest method testTransformation.

public void testTransformation() {
    System.out.println("\nTest LKJ transform.");
    double[] transformedValue = transform.inverse(CPCs, 0, CPCs.length);
    double[] inverseTransformedValues = transform.transform(transformedValue, 0, transformedValue.length);
    SymmetricMatrix R = compoundCorrelationSymmetricMatrix(transformedValue, dim);
    System.out.println("transformedValue=" + R);
    try {
        assertTrue("Positive Definite", R.isPD());
    } catch (IllegalDimension illegalDimension) {
        illegalDimension.printStackTrace();
    }
    System.out.println("iCPC=" + new Matrix(inverseTransformedValues, dim * (dim - 1) / 2, 1));
    assertEquals("size CPCs", format.format(CPCs.length), format.format(inverseTransformedValues.length));
    for (int k = 0; k < CPCs.length; k++) {
        assertEquals("inverse transform k=" + k, format.format(CPCs[k]), format.format(inverseTransformedValues[k]));
    }
}
Also used : SymmetricMatrix.compoundCorrelationSymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix.compoundCorrelationSymmetricMatrix) SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix) Matrix(dr.math.matrixAlgebra.Matrix) IllegalDimension(dr.math.matrixAlgebra.IllegalDimension) SymmetricMatrix.compoundCorrelationSymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix.compoundCorrelationSymmetricMatrix) SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 22 with SymmetricMatrix

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

the class GaussianProcessFromTree method nextRandomFast.

// boolean firstTime=true;
public double[] nextRandomFast() {
    double[] random = new double[traitModel.getTreeModel().getExternalNodeCount() * traitModel.getDimTrait()];
    NodeRef root = traitModel.getTreeModel().getRoot();
    double[] traitStart = traitModel.getPriorMean();
    double[][] varianceCholesky = null;
    double[][] temp = new SymmetricMatrix(traitModel.getDiffusionModel().getPrecisionmatrix()).inverse().toComponents();
    try {
        varianceCholesky = (new CholeskyDecomposition(temp).getL());
    } catch (IllegalDimension illegalDimension) {
        illegalDimension.printStackTrace();
    }
    // }
    if (USE_BUFFER) {
        final int length = traitModel.getDimTrait();
        final int nodeCount = traitModel.getTreeModel().getNodeCount();
        double[] currentValue = new double[(nodeCount + 1) * length];
        double[] epsilon = new double[length];
        final int priorOffset = nodeCount * length;
        System.arraycopy(traitStart, 0, currentValue, priorOffset, length);
        nextRandomFast2(currentValue, priorOffset, root, random, varianceCholesky, epsilon);
    } else {
        nextRandomFast(traitStart, root, random, varianceCholesky);
    }
    // }
    return random;
}
Also used : CholeskyDecomposition(dr.math.matrixAlgebra.CholeskyDecomposition) NodeRef(dr.evolution.tree.NodeRef) IllegalDimension(dr.math.matrixAlgebra.IllegalDimension) SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 23 with SymmetricMatrix

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

the class PrecisionMatrixGibbsOperator method setupWishartStatistics.

private void setupWishartStatistics(WishartStatistics priorDistribution) {
    this.priorDf = priorDistribution.getDF();
    this.priorInverseScaleMatrix = null;
    double[][] scale = priorDistribution.getScaleMatrix();
    if (scale != null)
        this.priorInverseScaleMatrix = (SymmetricMatrix) (new SymmetricMatrix(scale)).inverse();
}
Also used : SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 24 with SymmetricMatrix

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

the class CorrelationMatrixGibbsOperator method setupWishartStatistics.

private void setupWishartStatistics(WishartStatistics priorDistribution) {
    this.priorDf = priorDistribution.getDF();
    this.priorInverseScaleMatrix = null;
    double[][] scale = priorDistribution.getScaleMatrix();
    if (scale != null)
        this.priorInverseScaleMatrix = (SymmetricMatrix) (new SymmetricMatrix(scale)).inverse();
}
Also used : SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 25 with SymmetricMatrix

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

the class CorrelationMatrixGibbsOperator method getOperationScaleMatrixAndSetObservationCount2.

private double[][] getOperationScaleMatrixAndSetObservationCount2() {
    // calculate sum-of-the-weighted-squares matrix over tree
    double[][] S = new double[dim][dim];
    SymmetricMatrix S2;
    SymmetricMatrix inverseS2 = null;
    // Need to reset, as incrementOuterProduct can be recursive
    numberObservations = 0;
    // todo zy: outer product
    incrementOuterProductWithRescale(S, conjugateWishartProvider);
    try {
        S2 = new SymmetricMatrix(S);
        if (priorInverseScaleMatrix != null) {
            // todo zy: new inverse scale matrix = prior inverse scale +
            S2 = priorInverseScaleMatrix.add(S2);
        // outer product. S2 in add(S2) is the outer produt
        }
        inverseS2 = (SymmetricMatrix) S2.inverse();
    } catch (IllegalDimension illegalDimension) {
        illegalDimension.printStackTrace();
    }
    assert inverseS2 != null;
    return inverseS2.toComponents();
}
Also used : IllegalDimension(dr.math.matrixAlgebra.IllegalDimension) SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Aggregations

SymmetricMatrix (dr.math.matrixAlgebra.SymmetricMatrix)30 IllegalDimension (dr.math.matrixAlgebra.IllegalDimension)12 SymmetricMatrix.compoundCorrelationSymmetricMatrix (dr.math.matrixAlgebra.SymmetricMatrix.compoundCorrelationSymmetricMatrix)9 Matrix (dr.math.matrixAlgebra.Matrix)7 NormalDistribution (dr.math.distributions.NormalDistribution)4 CholeskyDecomposition (dr.math.matrixAlgebra.CholeskyDecomposition)3 NodeRef (dr.evolution.tree.NodeRef)2 MomentDistributionModel (dr.inference.distribution.MomentDistributionModel)2 WrappedMatrix (dr.math.matrixAlgebra.WrappedMatrix)2 Vector (dr.math.matrixAlgebra.Vector)1