smilly:
You may be solving the wrong problem altogether. If your word list is very large (as I suspect it is), you'll be calculating a huge set of values. For many problems, you won't need the entire matrix. It may be better to compute them as needed and store them in the array when computed. That way, you compute only the ones you want, and once only. Something like:
sub get_similarity {
my $i = shift;
my $j = shift;
# Matrix is symmetric around x==y
($i,$j) = ($j,$i) if $i > $j;
return $sim[$i][$j] if defined $sim[$i][$j];
$sim[$i][$j] = similarity($words[$i], $words[$j]);
}
Extra credit if you:
- Use a hash instead of an array.
- Tie your array or hash to a dbm file so you keep your values between runs...
...
roboticus
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.