Commit f311e46d authored by Davis King's avatar Davis King

Fixed some potential bugs in the rvm

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402480
parent c0754e3b
...@@ -59,25 +59,6 @@ namespace dlib ...@@ -59,25 +59,6 @@ namespace dlib
return kernel; return kernel;
} }
void set_epsilon (
scalar_type eps_
)
{
// make sure requires clause is not broken
DLIB_ASSERT(eps_ > 0,
"\tvoid rvm_trainer::set_epsilon(eps_)"
<< "\n\t invalid inputs were given to this function"
<< "\n\t eps: " << eps_
);
eps = eps_;
}
const scalar_type get_epsilon (
) const
{
return eps;
}
template < template <
typename in_sample_vector_type, typename in_sample_vector_type,
typename in_scalar_vector_type typename in_scalar_vector_type
...@@ -289,7 +270,7 @@ namespace dlib ...@@ -289,7 +270,7 @@ namespace dlib
// if we just did a search of all the alphas and it still put is back // if we just did a search of all the alphas and it still put is back
// into the current active set then we are done. // into the current active set then we are done.
if (search_all_alphas == true && active_bases(selected_idx) != -1) if (search_all_alphas == true && selected_idx != -1 && active_bases(selected_idx) != -1)
{ {
break; break;
} }
...@@ -327,7 +308,7 @@ namespace dlib ...@@ -327,7 +308,7 @@ namespace dlib
alpha(idx) = s*s/(q*q-s); alpha(idx) = s*s/(q*q-s);
} }
else else if (phi.nc() > 1) // don't ever remove the last basis vector
{ {
// the new alpha value is infinite so remove the selected alpha from our model // the new alpha value is infinite so remove the selected alpha from our model
active_bases(selected_idx) = -1; active_bases(selected_idx) = -1;
...@@ -348,6 +329,21 @@ namespace dlib ...@@ -348,6 +329,21 @@ namespace dlib
// recompute the beta vector next time around the main loop. // recompute the beta vector next time around the main loop.
recompute_beta = true; recompute_beta = true;
} }
else
{
if (search_all_alphas == true)
{
// In this case we are saying we are done because the wide search
// told us to remove the only basis function we have. So just stop
break;
}
else
{
// we tried to remove the last basis vector in phi
// so lets make sure we do a round of wide search next time.
ticker = rounds_of_narrow_search;
}
}
} }
else else
{ {
...@@ -629,25 +625,6 @@ namespace dlib ...@@ -629,25 +625,6 @@ namespace dlib
return kernel; return kernel;
} }
void set_epsilon (
scalar_type eps_
)
{
// make sure requires clause is not broken
DLIB_ASSERT(eps_ > 0,
"\tvoid rvm_regression_trainer::set_epsilon(eps_)"
<< "\n\t invalid inputs were given to this function"
<< "\n\t eps: " << eps_
);
eps = eps_;
}
const scalar_type get_epsilon (
) const
{
return eps;
}
template < template <
typename in_sample_vector_type, typename in_sample_vector_type,
typename in_scalar_vector_type typename in_scalar_vector_type
...@@ -799,7 +776,7 @@ namespace dlib ...@@ -799,7 +776,7 @@ namespace dlib
// if we just did a search of all the alphas and it still put is back // if we just did a search of all the alphas and it still put is back
// into the current active set then we are done. // into the current active set then we are done.
if (search_all_alphas == true && active_bases(selected_idx) != -1) if (search_all_alphas == true && selected_idx != -1 && active_bases(selected_idx) != -1)
{ {
break; break;
} }
...@@ -838,7 +815,7 @@ namespace dlib ...@@ -838,7 +815,7 @@ namespace dlib
alpha(idx) = s*s/(q*q-s); alpha(idx) = s*s/(q*q-s);
} }
else else if (phi.nc() > 1) // don't ever remove the last basis vector from phi
{ {
// the new alpha value is infinite so remove the selected alpha from our model // the new alpha value is infinite so remove the selected alpha from our model
active_bases(selected_idx) = -1; active_bases(selected_idx) = -1;
...@@ -855,6 +832,21 @@ namespace dlib ...@@ -855,6 +832,21 @@ namespace dlib
} }
} }
} }
else
{
if (search_all_alphas == true)
{
// In this case we are saying we are done because the wide search
// told us to remove the only basis function we have. So just stop
break;
}
else
{
// we tried to remove the last basis vector in phi
// so lets make sure we do a round of wide search next time.
ticker = rounds_of_narrow_search;
}
}
} }
else else
{ {
......
...@@ -50,7 +50,6 @@ namespace dlib ...@@ -50,7 +50,6 @@ namespace dlib
ensures ensures
- This object is properly initialized and ready to be used - This object is properly initialized and ready to be used
to train a relevance vector machine. to train a relevance vector machine.
- #get_epsilon() == 0.001
!*/ !*/
void set_kernel ( void set_kernel (
...@@ -68,25 +67,6 @@ namespace dlib ...@@ -68,25 +67,6 @@ namespace dlib
- returns a copy of the kernel function in use by this object - returns a copy of the kernel function in use by this object
!*/ !*/
void set_epsilon (
scalar_type eps_
);
/*!
requires
- eps > 0
ensures
- #get_epsilon() == eps
!*/
const scalar_type get_epsilon (
) const;
/*!
ensures
- returns the error epsilon that determines when training should stop.
Generally a good value for this is 0.001. Smaller values may result
in a more accurate solution but take longer to execute.
!*/
template < template <
typename in_sample_vector_type, typename in_sample_vector_type,
typename in_scalar_vector_type typename in_scalar_vector_type
...@@ -104,7 +84,7 @@ namespace dlib ...@@ -104,7 +84,7 @@ namespace dlib
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a relevance vector classifier given the training samples in x and - trains a relevance vector classifier given the training samples in x and
labels in y. Training is done when the error is less than get_epsilon(). labels in y.
- returns a decision function F with the following properties: - returns a decision function F with the following properties:
- if (new_x is a sample predicted have +1 label) then - if (new_x is a sample predicted have +1 label) then
- F(new_x) >= 0 - F(new_x) >= 0
...@@ -173,7 +153,6 @@ namespace dlib ...@@ -173,7 +153,6 @@ namespace dlib
ensures ensures
- This object is properly initialized and ready to be used - This object is properly initialized and ready to be used
to train a relevance vector machine. to train a relevance vector machine.
- #get_epsilon() == 0.001
!*/ !*/
void set_kernel ( void set_kernel (
...@@ -191,25 +170,6 @@ namespace dlib ...@@ -191,25 +170,6 @@ namespace dlib
- returns a copy of the kernel function in use by this object - returns a copy of the kernel function in use by this object
!*/ !*/
void set_epsilon (
scalar_type eps_
);
/*!
requires
- eps > 0
ensures
- #get_epsilon() == eps
!*/
const scalar_type get_epsilon (
) const;
/*!
ensures
- returns the error epsilon that determines when training should stop.
Generally a good value for this is 0.001. Smaller values may result
in a more accurate solution but take longer to execute.
!*/
template < template <
typename in_sample_vector_type, typename in_sample_vector_type,
typename in_scalar_vector_type typename in_scalar_vector_type
......
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