protected static double computeCHistograms(Instances instances, boolean[] used, CHistogram[] cHist) {
		double ySq = 0;
		// compute histogram
		for (Instance instance : instances) {
			double resp = instance.getTarget();
			for (int j = 0; j < instances.getAttributes().size(); j++) {
				if (used[j]) {
					int idx = (int) instance.getValue(j);
					cHist[j].sum[idx] += resp * instance.getWeight();
					cHist[j].count[idx] += instance.getWeight();
				}
			}
			ySq += resp * resp * instance.getWeight();
		}
		// compute cumulative histogram
		for (int j = 0; j < cHist.length; j++) {
			if (used[j]) {
				for (int idx = 1; idx < cHist[j].size(); idx++) {
					cHist[j].sum[idx] += cHist[j].sum[idx - 1];
					cHist[j].count[idx] += cHist[j].count[idx - 1];
				}
			}
		}
		return ySq;
	}