Search in sources :

Example 1 with CompoundSymmetricMatrix

use of dr.inference.model.CompoundSymmetricMatrix in project beast-mcmc by beast-dev.

the class CompoundSymmetricMatrixParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(DIAGONAL);
    Parameter diagonalParameter = (Parameter) cxo.getChild(Parameter.class);
    cxo = xo.getChild(OFF_DIAGONAL);
    Parameter offDiagonalParameter = (Parameter) cxo.getChild(Parameter.class);
    boolean asCorrelation = xo.getAttribute(AS_CORRELATION, false);
    boolean isCholesky = xo.getAttribute(IS_CHOLESKY, false);
    return new CompoundSymmetricMatrix(diagonalParameter, offDiagonalParameter, asCorrelation, isCholesky);
}
Also used : Parameter(dr.inference.model.Parameter) CompoundSymmetricMatrix(dr.inference.model.CompoundSymmetricMatrix)

Example 2 with CompoundSymmetricMatrix

use of dr.inference.model.CompoundSymmetricMatrix in project beast-mcmc by beast-dev.

the class SampledMultivariateTraitLikelihood method traitLogLikelihood.

private double traitLogLikelihood(double[] parentTrait, NodeRef node) {
    double logL = 0.0;
    double[] childTrait = treeModel.getMultivariateNodeTrait(node, traitName);
    if (parentTrait != null) {
        double time = getRescaledBranchLengthForPrecision(node);
        logL = diffusionModel.getLogLikelihood(parentTrait, childTrait, time);
        if (new Double(logL).isNaN()) {
            System.err.println("AbstractMultivariateTraitLikelihood: likelihood is undefined");
            System.err.println("time = " + time);
            System.err.println("parent trait value = " + new Vector(parentTrait));
            System.err.println("child trait value = " + new Vector(childTrait));
            double[][] precisionMatrix = diffusionModel.getPrecisionmatrix();
            if (precisionMatrix != null) {
                System.err.println("precision matrix = " + new Matrix(diffusionModel.getPrecisionmatrix()));
                if (diffusionModel.getPrecisionParameter() instanceof CompoundSymmetricMatrix) {
                    CompoundSymmetricMatrix csMatrix = (CompoundSymmetricMatrix) diffusionModel.getPrecisionParameter();
                // System.err.println("diagonals = " + new Vector(csMatrix.getDiagonals()));
                // System.err.println("off diagonal = " + csMatrix.getOffDiagonal());
                }
            }
        }
    }
    int childCount = treeModel.getChildCount(node);
    for (int i = 0; i < childCount; i++) {
        logL += traitLogLikelihood(childTrait, treeModel.getChild(node, i));
    }
    if (new Double(logL).isNaN()) {
        System.err.println("logL = " + logL);
        // System.err.println(new Matrix(diffusionModel.getPrecisionmatrix()));
        System.exit(-1);
    }
    return logL;
}
Also used : CompoundSymmetricMatrix(dr.inference.model.CompoundSymmetricMatrix) Matrix(dr.math.matrixAlgebra.Matrix) CompoundSymmetricMatrix(dr.inference.model.CompoundSymmetricMatrix) Vector(dr.math.matrixAlgebra.Vector)

Aggregations

CompoundSymmetricMatrix (dr.inference.model.CompoundSymmetricMatrix)2 Parameter (dr.inference.model.Parameter)1 Matrix (dr.math.matrixAlgebra.Matrix)1 Vector (dr.math.matrixAlgebra.Vector)1