Computational principles of collective intelligence