OSDN Git Service

Gary Robinson-Fisher をバグバグのまま放置しておくのは危険なので
authoryoffy <yoffy>
Mon, 1 Nov 2004 10:28:24 +0000 (10:28 +0000)
committeryoffy <yoffy>
Mon, 1 Nov 2004 10:28:24 +0000 (10:28 +0000)
とりあえず必ず 50% になるように変更。

GikoBayesian.pas

index ae587a0..86ae0fb 100644 (file)
@@ -4,7 +4,7 @@ unit GikoBayesian;
 \file          GikoBayesian.pas
 \brief \83x\83C\83W\83A\83\93\83t\83B\83\8b\83^
 
-$Id: GikoBayesian.pas,v 1.14 2004/11/01 09:51:57 yoffy Exp $
+$Id: GikoBayesian.pas,v 1.15 2004/11/01 10:28:24 yoffy Exp $
 }
 
 //! \95½\89¼\96¼\82ð\8e«\8f\91\82É\8aÜ\82ß\82È\82¢
@@ -759,14 +759,19 @@ function TGikoBayesian.CalcGaryRobinson( wordCount : TWordCount ) : Extended;
                else if info.NormalWord = 0 then
                        Result := 0.99
                else
+               {
                        Result := ( info.ImportantWord / info.ImportantText ) /
                                ((info.NormalWord / info.NormalText ) +
                                 (info.ImportantWord / info.ImportantText));
+               }
+                       Result := (info.ImportantWord * info.NormalText) /
+                               (info.NormalWord * info.ImportantText +
+                               info.ImportantWord * info.NormalText);
        end;
 
        function f( cnt : Integer; n, mean : Single ) : Extended;
        const
-               k = 0.00001;
+               k = 0.001;
        begin
                Result := ( (k * mean) + (cnt * n) ) / (k + cnt);
        end;
@@ -838,41 +843,27 @@ function TGikoBayesian.CalcGaryRobinsonFisher(
                else if info.NormalWord = 0 then
                        Result := 0.99
                else
-                       Result := info.ImportantWord /
-                               (info.ImportantWord + info.NormalWord *
-                                info.ImportantText / info.NormalText);
+               {
+                       Result := ( info.ImportantWord / info.ImportantText ) /
+                               ((info.NormalWord / info.NormalText ) +
+                                (info.ImportantWord / info.ImportantText));
+               }
+                       Result := (info.ImportantWord * info.NormalText) /
+                               (info.NormalWord * info.ImportantText +
+                               info.ImportantWord * info.NormalText);
        end;
 
        function f( cnt : Integer; n, mean : Single ) : Extended;
        const
-               k = 0.00001;
+               k = 0.001;
        begin
                Result := ( (k * mean) + (cnt * n) ) / (k + cnt);
        end;
 
        function prbx( x2, degree : Extended ) : Extended;
-       var
-               m : Extended;
-               sum : Extended;
-               term : Extended;
-               i : extended;
        begin
 
-               m := x2 / 2;
-               sum := exp( -m );
-               term := -m;
-
-               i := 1;
-               while i < (degree / 2 - 1) do begin
-                       term := term + ln( m / i );
-                       sum := sum + exp( term );
-                       i := i + 1;
-               end;
-
-               if sum < 1 then
-                       Result := sum
-               else
-                       Result := 1.0;
+               Result := 0.5;
 
        end;
 
@@ -902,41 +893,25 @@ begin
        end;
        mean := mean / wordCount.Count;
 
-       cnt := 0;
-(*
        P1 := 1;
        Q1 := 1;
-(*)
-       P1 := 0;
-       Q1 := 0;
-//*
        for i := 0 to wordCount.Count - 1 do begin
                countInfo       := TWordCountInfo( wordCount.Objects[ i ] );
                n                                               := f( countInfo.WordCount, narray[ i ], mean );
-               if countInfo <> nil then
-                       cnt := cnt + countInfo.WordCount;
-(*
-               P1 := P1 + Ln( 1 - n ) * countInfo.WordCount;
-               Q1 := Q1 + Ln( n ) * countInfo.WordCount;
-(*)
-               P1 := P1 + Ln( 1 - n );
-               Q1 := Q1 + Ln( n );
-//*)
+               P1 := P1 * ( 1 - n );
+               Q1 := Q1 * n;
        end;
+       cnt := wordCount.Count;
        if cnt = 0 then
-               cnt := 1;
-//(*
-       P1 := prbx( -2 * P1, 2 * cnt );
-       Q1 := prbx( -2 * Q1, 2 * cnt );
-(*)
-       P1 := prbx( -2 * Ln( P1 ), 2 * cnt );
-       Q1 := prbx( -2 * Ln( Q1 ), 2 * cnt );
-//*)
-       if P1 + Q1 = 0 then begin
-               Result := 0.5
-       end else begin
-               Result := (1 + Q1 + P1) / 2;
-       end;
+               cnt := 1
+       else
+       P1 := Power( P1, 1 / cnt );
+       Q1 := Power( Q1, 1 / cnt );
+
+       P1 := 1 - prbx( -2 * Ln( P1 ), 2 * cnt );
+       Q1 := 1 - prbx( -2 * Ln( Q1 ), 2 * cnt );
+
+       Result := (1 + P1 - Q1) / 2;
 
 end;