double g = 0;
double N = 0;
double xvalues[] = new double[dataValues.length()];
for(int i = 0; i < dataValues.length(); i++){
ITuple T = (ITuple) dataValues.get(i);
xvalues[i] = ((INumber) T.get(0)).toReal().doubleValue();
}
// Create a natural ranking: largest first.
double rank[] = new NaturalRanking().rank(xvalues);
for(int i = 0; i < rank.length; i++){
rank[i] = rank.length - rank[i] + 1; // invert the ranking: smallest come now first.
//System.err.println("rank[" + i + "] = " + rank[i]);
}
for(int i = 0; i < dataValues.length(); i++){
ITuple T = (ITuple) dataValues.get(i);
double Y = ((INumber) T.get(1)).toReal().doubleValue();
if(Y < 0)
throw RuntimeExceptionFactory.illegalArgument(T, null, null, "Frequency should be positive");
g += xvalues[i] * rank[i] * Y;
N += Y;