From inverse problems to learning: A Statistical Mechanics approach