bestDist[j][0] = m_Distribution[j][0] / sumOfWeights[j];
if (!Utils.eq(sumOfWeights[j], 0)) { bestDist[j][0] = m_Distribution[j][0] / sumOfWeights[j]; } else { bestDist[j][0] = totalSum / totalSumOfWeights; }
  private double findSplitNominalNumeric(int index) throws Exception {    double bestVal = Double.MAX_VALUE, currVal;    double[] sumsSquaresPerValue =       new double[theInstances.attribute(index).numValues()],       sumsPerValue = new double[theInstances.attribute(index).numValues()],       weightsPerValue = new double[theInstances.attribute(index).numValues()];    double totalSumSquares = 0, totalSum = 0, totalSumOfWeights = 0;    double[] sumsSquares = new double[3], sumOfWeights = new double[3];    double[][] bestDist = new double[3][1];    // Compute counts for all the values    for (int i = 0; i < theInstances.numInstances(); i++) {      Instance inst = theInstances.instance(i);      if (inst.isMissing(index)) {	m_Distribution[2][0] += inst.classValue() * inst.weight();	sumsSquares[2] += inst.classValue() * inst.classValue() 	  * inst.weight();	sumOfWeights[2] += inst.weight();      } else {	weightsPerValue[(int)inst.value(index)] += inst.weight();	sumsPerValue[(int)inst.value(index)] += inst.classValue() 	  * inst.weight();	sumsSquaresPerValue[(int)inst.value(index)] += 	  inst.classValue() * inst.classValue() * inst.weight();      }    }    // Compute sum of counts without missing ones    for (int i = 0; i < theInstances.attribute(index).numValues(); i++) {      totalSumOfWeights += weightsPerValue[i];      totalSumSquares += sumsSquaresPerValue[i];      totalSum += sumsPerValue[i];    }        // Make split counts for each possible split and evaluate    for (int i = 0; i < theInstances.attribute(index).numValues(); i++) {            m_Distribution[0][0] = sumsPerValue[i];      sumsSquares[0] = sumsSquaresPerValue[i];      sumOfWeights[0] = weightsPerValue[i];      m_Distribution[1][0] = totalSum - sumsPerValue[i];      sumsSquares[1] = totalSumSquares - sumsSquaresPerValue[i];      sumOfWeights[1] = totalSumOfWeights - weightsPerValue[i];      currVal = variance(m_Distribution, sumsSquares, sumOfWeights);            if (Utils.sm(currVal, bestVal)) {	bestVal = currVal;	m_SplitPoint = (double)i;	for (int j = 0; j < 3; j++) {	  bestDist[j][0] = m_Distribution[j][0] / sumOfWeights[j];	}      }    }    // No missing values in training data.    if (Utils.eq(sumOfWeights[2], 0)) {      bestDist[2][0] = totalSum / totalSumOfWeights;    }    m_Distribution = bestDist;    return bestVal;  }