Identification and optimization of stochastic systems