Develop and Download Open Source Software

Browse CVS Repository

Diff of /gikonavigoeson/gikonavi/GikoBayesian.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.14 by yoffy, Mon Nov 1 09:51:57 2004 UTC revision 1.15 by yoffy, Mon Nov 1 10:28:24 2004 UTC
# Line 759  function TGikoBayesian.CalcGaryRobinson( Line 759  function TGikoBayesian.CalcGaryRobinson(
759                  else if info.NormalWord = 0 then                  else if info.NormalWord = 0 then
760                          Result := 0.99                          Result := 0.99
761                  else                  else
762                    {
763                          Result := ( info.ImportantWord / info.ImportantText ) /                          Result := ( info.ImportantWord / info.ImportantText ) /
764                                  ((info.NormalWord / info.NormalText ) +                                  ((info.NormalWord / info.NormalText ) +
765                                   (info.ImportantWord / info.ImportantText));                                   (info.ImportantWord / info.ImportantText));
766                    }
767                            Result := (info.ImportantWord * info.NormalText) /
768                                    (info.NormalWord * info.ImportantText +
769                                    info.ImportantWord * info.NormalText);
770          end;          end;
771    
772          function f( cnt : Integer; n, mean : Single ) : Extended;          function f( cnt : Integer; n, mean : Single ) : Extended;
773          const          const
774                  k = 0.00001;                  k = 0.001;
775          begin          begin
776                  Result := ( (k * mean) + (cnt * n) ) / (k + cnt);                  Result := ( (k * mean) + (cnt * n) ) / (k + cnt);
777          end;          end;
# Line 838  function TGikoBayesian.CalcGaryRobinsonF Line 843  function TGikoBayesian.CalcGaryRobinsonF
843                  else if info.NormalWord = 0 then                  else if info.NormalWord = 0 then
844                          Result := 0.99                          Result := 0.99
845                  else                  else
846                          Result := info.ImportantWord /                  {
847                                  (info.ImportantWord + info.NormalWord *                          Result := ( info.ImportantWord / info.ImportantText ) /
848                                   info.ImportantText / info.NormalText);                                  ((info.NormalWord / info.NormalText ) +
849                                     (info.ImportantWord / info.ImportantText));
850                    }
851                            Result := (info.ImportantWord * info.NormalText) /
852                                    (info.NormalWord * info.ImportantText +
853                                    info.ImportantWord * info.NormalText);
854          end;          end;
855    
856          function f( cnt : Integer; n, mean : Single ) : Extended;          function f( cnt : Integer; n, mean : Single ) : Extended;
857          const          const
858                  k = 0.00001;                  k = 0.001;
859          begin          begin
860                  Result := ( (k * mean) + (cnt * n) ) / (k + cnt);                  Result := ( (k * mean) + (cnt * n) ) / (k + cnt);
861          end;          end;
862    
863          function prbx( x2, degree : Extended ) : Extended;          function prbx( x2, degree : Extended ) : Extended;
         var  
                 m : Extended;  
                 sum : Extended;  
                 term : Extended;  
                 i : extended;  
864          begin          begin
865    
866                  m := x2 / 2;                  Result := 0.5;
                 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;  
867    
868          end;          end;
869    
# Line 902  begin Line 893  begin
893          end;          end;
894          mean := mean / wordCount.Count;          mean := mean / wordCount.Count;
895    
         cnt := 0;  
 (*  
896          P1 := 1;          P1 := 1;
897          Q1 := 1;          Q1 := 1;
 (*)  
         P1 := 0;  
         Q1 := 0;  
 //*  
898          for i := 0 to wordCount.Count - 1 do begin          for i := 0 to wordCount.Count - 1 do begin
899                  countInfo       := TWordCountInfo( wordCount.Objects[ i ] );                  countInfo       := TWordCountInfo( wordCount.Objects[ i ] );
900                  n                                               := f( countInfo.WordCount, narray[ i ], mean );                  n                                               := f( countInfo.WordCount, narray[ i ], mean );
901                  if countInfo <> nil then                  P1 := P1 * ( 1 - n );
902                          cnt := cnt + countInfo.WordCount;                  Q1 := Q1 * n;
 (*  
                 P1 := P1 + Ln( 1 - n ) * countInfo.WordCount;  
                 Q1 := Q1 + Ln( n ) * countInfo.WordCount;  
 (*)  
                 P1 := P1 + Ln( 1 - n );  
                 Q1 := Q1 + Ln( n );  
 //*)  
903          end;          end;
904            cnt := wordCount.Count;
905          if cnt = 0 then          if cnt = 0 then
906                  cnt := 1;                  cnt := 1
907  //(*          else
908          P1 := prbx( -2 * P1, 2 * cnt );          P1 := Power( P1, 1 / cnt );
909          Q1 := prbx( -2 * Q1, 2 * cnt );          Q1 := Power( Q1, 1 / cnt );
910  (*)  
911          P1 := prbx( -2 * Ln( P1 ), 2 * cnt );          P1 := 1 - prbx( -2 * Ln( P1 ), 2 * cnt );
912          Q1 := prbx( -2 * Ln( Q1 ), 2 * cnt );          Q1 := 1 - prbx( -2 * Ln( Q1 ), 2 * cnt );
913  //*)  
914          if P1 + Q1 = 0 then begin          Result := (1 + P1 - Q1) / 2;
                 Result := 0.5  
         end else begin  
                 Result := (1 + Q1 + P1) / 2;  
         end;  
915    
916  end;  end;
917    

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26