protected bool HasConverged(double oldLikelihood, double newLikelihood, int currentIteration)
{
// Update and verify stop criteria
if (tolerance > 0)
{
// Stopping criteria is likelihood convergence
if (System.Math.Abs(oldLikelihood - newLikelihood) <= tolerance)
return true;
if (maxIterations > 0)
{
// Maximum iterations should also be respected
if (currentIteration >= maxIterations)
return true;
}
}
else
{
// Stopping criteria is number of iterations
if (currentIteration == maxIterations)
return true;
}
// Check if we have reached an invalid state
if (Double.IsNaN(newLikelihood) || Double.IsInfinity(newLikelihood))
{
return true;
}
return false;
}