Nonparametric Density Estimation for Stochastic Optimization with an Observable State Variable