Learning capacity and function of stochastic reaction networks