Efficient way to compute geometric mean of many numbers

前端 未结 7 1062
栀梦
栀梦 2020-12-14 07:12

I need to compute the geometric mean of a large set of numbers, whose values are not a priori limited. The naive way would be

double geometric_mean(std::vect         


        
7条回答
  •  [愿得一人]
    2020-12-14 07:48

    There is simple idea to reduce computation and also to prevent overflow. You can group together numbers say atleast two at time and calculate their log and then evaluate their sum.

    log(abcde) = 5*log(K)
    
    log(ab) + log(cde)  = 5*log(k)
    

提交回复
热议问题