æ¨æºåå·®ãæ±ããperlé¢æ°
æ¨æºåå·®ã£ã¦ããã®ãä½ãªã®ããæè¿ç¥ãã¾ãããããããæ°å¼ã§è¡¨ããã¾ãã
ã¦ããããåããããæ°å¼ã«ãããæµæãããã§ããããã
ããã°ã©ã ã®æ¹ãç解ããããããã
ãããè¦ã¦ãããããã°Buzzurlã®ã¿ã°ã¯ã©ã¦ããä½ãã®ã«ãæ¨æºåå·®ãåºã«éã¿ä»ãããããªãã¨æã£ã¦ã½ã¼ã¹ãè¦ããæ±ãã£ãã®ã§æ¸ãç´ãã¦ã¿ãã
æ®éã«æ¸ãã¨ããã
#åæ£ãæ±ãããæ¨æºåå·®ã欲ããå ´åã¯æ»ãå¤ãsqrt() #averageé¢æ°ã¯èªæãªã®ã§çç¥ sub variance { my $num = scalar(@_) or return 0; my $ave = average(@_); my $ret = 0; while(@_){ my $i = shift; $ret += ($i-$ave)**2; } return $ret/$num; }
ã¾ãããã§ãããã ãã©é·ã£ãããããå¤å°é ããªã£ã¦ããã¨ããã°ãããã«çãæ¸ãã»ããperlãããããï¼
#map/reduceã使ããã¼ã¸ã§ã³ã #ã«ã¼ãã2åèµ°ãåã巨大ãªé åã«å¯¾ãã¦ã¯é ãã use List::Util qw(reduce); sub variance_mr { my $num = scalar(@_) or return 0; my $ave = average(@_); my $ret = reduce { $a + $b } map { ($_ - $ave) ** 2 } @_; return $ret/$num; }
ãã£ã¨é ããªã£ã¦ããããªããããã«çããããªãã§ãããããã
#ãããããmapå ã§æ¿åº¦ã§å²ã£ã¦ãã¾ãçã #å²ãç®ã¿ã¤ãã³ã°ã®åé¡ã§å¤ãå¤ããå ´åãããã sub variance_mr2 { my $num = scalar(@_) or return 0; my $ave = average(@_); return reduce { $a + $b } map { ($_ - $ave) ** 2 / $num } @_; }
å¾è
2ã¤ã®æ¸ãæ¹ã ã¨ãå
ã®æ°å¼ã¨ã»ã¨ãã©ç価ã«è¦ããæ°ããã (( reduce { $a + $b }
ã ã«ç¸å½ãããmap { ($_ - $ave) ** 2 } @_
ãã«ç¸å½ããã))
ããã¨ãå¾è
2ã¤ã¯é
ããã©ãMapReduceãã¬ã¼ã ã¯ã¼ã¯ã¿ãããªãã®ã使ãã人ãªãããã«ã®ããããã®ã§ã¯ã½åæ£å®è¡ã§ããããï¼
ã¾ãä½ãè¨ããããã¨ããã¨ãtexè¨æ³ã使ã£ã¦ã¿ããã£ãã ããªãã§ããã