protected double updateAll(CorefInput input, CorefOutput outputCorrect,
			CorefOutput outputPredicted, double learningRate) {
		double loss = 0d;
		// Update all false positive and all false negative edges.
		for (int rightMention = 0; rightMention < input.getNumberOfTokens(); ++rightMention) {
			int correctClusterOfRightMention = outputCorrect
					.getClusterId(rightMention);
			int predictedClusterOfRightMention = outputPredicted
					.getClusterId(rightMention);

			// Correct and predicted left mentions in the latent structure.
			int correctLeftMention = outputCorrect.getHead(rightMention);
			int predictedLeftMention = outputPredicted.getHead(rightMention);
			if (correctLeftMention != predictedLeftMention) {
				if (predictedLeftMention == root)
					// Decrement incorrectly predicted root.
					updateFeatures(input.getFeatures(predictedLeftMention,
							rightMention), -learningRate);
				else if (correctLeftMention == root)
					// Increment correct root from latent structure.
					updateFeatures(
							input.getFeatures(correctLeftMention, rightMention),
							learningRate);
			}

			for (int leftMention = 0; leftMention < rightMention; ++leftMention) {
				// Skip artificial root mention.
				if (leftMention == root)
					continue;

				int correctClusterOfLeftMention = outputCorrect
						.getClusterId(leftMention);
				int predictedClusterOfLeftMention = outputPredicted
						.getClusterId(leftMention);
				if (correctClusterOfLeftMention != correctClusterOfRightMention) {
					if (predictedClusterOfLeftMention == predictedClusterOfRightMention)
						/*
						 * Mentions from different clusters put together in the
						 * same cluster (false positive) by the predicted
						 * structure.
						 */
						updateFeatures(
								input.getFeatures(leftMention, rightMention),
								-learningRate);
				} else {
					if (predictedClusterOfLeftMention != predictedClusterOfRightMention)
						/*
						 * Mentions from the same cluster put in different
						 * clusters (false negative) by the predicted
						 * structured.
						 */
						updateFeatures(
								input.getFeatures(leftMention, rightMention),
								learningRate);
				}
			}
		}
		return loss;
	}