code: public MatrixFile calculate(Matrix input) {
          try {
              File affMatrixFile = File.createTempFile("affinty-matrix",".dat");
              PrintWriter affMatrixWriter = new PrintWriter(affMatrixFile);
              
              int rows = input.rows();
  
              // Iterate through each row, i, in the data matrix and compare row i
              // to each proceeding row, j.  If the similarity is above the edge
              // similarity threshold, emit an edge between row i and row j and
              // between row j and row i, assuming that the edge similarity metric
              // is symmetric.  Each edge is written in the Matlab Sparse matrix
              // format.
              for (int i = 0; i < rows; ++i) {
                  LOG.fine("computing affinity for row " + i);
                  DoubleVector row1 = input.getRowVector(i);
                  for (int j = i+1; j < rows; ++j) {
                      DoubleVector row2 = input.getRowVector(j);
  
                      double dataSimilarity = edgeSim.sim(row1, row2);
  
                      // If the edge similarity is above the threshold, compute
                      // the kernel similarity for each new edge.
                      if (dataSimilarity > edgeSimThreshold) {
                          double edgeWeight = kernelSim.sim(row1, row2);
                          affMatrixWriter.printf("%d %d %f\n",i+1,j+1,edgeWeight);
  
                          // If the kernel metric is symmetric, just reuse the
                          // previously calculated edge weight.  Otherwise
                          // recalculate it.
                          edgeWeight = (kernelSim.isSymmetric())
                              ? edgeWeight
                              : kernelSim.sim(row2, row1);
                          affMatrixWriter.printf("%d %d %f\n",j+1,i+1,edgeWeight);
                      }
                  }
              }
  
              affMatrixWriter.close();    
              return new MatrixFile(affMatrixFile, MatrixIO.Format.MATLAB_SPARSE);
          } catch (IOException ioe) {
              throw new IOError(ioe);
          }
      }
docs: {@inheritDoc}