diff --git a/src/turnbull.rs b/src/turnbull.rs index 48cb7ed..71aa40c 100644 --- a/src/turnbull.rs +++ b/src/turnbull.rs @@ -513,11 +513,10 @@ fn do_icm_step(data: &TurnbullData, p: &Vec, s: &Vec, ll_tolerance: f6 step_size_exponent += 1; - // FIXME: Nasty hack! - // Limit of 10 should be good enough, but sometimes ICM step does not work well when constrained so the limit is increased - // It would be greatly preferable to simply handle this case more gracefully when constrained - if step_size_exponent > 100 { - panic!("ICM fails to increase log-likelihood"); + if step_size_exponent > 10 { + // If ICM does not increase log-likelihood, then simply return the original estimate and retry EM again + // If neither increases the log-likelihood, then we will have have converged within fit_turnbull_estimator + return (p.clone(), s.clone(), ll_model); } } } @@ -639,6 +638,9 @@ fn survival_prob_likelihood_ratio_ci(data: &TurnbullData, progress_bar: Progress ci_bound_upper = ci_estimate; } + // FIXME: Sometimes this does not converge within max_iterations - investigate why this is + // If it is not an issue with the algorithm, then we should also terminate if width of interval is narrower than a specified tolerance + ci_estimate = (ci_bound_lower + ci_bound_upper) / 2.0; iteration += 1;