rename error function to errorsquare function
fix a bug in momentum