siskos1 has asked for the wisdom of the Perl Monks concerning the following question:
this part is main part. all code is here :foreach my $yy ( keys %{$trans->{$state}} ) { $trans->{$state}->{$yy} * viterbi($yy, $r) ; }
i didnt add any of my wrong codes to main foreach part, for those who want to try the code after knowing what to do, answer must be 0.08. for those who know viterbi, i didnt add emission probabilities because it is the easy part i guess. but i really want to know how to make the program hold all temporary values for all recursive calculations. if i put them in an array, program adds values not layer by layer but level by level, so things doesnt work. iterative solution is possible but i cant figure out how to solve it in a recursive way. thanks so much whoever helps. thanks again@observation = qw(empty a a empty); $trans = { 'end' => {M2 => 1}, 'M2' => { I1 => 0.1, M1 => 0.3}, 'I1' => { begin => 0.8}, 'M1' => { begin => 0.2}, }; sub viterbi { my $state = shift; my $output = shift; # V (begin)(0) =1; V(anyother)(0) =0; V(begin)(other_numbers) =0; if($state eq begin) { if($output == 0) { return 1;} else { return 0; } + } elsif ( ($state ne begin) && ($output == 0) ) {return 0; } else { $r=$output-1; #maximum of below foreach# foreach my $yy ( keys %{$trans->{$state}} ) { $trans->{$state}->{$yy} * viterbi($yy, $r) ; } } } print "\n\n", viterbi(end, 3);
|
|---|