Variational learning for quantum artificial neural networks