generalized mean reimplemented