Diversity prediction theorem

From Rosetta Code
Revision as of 13:18, 3 December 2016 by rosettacode>Aloisdg (Init page with typescript)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Draft

The wisdom of the crowd is the collective opinion of a group of individuals rather than that of a single expert.

Wisdom-of-the-crowds research routinely attributes the superiority of crowd averages over individual judgments to the elimination of individual noise, an explanation that assumes independence of the individual judgments from each other. Thus the crowd tends to make its best decisions if it is made up of diverse opinions and ideologies.

Scott E. Page introduced the diversity prediction theorem: "The squared error of the collective prediction equals the average squared error minus the predictive diversity". Therefore, when the diversity in a group is large, the error of the crowd is small.

- Average Individual Error: Average of the individual squared errors

- Collective Error: Squared error of the collective prediction

- Prediction Diversity: Average squared distance from the individual predictions to the collective prediction

So, The Diversity Prediction Theorem: Given a crowd of predictive models

Collective Error = Average Individual Error - Prediction Diversity

wikipedia paper



TypeScript

<lang TypeScript> function sum(array: Array<number>): number {

   return array.reduce((a, b) => a + b)

}

function square(x : number) :number {

   return x * x

}

function mean(array: Array<number>): number {

   return sum(array) / array.length

}

function averageSquareDiff(a: number, predictions: Array<number>): number {

   return mean(predictions.map(x => square(x - a)))

}

function diversityTheorem(truth: number, predictions: Array<number>): Object {

   const average: number = mean(predictions)
   return {
       "average-error": averageSquareDiff(truth, predictions),
       "crowd-error": square(truth - average),
       "diversity": averageSquareDiff(average, predictions)
   }

}

console.log(diversityTheorem(49, [48,47,51])) console.log(diversityTheorem(49, [48,47,51,42])) </lang>

Output:
{ 'average-error': 3,
  'crowd-error': 0.11111111111111269,
  diversity: 2.888888888888889 }
{ 'average-error': 14.5, 'crowd-error': 4, diversity: 10.5 }