added calculation of expected value and basic gradient, i.e. without regularization