Theoretical foundations of multitask learning and metalearning