implement “average energy” algorithm