G'day azheid,
"I have just enough coding experience to hang myself with a short rope. ... I tried to create a second similar matrix that stored the minimum distance to each node, but I am having trouble with correctly referencing the distance matrix."
I think you need some basic foundation knowledge.
In both of these lines, you're assigning an arrayref to an array:
my @distance_mat=[]; ... my @vit_dist=[ [ 0] ];
And in this line:
${$vit_dist[$i]}[$j]=min(${$vit_dist[$i-1]}[$j]+${$distance_mat[$i]}[$ +j];
you appear to be calling a min() function. You've failed to include a closing parenthesis so that leaves me guessing what is intended (and, potentially, what else has been left out or accidentally included). Perl has no min() function, Algorithm::Viterbi's documentation shows no min() function and you show no code for a min() function: I'm out of guesses.
Attempting to access a multi-dimensional array element with code like:
${${$distance_mat[$i]}[$j]}[$k]
is difficult to read and maintain: and, therefore, error-prone.
I suggest starting with "Perl references short introduction" and "Perl data structures intro".
Here's how I might have written the first piece of code you posted. I've reduced the number of elements from 10 to 2 for demonstration purposes. This should give you an idea of how you can (much simply) drill down into this sort of data structure and access individual elements.
#!/usr/bin/env perl use strict; use warnings; my $max_index = 1; my $matrix; for my $i (0 .. $max_index) { for my $j (0 .. $max_index) { for my $k (0 .. $max_index) { $matrix->[$i][$j][$k] = rand 1; } } } use Data::Dump; dd $matrix;
Output:
[ [ [0.290579816865833, 0.491432556740136], [0.888187692306143, 0.761365009561764], ], [ [0.865674078359991, 0.284696276285089], [0.0562126863718184, 0.781856824452085], ], ]
-- Ken
In reply to Re: Viterbi application
by kcott
in thread Viterbi application
by azheid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |