private void mergeNewValues(boolean force, double compression) { if (totalWeight == 0 && unmergedWeight == 0) { // seriously nothing to do return; } if (force || unmergedWeight > 0) { // note that we run the merge in reverse every other merge to avoid left-to-right bias in merging merge(tempMean, tempWeight, tempUsed, tempData, order, unmergedWeight, useAlternatingSort & mergeCount % 2 == 1, compression); mergeCount++; tempUsed = 0; unmergedWeight = 0; if (data != null) { tempData = new ArrayList<>(); } } }
private void add(double[] m, double[] w, int count, List<List<Double>> data) { if (m.length != w.length) { throw new IllegalArgumentException("Arrays not same length"); } if (m.length < count + lastUsedCell) { // make room to add existing centroids double[] m1 = new double[count + lastUsedCell]; System.arraycopy(m, 0, m1, 0, count); m = m1; double[] w1 = new double[count + lastUsedCell]; System.arraycopy(w, 0, w1, 0, count); w = w1; } double total = 0; for (int i = 0; i < count; i++) { total += w[i]; } merge(m, w, count, data, null, total, false, compression); }