List of usage examples for org.apache.commons.math3.linear BlockRealMatrix getData
@Override public double[][] getData()
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:com.clust4j.algo.preprocess.PCA.java
@Override public double[][] transform(double[][] data) { checkFit();// w w w. ja va 2s .c om MatUtils.checkDimsForUniformity(data); double[][] x = this.centerer.transform(data); // use block because it's faster for multiplication of potentially large matrices BlockRealMatrix X = new BlockRealMatrix(x); BlockRealMatrix transformed = X.multiply(this.components.transpose()); return transformed.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();/* w w w. j a va 2 s.c o 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); }