List of usage examples for weka.core.matrix SingularValueDecomposition getU
public Matrix getU()
From source file:edu.stanford.rsl.apps.gui.roi.ComputeIndependentComponents.java
License:Open Source License
@Override public Object evaluate() { double[][] signals = null; if (roi.getMask() == null) { signals = new double[numChannels][roi.getBounds().height * roi.getBounds().width]; for (int j = 0; j < roi.getBounds().height; j++) { for (int i = 0; i < roi.getBounds().width; i++) { int x = roi.getBounds().x + i; int y = roi.getBounds().y + j; for (int k = 0; k < numChannels; k++) { signals[k][(j * roi.getBounds().width) + i] = ((MultiChannelGrid2D) multiGrid.getSubGrid(currentImage)).getChannel(k) .getPixelValue(x, y); }//from w w w .ja v a2s . c o m } } } else { // Count pixels in mask int count = 0; ByteProcessor mask = (ByteProcessor) roi.getMask(); for (int j = 0; j < roi.getBounds().height; j++) { for (int i = 0; i < roi.getBounds().width; i++) { if (mask.getPixel(i, j) == 255) { count++; } } } signals = new double[numChannels][count]; int index = 0; for (int j = 0; j < roi.getBounds().height; j++) { for (int i = 0; i < roi.getBounds().width; i++) { int x = roi.getBounds().x + i; int y = roi.getBounds().y + j; if (mask.getPixel(i, j) == 255) { for (int k = 0; k < numChannels; k++) { signals[k][index] = ((MultiChannelGrid2D) multiGrid.getSubGrid(currentImage)) .getChannel(k).getPixelValue(x, y); } index++; } } } } try { double[][] vectors = null; if (operation.equals(ICA)) { FastICA ica = new FastICA(signals, numChannels); vectors = ica.getICVectors(); } if (operation.equals(PCA)) { org.fastica.PCA pca = new org.fastica.PCA(signals); vectors = org.fastica.math.Matrix.mult(pca.getEigenVectors(), pca.getVectorsZeroMean()); for (int k = 0; k < numChannels; k++) { System.out.println("Eigen Value " + k + " " + pca.getEigenValues()[k]); } } if (operation.equals(SVD)) { weka.core.matrix.SingularValueDecomposition svd = new weka.core.matrix.SingularValueDecomposition( new Matrix(signals).transpose()); vectors = svd.getU().transpose().getArray(); for (int k = 0; k < numChannels; k++) { System.out.println("Singular Value " + k + " " + svd.getSingularValues()[k]); } } ByteProcessor mask = (ByteProcessor) roi.getMask(); MultiChannelGrid2D out = new MultiChannelGrid2D(roi.getBounds().width, roi.getBounds().height, numChannels); if (roi.getMask() == null) { for (int j = 0; j < roi.getBounds().height; j++) { for (int i = 0; i < roi.getBounds().width; i++) { for (int k = 0; k < numChannels; k++) { out.getChannel(k).putPixelValue(i, j, vectors[k][(j * roi.getBounds().width) + i]); } } } } else { int index = 0; for (int j = 0; j < roi.getBounds().height; j++) { for (int i = 0; i < roi.getBounds().width; i++) { if (mask.getPixel(i, j) == 255) { for (int k = 0; k < numChannels; k++) { out.getChannel(k).putPixelValue(i, j, vectors[k][index]); } index++; } } } } out.show("Components using" + operation); } catch (FastICAException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }