Program: 92559
Project: 92559
Buggy source:
/** 
 * Constructor.
 * @param data the dataset.
 * @param d the dimension of the manifold.
 * @param k k-nearest neighbor.
 */
public LLE(double[][] data,int d,int k){
  int n=data.length;
  int D=data[0].length;
  double tol=0.0;
  if (k > D) {
    logger.info("String_Node_Str");
    tol=1E-3;
  }
  KNNSearch<double[],double[]> knn=null;
  if (D < 10) {
    knn=new KDTree<>(data,data);
  }
 else {
    knn=new CoverTree<>(data,new EuclideanDistance());
  }
  Comparator<Neighbor<double[],double[]>> comparator=new Comparator<Neighbor<double[],double[]>>(){
    @Override public int compare(    Neighbor<double[],double[]> o1,    Neighbor<double[],double[]> o2){
      return o1.index - o2.index;
    }
  }
;
  int[][] N=new int[n][k];
  graph=new AdjacencyList(n);
  for (int i=0; i < n; i++) {
    Neighbor<double[],double[]>[] neighbors=knn.knn(data[i],k);
    Arrays.sort(neighbors,comparator);
    for (int j=0; j < k; j++) {
      graph.setWeight(i,neighbors[j].index,neighbors[j].distance);
      N[i][j]=neighbors[j].index;
    }
  }
  int[][] cc=graph.bfs();
  int[] newIndex=new int[n];
  if (cc.length == 1) {
    index=new int[n];
    for (int i=0; i < n; i++) {
      index[i]=i;
      newIndex[i]=i;
    }
  }
 else {
    n=0;
    int component=0;
    for (int i=0; i < cc.length; i++) {
      if (cc[i].length > n) {
        component=i;
        n=cc[i].length;
      }
    }
    logger.info("String_Node_Str",cc.length,n);
    index=cc[component];
    graph=graph.subgraph(index);
    for (int i=0; i < index.length; i++) {
      newIndex[index[i]]=i;
    }
  }
  int len=n * (k + 1);
  double[] w=new double[len];
  int[] rowIndex=new int[len];
  int[] colIndex=new int[n + 1];
  for (int i=1; i <= n; i++) {
    colIndex[i]=colIndex[i - 1] + k + 1;
  }
  DenseMatrix C=Matrix.zeros(k,k);
  double[] b=new double[k];
  for (int i=0; i < k; i++) {
    b[i]=1.0;
  }
  int m=0;
  for (  int i : index) {
    double trace=0.0;
    for (int p=0; p < k; p++) {
      for (int q=0; q < k; q++) {
        C.set(p,q,0.0);
        for (int l=0; l < D; l++) {
          C.add(p,q,(data[i][l] - data[N[i][p]][l]) * (data[i][l] - data[N[i][q]][l]));
        }
      }
      trace+=C.get(p,p);
    }
    if (tol != 0.0) {
      trace*=tol;
      for (int p=0; p < k; p++) {
        C.add(p,p,trace);
      }
    }
    LU lu=C.lu(true);
    lu.solve(b);
    double sum=Math.sum(b);
    int shift=0;
    for (int p=0; p < k; p++) {
      if (newIndex[N[i][p]] > m && shift == 0) {
        shift=1;
        w[m * (k + 1) + p]=1.0;
        rowIndex[m * (k + 1) + p]=m;
      }
      w[m * (k + 1) + p + shift]=-b[p] / sum;
      rowIndex[m * (k + 1) + p + shift]=newIndex[N[i][p]];
    }
    if (shift == 0) {
      w[m * (k + 1) + k]=1.0;
      rowIndex[m * (k + 1) + k]=m;
    }
    m++;
  }
  SparseMatrix W=new SparseMatrix(n,n,w,rowIndex,colIndex);
  SparseMatrix M=W.aat();
  M.setSymmetric(true);
  EVD eigen=M.eigen(n - 1);
  coordinates=new double[n][d];
  for (int j=0; j < d; j++) {
    for (int i=0; i < n; i++) {
      coordinates[i][j]=eigen.getEigenVectors().get(i,n - j - 2);
    }
  }
}

