the number of elements of the value array of each key!

This: my $prob_es = ( $#{$hash_es{$string_es}} + 1) / 6939873;

is better written as: my $prob_es = ( @{ $hash_es{$string_es} }  ) / 6939873;

The same goes for MI, I need the intersection between the array of both value arrays for the keys to the two hashes.

Okay. Then I think these refactorings should do the trick and save considerable time and space in the process:

sub MI { my( $string_es, $string_en, $hash_es, $hash_en ) = @_; my $prob_es = ( @{ $hash_es{ $string_es } } ) / 6939873; my $prob_en = ( @{ $hash_en{ $string_en } } ) / 6939873; my $intersection = Intersection( $hash_es{ $string_es }, $hash_en{ $string_en } ); my $prob_es_en = ( $intersection ) / 6939873; $prob_es_en = ( $prob_es_en + ( $prob_es * $prob_en * 0.1) ) / 1.1 +; my $mi = $prob_es_en * log( $prob_es_en / ( $prob_es * $prob_en ) +); return $mi; } sub Intersection { my( $refA, $refB ) = @_; my %counts; ++$counts{ $_ } for @$refA; ++$counts{ $_ } for @$refB; my $intersects = 0; $counts{ $_ } > 1 and ++$intersects for keys %counts; return $intersects; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^13: statistics of a large text by BrowserUk
in thread statistics of a large text by perl_lover_always

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.