private void compute() {


    double[] inputFace = new double[length];
    int nrfaces = eigVector.length;
    int MAGIC_NR = wk[0].length;
    int j, pix, image;

    computed = false;
    System.arraycopy(cmpFace,0,inputFace,0,length);

    for ( pix = 0; pix < inputFace.length; pix++) {
        inputFace[pix] = inputFace[pix] - avgFace[pix];
    }

    //System.out.println(nrfaces+" "+inputFace.length);
    double[] input_wk = new double[MAGIC_NR];
    double temp = 0;
    /* Subtract the image from the average image */
    for (j = 0; j < MAGIC_NR; j++) {
      temp = 0.0;
      for ( pix=0; pix <length; pix++)
        temp += eigVector[j][pix] * inputFace[pix];

      input_wk[j] = Math.abs( temp );
    }

    /*
     * Find the minimun distance from the input_wk as compared to wk
     */


    double[] distance = new double[MAGIC_NR];
    double[] minDistance = new double[MAGIC_NR];
    idx = 0;
    for (image = 0; image < nrfaces; image++) {
        temp = 0.0;
        for (j = 0; j < MAGIC_NR; j++) {
          distance[j] = Math.abs(input_wk[j] - wk[image][j]);
          //System.out.print(distance[j]+"\t");
        }
        //System.out.println();
        if (image == 0)
          System.arraycopy(distance,0,minDistance,0,MAGIC_NR);
        if (sum(minDistance) > sum(distance)) {

          this.idx = image;
          System.arraycopy(distance,0,minDistance,0,MAGIC_NR);
        }
    }


    /*
     * Normalize our minimum distance.
     */

    if (max(minDistance) > 0.0)
      divide(minDistance, max(minDistance));

    minD = sum(minDistance);

    computed = true;


  }