Algorithm-BaumWelch
view release on metacpan or search on metacpan
lib/Algorithm/BaumWelch.pm view on Meta::CPAN
undef @config;
@config = ( [15, q{}] );
push @config, (map { [ 15, q{P(...|State_}.$_.q{)} ] } (1..$#{$trans->[0]}+1));
my $tbl1 = Text::SimpleTable->new(@config);
my $count = 0;
for my $row (@{$keys}) {
#$tbl1->row( $row, ( map { my $v = $emis->{$row}[$_]; if ($v > 1e-4 || $v < 1e4 ) { $v = sprintf(q{%.12f},$start->[$_]) } else { $v = sprintf(q{%.8e},$start->[$_]) }; $v } (0..$#{$trans->[0]}) ) );
my @data;
for my $col (0..$#{$trans->[0]}) { push @data, sprintf(q{%.8e},$emis->{$row}[$col]); }
$tbl1->row( qq{P($row|...)}, @data );
$tbl1->hr if $count != $#{$keys};
$count++;
}
print qq{\nEmission matrix.\n};
print $tbl1->draw;
undef @config;
push @config, (map { [ 15, q{State_}.$_ ] } (1..$#{$start}+1));
my $tbl2 = Text::SimpleTable->new(@config);
#my @data;
#for my $i (0..$#{$trans->[0]}) { push @data, sprintf(q{%.8e},$start->[$i]); }
#$tbl2->row(@data);
$tbl2->row( ( map { my $v = $start->[$_]; if ($v > 1e-4 && $v < 1e4 || $v == 0 ) {
$v = sprintf(q{%.12f},$start->[$_])
}
else {
$v = sprintf(q{%.8e},$start->[$_]) }; $v
} (0..$#{$trans->[0]}) ) );
print qq{\nStart probabilities.\n};
print $tbl2->draw;
}
return;
}
1; # Magic true value required at end of module
__END__
#ARRAY REFERENCE (0)
# |
# |__ARRAY REFERENCE (1) [ '->[0]' ]
# | |
# | |__ARRAY REFERENCE (2) ---LONG_LIST_OF_SCALARS--- [ length = 33 ] e.g. 0..2: obs2, obs3, obs3 [ '->[0][0]' ] # a serie
# | |
# | |__ARRAY REFERENCE (2) ---LONG_LIST_OF_SCALARS--- [ length = 3 ]: obs3, obs1, obs2 [ '->[0][1]' ] # a lista de tipos de observacoes
# | |
# | |__SCALAR = '3' (2) [ '->[0][2]' ] # o numero de tipos de observacoes
# |
# |__ARRAY REFERENCE (1) [ '->[1]' ]
# | |
# | |__ARRAY REFERENCE (2) [ '->[1][0]' ] # transition matrix
# | | |
# | | |__ARRAY REFERENCE (3) ---LONG_LIST_OF_SCALARS--- [ length = 2 ]: 0.933779184947876, 0.0718663090308487 [ '->[1][0][0]' ]
# | | |
# | | |__ARRAY REFERENCE (3) ---LONG_LIST_OF_SCALARS--- [ length = 2 ]: 0.0662208150521236, 0.864944219467616 [ '->[1][0][1]' ]
# | |
# | |__HASH REFERENCE (2) [ '->[1][1]' ] # emission matrix
# | | |
# | | |__'obs3'=>ARRAY REFERENCE (3) ---LONG_LIST_OF_SCALARS--- [ length = 2 ]: 0.211448366743702, 0.465609305295478 [ '->[1][1]{obs3}' ]
# | | |
# | | |__'obs1'=>ARRAY REFERENCE (3) ---LONG_LIST_OF_SCALARS--- [ length = 2 ]: 0.640481492730478, 7.18630557481621e-09 [ '->[1][1]{obs1}' ]
# | | |
# | | |__'obs2'=>ARRAY REFERENCE (3) ---LONG_LIST_OF_SCALARS--- [ length = 2 ]: 0.14807014052582, 0.534390687518216 [ '->[1][1]{obs2}' ]
# | |
# | |__ARRAY REFERENCE (2) ---LONG_LIST_OF_SCALARS--- [ length = 2 ]: 4.52394236439737e-30, 1 [ '->[1][2]' ] # start conditions
# |
# |__ ARRAY REFERENCE (1) [ '->[2]' ] # perp
#
=head1 SEE ALSO
Algorithm::Viterbi
=cut
=head1 DEPENDENCIES
'Carp' => '1.08',
'Math::Cephes' => '0.47',
'List::Util' => '1.19',
'Text::SimpleTable' => '2.0',
=cut
=head1 WARNING
This module Baum-Welch implementation has been tested fairly extensively with 2-hidden state cases but as yet has been subject to little (almost
no) testing with >2 hidden states.
=cut
=head1 BUGS AND LIMITATIONS
Let me know.
=head1 AUTHOR
Daniel S. T. Hughes C<< <dsth@cantab.net> >>
=cut
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2010, Daniel S. T. Hughes C<< <dsth@cantab.net> >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
=cut
=head1 DISCLAIMER OF WARRANTY
Because this software is licensed free of charge, there is no warranty
for the software, to the extent permitted by applicable law. Except when
otherwise stated in writing the copyright holders and/or other parties
provide the software "as is" without warranty of any kind, either
expressed or implied, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose. The
entire risk as to the quality and performance of the software is with
you. Should the software prove defective, you assume the cost of all
necessary servicing, repair, or correction.
( run in 2.199 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )