in reply to Re^2: Viterbi application
in thread Viterbi application

"min() is a subroutine that I did not include. It does exactly what it sounds like, returns the minimum of two values in a list."

I did consider that might have been something like that (e.g. similar to List::Util's min() function); however, you're only providing a single value after min( in the code you posted.

Here's an example of how ${$vit_dist[$i-1]}[$j]+${$distance_mat[$i]}[$j] might be evaluated:

$ perl -Mstrict -Mwarnings -le ' my (@vit_dist, @distance_mat); $vit_dist[0][0] = 30; $distance_mat[1][0] = 12; my ($i, $j) = (1, 0); print ${$vit_dist[$i-1]}[$j]+${$distance_mat[$i]}[$j]; ' 42

Perhaps you need a comma instead of a plus:

min(${$vit_dist[$i-1]}[$j], ${$distance_mat[$i]}[$j])

A liberalsplinklingofwhitespace may improve the readability of your code and reduce errors. :-)

-- Ken

Replies are listed 'Best First'.
Re^4: Viterbi application
by azheid (Sexton) on Apr 06, 2014 at 23:28 UTC

    I stopped when I realized, for what seemed like the 10th consecutive try, that this code was not going to do what I wanted either

    I updated the original post with where I was intending to go with the min() line, however the code is not really doing the right thing

    My main problem is I cannot seem to translate the toy examples of viterbi into a piece of code that works regardless of the number of nodes in each row.

      "I updated the original post ..."

      Updating your post is absolutely fine but please do indicate what you've changed. Not doing so often renders responses meaningless or makes it look like the person replying hasn't read your post correctly.

      In this particular case, a simple note to say you added ,${$vit_distance[$i]}+${$distance_mat[$i]}[$j]) to the min() function would suffice.

      All this is explained in more detail in "How do I change/delete my post?".

      -- Ken

        I understand your point. Noted for future posts, and fixed in this one