这是否有区别:
average = (x1+x2)/2; deviation1 = x1 -average; deviation2 = x2 -average; variance = deviation1*deviation1 + deviation2*deviation2;和这个:
average2 = (x1+x2); deviation1 = 2*x1 -average2; deviation2 = 2*x2 -average2; variance = (deviation1*deviation1 + deviation2*deviation2) / 4;请注意,在第二个版本中,我试图尽可能延迟分部。 第二个版本[延迟分割]是否会提高总体精度?
上面的代码片段仅作为示例,我并不试图优化此特定代码段。
顺便说一句,我在询问有关部门的一般情况,不仅仅是2或2的幂,因为他们减少到IEEE 754表示的简单转换。 我用2分开,只是用一个非常简单的例子来说明这个问题。
Is there a difference between this:
average = (x1+x2)/2; deviation1 = x1 -average; deviation2 = x2 -average; variance = deviation1*deviation1 + deviation2*deviation2;and this:
average2 = (x1+x2); deviation1 = 2*x1 -average2; deviation2 = 2*x2 -average2; variance = (deviation1*deviation1 + deviation2*deviation2) / 4;Note that in the second version I am trying to delay division as late as possible. Does the second version [delay divisions] increase accuracy in general?
Snippet above is only intended as an example, I am not trying to optimize this particular snippet.
BTW, I am asking about division in general, not just by 2 or a power of 2 as they reduce to simple shifts in IEEE 754 representation. I took division by 2, just to illustrate the issue using a very simple example.
最满意答案
没有什么可以从中获得。 你只是在改变规模,但是在你的计算中你不会得到更有意义的数字。
维基百科有关方差的文章以高水平解释了计算方差的一些选项。
There's nothing to be gained from this. You are only changing the scale but you'd don't get any more significant figures in your calculation.
The Wikipedia article on variance explains at a high level some of the options for calculation variance in a robust fashion.
浮点除法与乘法的精度差异(Difference in accuracy with floating point division vs multiplication)这是否有区别:
average = (x1+x2)/2; deviation1 = x1 -average; deviation2 = x2 -average; variance = deviation1*deviation1 + deviation2*deviation2;和这个:
average2 = (x1+x2); deviation1 = 2*x1 -average2; deviation2 = 2*x2 -average2; variance = (deviation1*deviation1 + deviation2*deviation2) / 4;请注意,在第二个版本中,我试图尽可能延迟分部。 第二个版本[延迟分割]是否会提高总体精度?
上面的代码片段仅作为示例,我并不试图优化此特定代码段。
顺便说一句,我在询问有关部门的一般情况,不仅仅是2或2的幂,因为他们减少到IEEE 754表示的简单转换。 我用2分开,只是用一个非常简单的例子来说明这个问题。
Is there a difference between this:
average = (x1+x2)/2; deviation1 = x1 -average; deviation2 = x2 -average; variance = deviation1*deviation1 + deviation2*deviation2;and this:
average2 = (x1+x2); deviation1 = 2*x1 -average2; deviation2 = 2*x2 -average2; variance = (deviation1*deviation1 + deviation2*deviation2) / 4;Note that in the second version I am trying to delay division as late as possible. Does the second version [delay divisions] increase accuracy in general?
Snippet above is only intended as an example, I am not trying to optimize this particular snippet.
BTW, I am asking about division in general, not just by 2 or a power of 2 as they reduce to simple shifts in IEEE 754 representation. I took division by 2, just to illustrate the issue using a very simple example.
最满意答案
没有什么可以从中获得。 你只是在改变规模,但是在你的计算中你不会得到更有意义的数字。
维基百科有关方差的文章以高水平解释了计算方差的一些选项。
There's nothing to be gained from this. You are only changing the scale but you'd don't get any more significant figures in your calculation.
The Wikipedia article on variance explains at a high level some of the options for calculation variance in a robust fashion.
发布评论