Search in sources :

Example 1 with SingularValueDecomposition

use of cern.colt.matrix.linalg.SingularValueDecomposition in project beast-mcmc by beast-dev.

the class GeneralizedLinearModelParser method checkFullRank.

private void checkFullRank(DesignMatrix designMatrix) throws XMLParseException {
    int fullRank = designMatrix.getColumnDimension();
    //        System.err.println("designMatrix getColumnDimension = "+fullRank);
    SingularValueDecomposition svd = new SingularValueDecomposition(new DenseDoubleMatrix2D(designMatrix.getParameterAsMatrix()));
    int realRank = svd.rank();
    if (realRank != fullRank) {
        throw new XMLParseException("rank(" + designMatrix.getId() + ") = " + realRank + ".\nMatrix is not of full rank as colDim(" + designMatrix.getId() + ") = " + fullRank);
    }
}
Also used : DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) SingularValueDecomposition(cern.colt.matrix.linalg.SingularValueDecomposition)

Example 2 with SingularValueDecomposition

use of cern.colt.matrix.linalg.SingularValueDecomposition in project beast-mcmc by beast-dev.

the class GeneralizedLinearModel method getAllIndependentVariablesIdentifiable.

public boolean getAllIndependentVariablesIdentifiable() {
    int totalColDim = 0;
    for (DesignMatrix mat : designMatrix) {
        totalColDim += mat.getColumnDimension();
    }
    double[][] grandDesignMatrix = new double[N][totalColDim];
    int offset = 0;
    for (DesignMatrix mat : designMatrix) {
        final int length = mat.getColumnDimension();
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < length; ++j) {
                grandDesignMatrix[i][offset + j] = mat.getParameterValue(i, j);
            }
        }
        offset += length;
    }
    double[][] mat = grandDesignMatrix;
    if (grandDesignMatrix.length < grandDesignMatrix[0].length) {
        mat = new double[grandDesignMatrix[0].length][grandDesignMatrix.length];
        for (int i = 0; i < grandDesignMatrix.length; ++i) {
            for (int j = 0; j < grandDesignMatrix[i].length; ++j) {
                mat[j][i] = grandDesignMatrix[i][j];
            }
        }
    }
    SingularValueDecomposition svd = new SingularValueDecomposition(new DenseDoubleMatrix2D(mat));
    int rank = svd.rank();
    boolean isFullRank = (totalColDim == rank);
    Logger.getLogger("dr.inference").info("\tTotal # of predictors = " + totalColDim + " and rank = " + rank);
    return isFullRank;
}
Also used : DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) SingularValueDecomposition(cern.colt.matrix.linalg.SingularValueDecomposition)

Example 3 with SingularValueDecomposition

use of cern.colt.matrix.linalg.SingularValueDecomposition in project beast-mcmc by beast-dev.

the class GeneralizedLinearModel method getAllIndependentVariablesIdentifiable.

public boolean getAllIndependentVariablesIdentifiable() {
    int totalColDim = 0;
    for (DesignMatrix mat : designMatrix) {
        totalColDim += mat.getColumnDimension();
    }
    double[][] grandDesignMatrix = new double[N][totalColDim];
    int offset = 0;
    for (DesignMatrix mat : designMatrix) {
        final int length = mat.getColumnDimension();
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < length; ++j) {
                grandDesignMatrix[i][offset + j] = mat.getParameterValue(i, j);
            }
        }
        offset += length;
    }
    double[][] mat = grandDesignMatrix;
    if (grandDesignMatrix.length < grandDesignMatrix[0].length) {
        mat = new double[grandDesignMatrix[0].length][grandDesignMatrix.length];
        for (int i = 0; i < grandDesignMatrix.length; ++i) {
            for (int j = 0; j < grandDesignMatrix[i].length; ++j) {
                mat[j][i] = grandDesignMatrix[i][j];
            }
        }
    }
    SingularValueDecomposition svd = new SingularValueDecomposition(new DenseDoubleMatrix2D(mat));
    int rank = svd.rank();
    boolean isFullRank = (totalColDim == rank);
    Logger.getLogger("dr.inference").info("\tTotal # of predictors = " + totalColDim + " and rank = " + rank);
    return isFullRank;
}
Also used : DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) SingularValueDecomposition(cern.colt.matrix.linalg.SingularValueDecomposition)

Example 4 with SingularValueDecomposition

use of cern.colt.matrix.linalg.SingularValueDecomposition in project beast-mcmc by beast-dev.

the class GeneralizedLinearModelParser method checkFullRank.

private void checkFullRank(DesignMatrix designMatrix) throws XMLParseException {
    int fullRank = designMatrix.getColumnDimension();
    //        System.err.println("designMatrix getColumnDimension = "+fullRank);
    SingularValueDecomposition svd = new SingularValueDecomposition(new DenseDoubleMatrix2D(designMatrix.getParameterAsMatrix()));
    int realRank = svd.rank();
    if (realRank != fullRank) {
        throw new XMLParseException("rank(" + designMatrix.getId() + ") = " + realRank + ".\nMatrix is not of full rank as colDim(" + designMatrix.getId() + ") = " + fullRank);
    }
}
Also used : DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) SingularValueDecomposition(cern.colt.matrix.linalg.SingularValueDecomposition)

Aggregations

DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)4 SingularValueDecomposition (cern.colt.matrix.linalg.SingularValueDecomposition)4