2015年7月24日金曜日

Accuracy vs Precision:四捨五入誤差

 71.2, 72.5, 70.5, 74.7, 73.5

これらを「小数点第1位で四捨五入」すると

 71, 73, 71, 75, 74

次に、上記の四捨五入前後の平均(算術平均)を求めると

 四捨五入前:
 > mean(c(71.2, 72.5, 70.5, 74.7, 73.5))
 [1] 72.48

 四捨五入後:
 > mean(c(71, 73, 71, 75, 74))
 [1] 72.8

その誤差は 0.32 と、四捨五入後の平均値が大きくなっている。

この原因は

端数が0.5のとき常に増える方向に丸められるため、(端数がランダムでない場合は)わずかに正のバイアスが発生しうる。Wikipedia 端数処理

つまり、先の四捨五入前の数字には、「小数点第1位が 5」の数が 5つ中3つ含まれているので「端数がランダムではない」。よって「増える方向に丸められた」のが平均値が大きくなった原因。

「数字の丸め」は「端数処理」であり、一般的には「切り捨て・切り上げ」や「四捨五入」が使われるが、それだけではない。ただし、端数を何らかの方法で処理したので、誤差は多くの場合で避けられない。各端数処理の違いは「誤差精度の差」、もしくは「bias バイアス(偏り具合)」。


四捨五入以外の方法:Round Half to Even

四捨五入より端数処理の精度を上げる方法として「最近接偶数へのまるめ round to the nearest even」(Math Dude では「round half to even」)がある。

最近接偶数への丸め (round to the nearest even; RN) は、端数が0.5より小さいなら切り捨て、端数が0.5より大きいならは切り上げ、端数がちょうど0.5なら切り捨てと切り上げのうち結果が偶数となる方へ丸める。Wikipedia 端数処理

例えば、

 13.35 を小数点第1位の精度で丸めると 13.4、13.45 は 13.4

という具合。

先の例  71.2, 72.5, 70.5, 74.7, 73.5 を「round half to even」すると

 71, 72, 70, 75, 74

平均値は
> mean(c(71, 72, 70, 75, 74))
[1] 72.4

元の平均値 72.48 より 0.08 の誤差で、四捨五入の場合の誤差 0.32 から精度は向上している。この端数処理の方が「bias は少ない」といえる。

ここまでは、Math Dude 「How to Round Numbers (Part 2)」を元にした。


Accuracy vs Precision 再び

「四捨五入」に相当する英語がハッキリしない。half round up, half round down で良いような気もするが...。「rounding 端数処理」を数学的には意外と深い。もっと興味が湧いてから突っ込むことにする。全体的には「bias の極小化」と理解している。

英語といえば、以前「緻密と正確は違うよね?」を投稿した頃は precision を誤解していたようだ。次の Math is Fun の「Accuracy and Precision」の説明がとても明確。

Accuracy is how close a measured value is to the actual (true) value.
Precision is how close the measured values are to each other.

precision は「値がお互い近接している具合」ということ。「緻密」という英和辞書の訳に引きずられて理解していた。ただし今回は英和辞書は責められない

Oxford Learner's Dictionaries による precise の意味は

1. clear and accurate -> SYNONYM exact
2. [only before noun] used to emphasize that something happens at a particular time or in a particular way
3. taking care to be exact and accurate, especially about small details -> SYNONYM meticulous

名詞の precision

the quality of being exact, accurate and careful -> SYNONYM accuracy

つまり、日常的には accuracy と precision の違いは意識されないのだ。ただし、次の Math Dude の「Accuracy Versus Precision」からの引用のように

But, as we'll learn today, in the wonderful world of math, science, and engineering, they have very different meanings. And sometimes one is more important than the other. So, what are the differences? And when does each matter the most? Those are exactly the questions we'll be answering today.

数学、科学、エンジニアリングの分野では、この違いは非常に重要となる。とはいえ、その違いは難しいものではなく、次の図で一目瞭然。
この図は、Math Dude の記事でいえば、左から「precision without accuracy」「accuracy without precision」「accuracy and precision」。

次の Math Dude の記事からの引用は precision の理解に訳に立つ。

Keep in mind that low precision doesn't necessarily mean bad. Sometimes you don't need high precision, sometimes you can't get high precision, and sometimes things just don't work out the way you hoped they would. But that doesn't always mean that imprecise data is useless…it's just not precise.
低い緻密さは必ずしも悪いわけではない。時として高い緻密さは不要で、時には高い緻密さは得ることができない。緻密ではないデータが訳に立たない、とは必ずしもならない。

この「Accuracy と Precision」は Significant Figures(有効数字)にも繋がるが、Math Dude の「How to Identify Significant Figures」の次の Accuracy と Precision の区別も分かりやすい。

  1. Accuracy tells you how close a series of measurements are (on average) to the true value.
  2. Precision tells you how close a series of measurements are to each other.

ちなみに、significant figures は

With all of this in mind, do you think significant figures are about accuracy or precision? If you think about it, you'll see that the significant figures in a measurement tell us how precisely we have determined the value. They tell us nothing about the accuracy of that measurement. Which means that significant figures are about precision not accuracy.

です。


木を見て森を見ず

数学は Accuracy と Precision な理論が積み重なった学問。多くの学問も同様だが、数学はそれが際立っている。とはいえ、我々の日常生活やビジネスにおいて、求められる precision は違う。概算という「誤差を含んだ結果」でも、十分に役立つ局面もある。

冒頭に「四捨五入の誤差」の例を挙げたのは、「何でもかんでも四捨五入、切り上げ、切り捨て」にある弊害を明らかにしたかったのと

precision を意識しながらも
求めるのは accuracy

ということを再確認したかったから。これは数学だけに限定されず、日常でも意識すべきことだと思う。

そして accuracy と precision から連想するのは

「木を見て森を見ず」
(英語では「can't see the wood for the trees」)

例えば、数学を「難しそう」「計算が面倒」とかいう理由で避けるのは「木を見て森を見ず」という感じ。「Σ記号が出ただけで苦手意識が...」は、数学の極小の部分しか見ていない状態だろう。数学の全てを理解する必要はなく、求められる数学は個人によって違う。何といっても、数学の根本理論は難解ではなく、誰にとっても非常に有益だ(「はじめまして数学」参照)。

日常のことは割愛するが、ビジネス上でも顕著だ。何らかの解決策や案を検討する際、precision 的なことに拘り過ぎて accuracy 的なことが欠如している場面が往々にしてある。「これからデータ分析を始めたい人のための本」にあった「order of magnitude:インパクトの大きさを優先」のことを思い出すが、その優先事項を考慮しないのも「木を見て森を見ず」だろう。

「ガーガー、同じ(時として狭い)持論を、事細かに繰り返す」専門家の主張は「precision なのかもしれないが、必ずしも accracy  とは限らない」と考える方が健在な場合が多い気がしている。そんな専門家は「森が見えてない」のかもしれない。

数学が教えてくれるのは、計算方法だけではないのです。

0 件のコメント:

コメントを投稿