Commit 14dbd96b authored by Davis King's avatar Davis King

Fixed a bug in find_max_factor_graph_viterbi() which occurred when a

zero order model had negative factor values.
parent d3393766
...@@ -92,7 +92,7 @@ namespace dlib ...@@ -92,7 +92,7 @@ namespace dlib
{ {
matrix<unsigned long,1,1> node_state; matrix<unsigned long,1,1> node_state;
unsigned long best_state = 0; unsigned long best_state = 0;
double best_val = 0; double best_val = -std::numeric_limits<double>::infinity();
for (unsigned long s = 0; s < num_states; ++s) for (unsigned long s = 0; s < num_states; ++s)
{ {
node_state(0) = s; node_state(0) = s;
......
...@@ -26,7 +26,8 @@ namespace ...@@ -26,7 +26,8 @@ namespace
template < template <
unsigned long O, unsigned long O,
unsigned long NS, unsigned long NS,
unsigned long num_nodes unsigned long num_nodes,
bool all_negative
> >
class map_problem class map_problem
{ {
...@@ -37,6 +38,8 @@ namespace ...@@ -37,6 +38,8 @@ namespace
map_problem() map_problem()
{ {
data = randm(number_of_nodes(),(long)std::pow(num_states(),(double)order()+1), rnd); data = randm(number_of_nodes(),(long)std::pow(num_states(),(double)order()+1), rnd);
if (all_negative)
data = -data;
} }
unsigned long number_of_nodes ( unsigned long number_of_nodes (
...@@ -110,18 +113,20 @@ namespace ...@@ -110,18 +113,20 @@ namespace
template < template <
unsigned long order, unsigned long order,
unsigned long num_states, unsigned long num_states,
unsigned long num_nodes unsigned long num_nodes,
bool all_negative
> >
void do_test() void do_test_()
{ {
dlog << LINFO << "order: "<< order dlog << LINFO << "order: "<< order
<< " num_states: " << num_states << " num_states: " << num_states
<< " num_nodes: " << num_nodes; << " num_nodes: " << num_nodes
<< " all_negative: " << all_negative;
for (int i = 0; i < 25; ++i) for (int i = 0; i < 25; ++i)
{ {
print_spinner(); print_spinner();
map_problem<order,num_states,num_nodes> prob; map_problem<order,num_states,num_nodes,all_negative> prob;
std::vector<unsigned long> assign, assign2; std::vector<unsigned long> assign, assign2;
brute_force_find_max_factor_graph_viterbi(prob, assign); brute_force_find_max_factor_graph_viterbi(prob, assign);
find_max_factor_graph_viterbi(prob, assign2); find_max_factor_graph_viterbi(prob, assign2);
...@@ -133,6 +138,26 @@ namespace ...@@ -133,6 +138,26 @@ namespace
} }
} }
template <
unsigned long order,
unsigned long num_states,
unsigned long num_nodes
>
void do_test()
{
do_test_<order,num_states,num_nodes,false>();
}
template <
unsigned long order,
unsigned long num_states,
unsigned long num_nodes
>
void do_test_negative()
{
do_test_<order,num_states,num_nodes,true>();
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
class test_find_max_factor_graph_viterbi : public tester class test_find_max_factor_graph_viterbi : public tester
...@@ -151,11 +176,14 @@ namespace ...@@ -151,11 +176,14 @@ namespace
do_test<1,3,1>(); do_test<1,3,1>();
do_test<1,3,2>(); do_test<1,3,2>();
do_test<0,3,2>(); do_test<0,3,2>();
do_test_negative<0,3,2>();
do_test<1,3,8>(); do_test<1,3,8>();
do_test<2,3,7>(); do_test<2,3,7>();
do_test_negative<2,3,7>();
do_test<3,3,8>(); do_test<3,3,8>();
do_test<4,3,8>(); do_test<4,3,8>();
do_test_negative<4,3,8>();
do_test<0,3,8>(); do_test<0,3,8>();
do_test<4,3,1>(); do_test<4,3,1>();
do_test<4,3,0>(); do_test<4,3,0>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment