implemented part of the gradient ascent algorithm