The Stochastic Replica Approach to Machine Learning: Stability and Parameter Optimization