Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Viterbi application

by azheid (Sexton)
on Apr 06, 2014 at 21:52 UTC ( [id://1081340]=note: print w/replies, xml ) Need Help??


in reply to Re: Viterbi application
in thread Viterbi application

You are right, your implementation of the data matrix is much cleaner. I was not aware of that notation. 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 will try to implement the code with this notation and see if the algorithm is easier to implement.

Replies are listed 'Best First'.
Re^3: Viterbi application
by kcott (Archbishop) on Apr 06, 2014 at 22:47 UTC
    "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

      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

Re^3: Viterbi application
by azheid (Sexton) on Apr 06, 2014 at 22:23 UTC

    Implement seems to be my favorite word today

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1081340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found