Utils.normalize(temp);
double sum = Utils.sum(temp); if (sum <= 0) { for (int j = 0; j < temp.length; j++) { temp[j] = 1.0 / (double)temp.length; } } else { Utils.normalize(temp, sum); }
  public double [] distributionForInstance(Instance instance)     throws Exception {    double [] dist = new double[m_NumClasses];    double [] temp = new double[m_NumClasses];    double totalWeight = 0.0;    double weight = 1.0;    for (int i = 0; i < instance.numAttributes(); i++) {      if (i != m_ClassIndex && !instance.isMissing(i)) {	double val = instance.value(i);	boolean ok = false;	if (instance.attribute(i).isNumeric()) {	  int k;	  for (k = m_intervalBounds[i].length-1; k >= 0; k--) {	    if (val > m_intervalBounds[i][k]) {	      for (int j = 0; j < m_NumClasses; j++) {		if (m_globalCounts[j] > 0) {		  temp[j] = ((m_counts[i][k][j]+TINY) / 			     (m_globalCounts[j]+TINY));		}	      }	      ok = true;	      break;	    } else if (val == m_intervalBounds[i][k]) {	      for (int j = 0; j < m_NumClasses; j++) {		if (m_globalCounts[j] > 0) {		  temp[j] = ((m_counts[i][k][j] + m_counts[i][k-1][j]) / 2.0) +		    TINY;		  temp[j] /= (m_globalCounts[j]+TINY);		}	      }	      ok = true;	      break;	    }	  }	  if (!ok) {	    throw new Exception("This shouldn't happen");	  }	} else { // nominal attribute	  ok = true;	  for (int j = 0; j < m_NumClasses; j++) {	    if (m_globalCounts[j] > 0) {	      temp[j] = ((m_counts[i][(int)val][j]+TINY) / 			 (m_globalCounts[j]+TINY));	    }	  }	  	}	Utils.normalize(temp);	if (m_weightByConfidence) {	  weight = weka.core.ContingencyTables.entropy(temp);	  weight = Math.pow(weight, m_bias);	  if (weight < 1.0) {	    weight = 1.0;	  }	}	for (int j = 0; j < m_NumClasses; j++) {	  dist[j] += (temp[j] * weight);	}      }    }       Utils.normalize(dist);    return dist;  }