Most neural optimization algorithms use either gradient tuning methods or complicated recurrent dynamics that may lead to suboptimal solutions or require huge number of iterations. Here we propose a framework based on the cross-entropy method (CEM). CEM is an efficient global optimization technique, but it requires batch access to many samples. We transcribed CEM to an online form and embedded it into a reconstruction network that finds optimal representations in a robust way as demonstrated by computer simulations. We argue that this framework allows for neural implementation and suggests a novel computational role for spikes in real neuronal systems.