calculate expectation