Example usage for org.apache.commons.math3.linear BlockRealMatrix setColumnVector

List of usage examples for org.apache.commons.math3.linear BlockRealMatrix setColumnVector

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear BlockRealMatrix setColumnVector.

Prototype

@Override
public void setColumnVector(final int column, final RealVector vector)
        throws OutOfRangeException, MatrixDimensionMismatchException 

Source Link

Usage

From source file:gamlss.utilities.MatrixFunctions.java

/**
 * Multiply vector with every row of the matrix.
 * @param v - vector// w w  w.  j  av  a  2s  .c  o m
 * @param m - matrix
 * @return v*m
 */
public static BlockRealMatrix multVectorMatrix(final ArrayRealVector v, final BlockRealMatrix m) {

    BlockRealMatrix tempM = new BlockRealMatrix(m.getRowDimension(), m.getColumnDimension());
    for (int i = 0; i < m.getColumnDimension(); i++) {
        tempM.setColumnVector(i, v.ebeMultiply(m.getColumnVector(i)));
    }
    return tempM;
}

From source file:bigdataproject.PCA.java

public double[][] reduceDimensions() {
    BlockRealMatrix matrix = new BlockRealMatrix(dataSet);
    Covariance cov = new Covariance(matrix, false);
    RealMatrix covarianceMatrix = cov.getCovarianceMatrix();
    EigenDecomposition dec = new EigenDecomposition(covarianceMatrix);
    RealVector principalEigenVector = dec.getEigenvector(0);
    RealVector secondEigenVector = dec.getEigenvector(1);
    BlockRealMatrix pca = new BlockRealMatrix(principalEigenVector.getDimension(), 2);
    pca.setColumnVector(0, principalEigenVector);
    pca.setColumnVector(1, secondEigenVector);
    BlockRealMatrix pcaTranspose = pca.transpose();
    BlockRealMatrix columnVectorMatrix = matrix.transpose();
    BlockRealMatrix matrix2D = pcaTranspose.multiply(columnVectorMatrix);
    return matrix2D.getData();
}