The Computational Foundations of Collective Intelligence