public static void lineSearch(Instances instances, Function1D func) {
		double[] predictions = func.getPredictions();
		double[] numerator = new double[predictions.length];
		double[] denominator = new double[numerator.length];
		for (Instance instance : instances) {
			int idx = func.getSegmentIndex(instance);
			numerator[idx] += instance.getTarget() * instance.getWeight();
			double t = Math.abs(instance.getTarget());
			denominator[idx] += t * (1 - t) * instance.getWeight();
		}
		for (int i = 0; i < predictions.length; i++) {
			predictions[i] = denominator[i] == 0 ? 0 : numerator[i] / denominator[i];
		}
	}