code: @Override
  	public double calculateExpectedDisagreement() {
  		ensureDistanceFunction();
  
  		BigDecimal result = BigDecimal.ZERO;
  		Map<Object, int[]> annotationsPerCategory
  				= CodingAnnotationStudy.countAnnotationsPerCategory(study);
  
  		double maxDistance = 1.0;
  		for (Object category1 : study.getCategories())
  			for (Object category2 : study.getCategories()) {
  				int[] annotationCounts1 = annotationsPerCategory.get(category1);
  				int[] annotationCounts2 = annotationsPerCategory.get(category2);
  				for (int m = 0; m < study.getRaterCount(); m++)
  					for (int n = m + 1; n < study.getRaterCount(); n++) {
  						double distance = distanceFunction.measureDistance(study, category1, category2);
  						result = result.add(
  								new BigDecimal(annotationCounts1[m]).multiply(
  								new BigDecimal(annotationCounts2[n]).multiply(
  								new BigDecimal(distance)
  								)));
  						if (distance > maxDistance)
  							maxDistance = distance;
  					}
  			}
  
  		result = result.divide(new BigDecimal(study.getItemCount()).pow(2).multiply(
  				new BigDecimal(maxDistance)), MathContext.DECIMAL128);
  		return result.doubleValue();
  	}
docs: Calculates the expected inter-rater agreement using the defined
  distance function to infer the assumed probability distribution.
  @throws NullPointerException if the annotation study is null.
  @throws ArithmeticException if there are no items or raters in the
  annotation study.