Fixed version (ground truth):
/** 
 * Constructor.
 * @param data the dataset.
 * @param d the dimension of the manifold.
 * @param k k-nearest neighbor.
 */
public LLE(double[][] data,int d,int k){
  int n=data.length;
  int D=data[0].length;
  double tol=0.0;
  if (k > D) {
    logger.info("String_Node_Str");
    tol=1E-3;
  }
  KNNSearch<double[],double[]> knn=null;
  if (D < 10) {
    knn=new KDTree<>(data,data);
  }
 else {
    knn=new CoverTree<>(data,new EuclideanDistance());
  }
  Comparator<Neighbor<double[],double[]>> comparator=new Comparator<Neighbor<double[],double[]>>(){
    @Override public int compare(    Neighbor<double[],double[]> o1,    Neighbor<double[],double[]> o2){
      return o1.index - o2.index;
    }
  }
;
  int[][] N=new int[n][k];
  graph=new AdjacencyList(n);
  for (int i=0; i < n; i++) {
    Neighbor<double[],double[]>[] neighbors=knn.knn(data[i],k);
    Arrays.sort(neighbors,comparator);
    for (int j=0; j < k; j++) {
      graph.setWeight(i,neighbors[j].index,neighbors[j].distance);
      N[i][j]=neighbors[j].index;
    }
  }
  int[][] cc=graph.bfs();
  int[] newIndex=new int[n];
  if (cc.length == 1) {
    index=new int[n];
    for (int i=0; i < n; i++) {
      index[i]=i;
      newIndex[i]=i;
    }
  }
 else {
    n=0;
    int component=0;
    for (int i=0; i < cc.length; i++) {
      if (cc[i].length > n) {
        component=i;
        n=cc[i].length;
      }
    }
    logger.info("String_Node_Str",cc.length,n);
    index=cc[component];
    graph=graph.subgraph(index);
    for (int i=0; i < index.length; i++) {
      newIndex[index[i]]=i;
    }
  }
  int len=n * (k + 1);
  double[] w=new double[len];
  int[] rowIndex=new int[len];
  int[] colIndex=new int[n + 1];
  for (int i=1; i <= n; i++) {
    colIndex[i]=colIndex[i - 1] + k + 1;
  }
  DenseMatrix C=Matrix.zeros(k,k);
  double[] b=new double[k];
  int m=0;
  for (  int i : index) {
    double trace=0.0;
    for (int p=0; p < k; p++) {
      for (int q=0; q < k; q++) {
        C.set(p,q,0.0);
        for (int l=0; l < D; l++) {
          C.add(p,q,(data[i][l] - data[N[i][p]][l]) * (data[i][l] - data[N[i][q]][l]));
        }
      }
      trace+=C.get(p,p);
    }
    if (tol != 0.0) {
      trace*=tol;
      for (int p=0; p < k; p++) {
        C.add(p,p,trace);
      }
    }
    Arrays.fill(b,1.0);
    LU lu=C.lu(true);
    lu.solve(b);
    double sum=Math.sum(b);
    int shift=0;
    for (int p=0; p < k; p++) {
      if (newIndex[N[i][p]] > m && shift == 0) {
        shift=1;
        w[m * (k + 1) + p]=1.0;
        rowIndex[m * (k + 1) + p]=m;
      }
      w[m * (k + 1) + p + shift]=-b[p] / sum;
      rowIndex[m * (k + 1) + p + shift]=newIndex[N[i][p]];
    }
    if (shift == 0) {
      w[m * (k + 1) + k]=1.0;
      rowIndex[m * (k + 1) + k]=m;
    }
    m++;
  }
  SparseMatrix W=new SparseMatrix(n,n,w,rowIndex,colIndex);
  SparseMatrix M=W.aat();
  M.setSymmetric(true);
  EVD eigen=M.eigen(n - 1);
  coordinates=new double[n][d];
  for (int j=0; j < d; j++) {
    for (int i=0; i < n; i++) {
      coordinates[i][j]=eigen.getEigenVectors().get(i,n - j - 2);
    }
  }
}