Machine learning using magnetic stochastic synapses