void LMfit::autoiter() { wssr_before_ = chi2; realt prev_chi2 = chi2; const SettingsMgr *sm = F_->settings_mgr(); if (F_->get_verbosity() >= 1) { F_->ui()->mesg("\t === Levenberg-Marquardt method ==="); F_->ui()->mesg("Initial values: lambda=" + S(lambda) + " WSSR=" + sm->format_double(chi2)); F_->ui()->mesg("Max. number of iterations: " + max_iterations_); } realt stop_rel = F_->get_settings()->lm_stop_rel_change; realt max_lambda = F_->get_settings()->lm_max_lambda; if (stop_rel > 0 && F_->get_verbosity() >= 1) F_->ui()->mesg("Will stop when relative change of WSSR is " "twice in row below " + S (stop_rel * 100.) + "%"); int small_change_counter = 0; for (int iter = 0; !common_termination_criteria(iter); iter++) { bool better_fit = do_iteration(); if (better_fit) { realt d = prev_chi2 - chi2; if (F_->get_verbosity() >= 1) F_->ui()->mesg("#" + S(iter_nr_) + ":" " WSSR=" + sm->format_double(chi2) + " lambda=" + S(lambda) + " d(WSSR)=" + S(-d) + " (" + S (d / prev_chi2 * 100) + "%)"); // another termination criterium: negligible change of chi2 if (d / prev_chi2 < stop_rel || chi2 == 0) { small_change_counter++; if (small_change_counter >= 2 || chi2 == 0) { F_->msg("... converged."); break; } } else small_change_counter = 0; prev_chi2 = chi2; } else { // no better fit if (F_->get_verbosity() >= 1) F_->ui()->mesg("#" + S(iter_nr_) + ":" " (WSSR=" + sm->format_double(chi2_) + ")" " lambda=" + S(lambda)); if (lambda > max_lambda) { // another termination criterium F_->msg("In L-M method: lambda=" + S(lambda) + " > " + S(max_lambda) + ", stopped."); break; } } iteration_plot(a, chi2); } post_fit (a, chi2); }
void NMfit::autoiter() { realt convergence = F_->get_settings()->nm_convergence; wssr_before_ = compute_wssr(a_orig_, dmdm_); F_->msg("WSSR before starting simplex fit: " + S(wssr_before_)); for (int iter = 0; !termination_criteria(iter, convergence); ++iter) { ++iter_nr_; change_simplex(); find_best_worst(); iteration_plot(best->a, best->wssr); } post_fit (best->a, best->wssr); }