Learning, Inference and Control of Multi-Agent Systems