tempSorted = Utils.sortUnsafe(tempDist);
tempSorted = Utils.sort(tempDist);
  private void updateWeightsNumericClass (int instNum) {    int i, j;    double temp,temp2;    int[] tempSorted = null;    double[] tempDist = null;    double distNorm = 1.0;    int firstI, secondI;    Instance inst = m_trainInstances.instance(instNum);       // sort nearest neighbours and set up normalization variable    if (m_weightByDistance) {      tempDist = new double[m_stored[0]];      for (j = 0, distNorm = 0; j < m_stored[0]; j++) {	// copy the distances	tempDist[j] = m_karray[0][j][0];	// sum normalizer	distNorm += m_weightsByRank[j];      }      tempSorted = Utils.sortUnsafe(tempDist);    }    for (i = 0; i < m_stored[0]; i++) {      // P diff prediction (class) given nearest instances      if (m_weightByDistance) {	temp = difference(m_classIndex, 			  inst.value(m_classIndex),			  m_trainInstances.			  instance((int)m_karray[0][tempSorted[i]][1]).			  value(m_classIndex));	temp *= (m_weightsByRank[i]/distNorm);      }      else {	temp = difference(m_classIndex, 			  inst.value(m_classIndex), 			  m_trainInstances.			  instance((int)m_karray[0][i][1]).			  value(m_classIndex));	temp *= (1.0/(double)m_stored[0]); // equal influence      }      m_ndc += temp;      Instance cmp;      cmp = (m_weightByDistance) 	? m_trainInstances.instance((int)m_karray[0][tempSorted[i]][1])	: m_trainInstances.instance((int)m_karray[0][i][1]);       double temp_diffP_diffA_givNearest = 	difference(m_classIndex, inst.value(m_classIndex),		   cmp.value(m_classIndex));      // now the attributes      for (int p1 = 0, p2 = 0; 	   p1 < inst.numValues() || p2 < cmp.numValues();) {	if (p1 >= inst.numValues()) {	  firstI = m_trainInstances.numAttributes();	} else {	  firstI = inst.index(p1); 	}	if (p2 >= cmp.numValues()) {	  secondI = m_trainInstances.numAttributes();	} else {	  secondI = cmp.index(p2);	}	if (firstI == m_trainInstances.classIndex()) {	  p1++; continue;	} 	if (secondI == m_trainInstances.classIndex()) {	  p2++; continue;	} 	temp = 0.0;	temp2 = 0.0;      	if (firstI == secondI) {	  j = firstI;	  temp = difference(j, inst.valueSparse(p1), cmp.valueSparse(p2)); 	  p1++;p2++;	} else if (firstI > secondI) {	  j = secondI;	  temp = difference(j, 0, cmp.valueSparse(p2));	  p2++;	} else {	  j = firstI;	  temp = difference(j, inst.valueSparse(p1), 0);	  p1++;	}        	temp2 = temp_diffP_diffA_givNearest * temp; 	// P of different prediction and different att value given	// nearest instances	if (m_weightByDistance) {	  temp2 *= (m_weightsByRank[i]/distNorm);	}	else {	  temp2 *= (1.0/(double)m_stored[0]); // equal influence	}	m_ndcda[j] += temp2;       	// P of different attribute val given nearest instances	if (m_weightByDistance) {	  temp *= (m_weightsByRank[i]/distNorm);	}	else {	  temp *= (1.0/(double)m_stored[0]); // equal influence	}	m_nda[j] += temp;      }    }  }