in reply to Viterbi application
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Viterbi application
by azheid (Sexton) on Apr 06, 2014 at 21:52 UTC | |
by kcott (Archbishop) on Apr 06, 2014 at 22:47 UTC | |
by azheid (Sexton) on Apr 06, 2014 at 23:28 UTC | |
by kcott (Archbishop) on Apr 06, 2014 at 23:47 UTC | |
by azheid (Sexton) on Apr 07, 2014 at 16:09 UTC | |
by azheid (Sexton) on Apr 06, 2014 at 22:23 UTC |