Search in sources :

Example 26 with SymmetricMatrix

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

the class FactorIndependenceOperator method doOperation.

@Override
public double doOperation() {
    setupParameters();
    getPrecision(precision);
    double[][] variance = (new SymmetricMatrix(precision)).inverse().toComponents();
    if (randomScan) {
        int i = MathUtils.nextInt(LFM.getFactors().getColumnDimension());
        randomDraw(i, variance);
    }
    for (int i = 0; i < LFM.getFactors().getColumnDimension(); i++) {
        randomDraw(i, variance);
    }
    LFM.getFactors().fireParameterChangedEvent();
    // To change body of implemented methods use File | Settings | File Templates.
    return 0;
}
Also used : SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 27 with SymmetricMatrix

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

the class ModeIndependenceOperator method formXtXInverse.

private double[][] formXtXInverse(double[][] X) {
    int N = X.length;
    int P = X[0].length;
    double[][] matrix = new double[P][P];
    for (int i = 0; i < P; i++) {
        for (int j = 0; j < P; j++) {
            double total = 0.0;
            for (int k = 0; k < N; k++) {
                total += X[k][i] * X[k][j];
            }
            matrix[i][j] = total;
        }
    }
    // System.err.println("XtX:");
    // System.err.println(new Matrix(matrix));
    // Take inverse
    matrix = new SymmetricMatrix(matrix).inverse().toComponents();
    return matrix;
}
Also used : SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 28 with SymmetricMatrix

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

the class FactorGibbsOperator method doOperation.

@Override
public double doOperation() {
    setupParameters();
    getPrecision(precision);
    double[][] variance = (new SymmetricMatrix(precision)).inverse().toComponents();
    if (randomScan) {
        int i = MathUtils.nextInt(LFM.getFactors().getColumnDimension());
        randomDraw(i, variance);
    }
    for (int i = 0; i < LFM.getFactors().getColumnDimension(); i++) {
        randomDraw(i, variance);
    }
    LFM.getFactors().fireParameterChangedEvent();
    // To change body of implemented methods use File | Settings | File Templates.
    return 0;
}
Also used : SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 29 with SymmetricMatrix

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

the class CorrelationToCholesky method inverse.

// values = cholesky
@Override
protected double[] inverse(double[] values) {
    WrappedMatrix.WrappedUpperTriangularMatrix L = fillDiagonal(values, dimVector);
    SymmetricMatrix R = L.transposedProduct();
    return extractUpperTriangular(R);
}
Also used : WrappedMatrix(dr.math.matrixAlgebra.WrappedMatrix) SymmetricMatrix.compoundCorrelationSymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix.compoundCorrelationSymmetricMatrix) SymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix)

Example 30 with SymmetricMatrix

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

the class CorrelationToCholesky method transform.

// values = correlation
@Override
protected double[] transform(double[] values) {
    SymmetricMatrix R = compoundCorrelationSymmetricMatrix(values, dimVector);
    double[] L;
    try {
        L = (new CholeskyDecomposition(R)).getStrictlyUpperTriangular();
    } catch (IllegalDimension illegalDimension) {
        throw new RuntimeException("Unable to decompose matrix in LKJ inverse transform.");
    }
    return L;
}
Also used : CholeskyDecomposition(dr.math.matrixAlgebra.CholeskyDecomposition) IllegalDimension(dr.math.matrixAlgebra.IllegalDimension) SymmetricMatrix.compoundCorrelationSymmetricMatrix(dr.math.matrixAlgebra.SymmetricMatrix.compoundCorrelationSymmetricMatrix) 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