code: public void computeBasis() {
  		if (sampleIndex != numSamples)
  			throw new IllegalArgumentException("Not all the data has been added");
  		if (numComponents > numSamples)
  			throw new IllegalArgumentException(
  					"More data needed to compute the desired number of components");
  
  		means = new DenseMatrix64F(sampleSize, 1);
  		// compute the mean of all the samples
  		for (int i = 0; i < numSamples; i++) {
  			for (int j = 0; j < sampleSize; j++) {
  				double val = means.get(j);
  				means.set(j, val + A.get(i, j));
  			}
  		}
  		for (int j = 0; j < sampleSize; j++) {
  			double avg = means.get(j) / numSamples;
  			means.set(j, avg);
  		}
  
  		// subtract the mean from the original data
  		for (int i = 0; i < numSamples; i++) {
  			for (int j = 0; j < sampleSize; j++) {
  				A.set(i, j, A.get(i, j) - means.get(j));
  			}
  		}
  
  		// compute SVD and save time by not computing U
  		SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(numSamples, sampleSize,
  				false, true, compact);
  		if (!svd.decompose(A))
  			throw new RuntimeException("SVD failed");
  
  		V_t = svd.getV(null, true);
  		W = svd.getW(null);
  
  		// singular values are in an arbitrary order initially and need to be sorted in descending order
  		SingularOps.descendingOrder(null, false, W, V_t, true);
  
  		// strip off unneeded components and find the basis
  		V_t.reshape(numComponents, sampleSize, true);
  
  	}
docs: Computes a basis (the principle components) from the most dominant eigenvectors.