include "NSLog.incl" double local fn Square( d as double ) end fn = d * d double local fn AverageSquareDiff( d as double, predictions as CFArrayRef ) double sum = 0.0 for CFNumberRef num in predictions sum += fn Square( fn NumberDoubleValue( num ) - d ) next return sum / fn ArrayCount( predictions ) end fn = 0.0 CFStringRef local fn DiversityTheorem( truth as double, predictions as CFArrayRef ) double average = fn NumberDoubleValue( fn ObjectValueForKeyPath( predictions, @"@avg.self" ) ) CFStringRef avgErr = fn StringWithFormat( @"%4.5f", fn AverageSquareDiff( truth, predictions ) ) CFStringRef crowdErr = fn StringWithFormat( @"%6.5f", fn Square( truth - average ) ) CFStringRef diversity = fn StringWithFormat( @"%6.5f", fn AverageSquareDiff( average, predictions ) ) return fn StringWithFormat( @"Average error : %@\nCrowd error : %@\nDiversity : %@\n", avgErr, crowdErr, diversity ) end fn = NULL NSLog( @"Diversity prediction with crowd estimates of 48, 47 and 51:" ) NSLog( @"%@\n", fn DiversityTheorem( 49.0, @[@48.0, @47.0, @51.0] ) ) NSLog( @"Diversity prediction with crowd estimates of 48, 47, 51 and 42:" ) NSLog( @"%@\n", fn DiversityTheorem( 49.0, @[@48.0, @47.0, @51.0, @42.0] ) ) HandleEvents