code: public static void byCorrelation(Matrix m, boolean saveNegatives) {
          double totalSum = 0;
  
          // Generate the total value in each row and column.
          double[] rowSums = new double[m.rows()];
          double[] colSums = new double[m.columns()];
          for (int i = 0; i < m.rows(); ++i) {
              for (int j = 0; j < m.columns(); ++j) {
                  totalSum += m.get(i,j);
                  colSums[j] += m.get(i,j);
                  rowSums[i] += m.get(i,j);
              }
          }
  
          // Use the row and column totals to compute the correlation.
          for (int i = 0; i < m.rows(); ++i) {
              for (int j = 0; j< m.columns(); ++j) {
                  double newVal =
                      (totalSum * m.get(i,j) - rowSums[i] * colSums[j]) /
                      Math.sqrt(rowSums[i] * (totalSum - rowSums[i]) *
                                colSums[j] * (totalSum - colSums[j]));
  
                  // Store the computed value.
                  if (saveNegatives)
                      m.set(i,j, newVal);
                  else
                      m.set(i,j, newVal > 0 ? newVal : 0);
              }
          }
      }
docs: Normalize the values of the {@code Matrix} by using the Pearson
  correlation.  This will give values between -1 and 1.  If {@code
  saveNegatives} is is {@code true}, negative correlations will be saved,
  and otherwise they are reduced to zero.
  
  @param m The {@code Matrix} to normalize.
  @param saveNegatives If true, save all values, even if they are negative.