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

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

Introduction

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

Prototype

@Override
public BlockRealMatrix transpose() 

Source Link

Usage

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();
}

From source file:bigdataproject.MainJFrame.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    this.jLabel8.setText("");
    ReadDataSet read = new ReadDataSet();
    read.readFromFile();/* www  . j  av a2  s  .co  m*/
    read.filter();
    matrix = read.getMatrix();
    PCA pca = new PCA(matrix);
    double[][] matrix2DPCA = pca.reduceDimensions();
    BlockRealMatrix pcaMatrix = new BlockRealMatrix(matrix2DPCA);
    BlockRealMatrix pcaMatrixTranspose = pcaMatrix.transpose();
    List<DoublePoint> list = read.getCollection(read.getHashMap(pcaMatrixTranspose.getData()));
    List<Cluster<DoublePoint>> clusterList;
    if (kMeans) {
        int k;
        if (this.jCheckBox1.isSelected()) {
            KMeansKFinder kFinder = new KMeansKFinder(list);
            k = kFinder.find(0.15);
        } else
            k = (int) this.jSpinner1.getValue();
        KMeansPlusPlusClusterer kmeans = new KMeansPlusPlusClusterer(k, 1000, new EuclideanDistance());
        clusterList = kmeans.cluster(list);
    } else {
        int minPts;
        double eps;
        if (this.jCheckBox2.isSelected()) {
            minPts = 6;
            //KDistances dist = new KDistances(pcaMatrixTranspose.getData());
            //dist.calculateDistances();
            //dist.getKSortedNearestNeighbors(minPts);
            //dist.printKdistances();
            eps = 1.0;
        } else {
            minPts = (int) this.jSpinner2.getValue();
            try {
                eps = Double.parseDouble(this.jTextField1.getText());
            } catch (NumberFormatException e) {
                this.jLabel8.setText("Wrong eps Value");
                return;
            }
        }
        DBSCANClusterer dbscan = new DBSCANClusterer(eps, minPts);
        clusterList = dbscan.cluster(list);
    }
    final ScatterPlot demo = new ScatterPlot("Big Data Clustering Project", matrix2DPCA, clusterList);
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}

From source file:gamlss.smoothing.PB.java

/**
* Constructs the base matrix.//from ww  w  .  j a va2  s .c  o m
* @param colValues - values of the certain column of
*  the smooth matrix which corresponds to the 
*  currently fitting distribution parameter
* @return - base matrix
*/
//bbase <- function(x, xl, xr, ndx, deg, quantiles=FALSE)
private static BlockRealMatrix formX(final ArrayRealVector colValues) {

    //control$inter <- if (lx<99) 10 else control$inter # 
    //this is to prevent singularities when length(x) is small
    if (colValues.getDimension() < 99) {
        Controls.INTER = 10;
    }

    //xl <- min(x)
    double xl = colValues.getMinValue();

    //xr <- max(x)
    double xr = colValues.getMaxValue();

    //xmax <- xr + 0.01 * (xr - xl)
    double xmax = xr + 0.01 * (xr - xl);

    //xmin <- xl - 0.01 * (xr - xl)
    double xmin = xl - 0.01 * (xr - xl);

    //dx <- (xr - xl) / ndx
    double dx = (xmax - xmin) / Controls.INTER;

    //if (quantiles) # if true use splineDesign
    if (Controls.QUANTILES) {
        //knots <-  sort(c(seq(xl-deg*dx, xl, dx),quantile(x, 
        //prob=seq(0, 1, length=ndx)), seq(xr, xr+deg*dx, dx))) 
        ArrayRealVector kts = null;

        //B <- splineDesign(knots, x = x, outer.ok = TRUE, ord=deg+1)
        //return(B)  
        return null;
    } else {

        //kts <-   seq(xl - deg * dx, xr + deg * dx, by = dx)
        //ArrayRealVector kts = new ArrayRealVector(
        //ArithmeticSeries.getSeries(xl-deg*dx, xr+deg*dx, dx),false);

        rConnection.assingVar("min", new double[] { xmin - Controls.DEGREE * dx });
        rConnection.assingVar("max", new double[] { xmax + Controls.DEGREE * dx });
        rConnection.assingVar("step", new double[] { dx });

        ArrayRealVector kts = new ArrayRealVector(
                rConnection.runEvalDoubles("knots <- seq(min, max, by = step)"));

        //P <- outer(x, kts, FUN = tpower, deg)
        BlockRealMatrix pM = MatrixFunctions.outertpowerPB(colValues, kts, Controls.DEGREE);

        //D <- diff(diag(dim(P)[2]), 
        //diff = deg + 1) / (gamma(deg + 1) * dx ^ deg)
        BlockRealMatrix tempM = MatrixFunctions
                .diff(MatrixFunctions.buildIdentityMatrix(pM.getColumnDimension()), Controls.DEGREE + 1);

        double[][] tempArrArr = new double[tempM.getRowDimension()][tempM.getColumnDimension()];
        for (int i = 0; i < tempArrArr.length; i++) {
            for (int j = 0; j < tempArrArr[i].length; j++) {
                tempArrArr[i][j] = tempM.getEntry(i, j) / ((FastMath.exp(Gamma.logGamma(Controls.DEGREE + 1)))
                        * FastMath.pow(dx, Controls.DEGREE));
            }
        }
        tempM = new BlockRealMatrix(tempArrArr);

        //B <- (-1) ^ (deg + 1) * P %*% t(D)
        return (BlockRealMatrix) pM.multiply(tempM.transpose())
                .scalarMultiply(FastMath.pow(-1, (Controls.DEGREE + 1)));
    }
}