Пример #1
0
void Minimizer_minimize (Minimizer me, long maxNumOfIterations, double tolerance, int monitor) {
	try {

		my tolerance = tolerance;
		if (maxNumOfIterations <= 0) {
			return;
		}

		if (my iteration + maxNumOfIterations > my maxNumOfIterations) {
			my maxNumOfIterations += maxNumOfIterations;
			if (my history) { // clumsy because vector must have been allocated  before one can append
				NUMvector_append<double> (& my history, 1, & my maxNumOfIterations);
			} else {
				my history = NUMvector<double> (1, my maxNumOfIterations);
			}
		}
		if (monitor) {
			my gmonitor = (Graphics) Melder_monitor (0.0, U"Starting...");
		}
		my start = 1; /* for my after() */
		my v_minimize ();
		if (monitor) {
			monitor_off (me);
		}
		if (my success) Melder_casual (U"Minimizer_minimize:", U" minimum ", my minimum, U" reached \nafter ", my iteration,
			U" iterations and ", my funcCalls, U" function calls.");
	} catch (MelderError) {
		if (monitor) {
			monitor_off (me);    // temporarily until better monitor facilities
		}
		Melder_clearError(); // memory error in history mechanism is not fatal
	}
}
Пример #2
0
void Minimizer_minimize (Minimizer me, long maxNumOfIterations, double tolerance, int monitor) {
	try {

		my tolerance = tolerance;
		if (maxNumOfIterations <= 0) {
			return;
		}

		if (my iteration + maxNumOfIterations > my maxNumOfIterations) {
			double *history;
			my maxNumOfIterations += maxNumOfIterations;
			if (my history) {
				my history++;    /* arrays start at 1 !! */
			}
			history = (double *) Melder_realloc (my history, my maxNumOfIterations *
			                                     sizeof (double));
			my history = --history; /* arrays start at 1 !! */
		}
		if (monitor) {
			my gmonitor = (Graphics) Melder_monitor (0.0, L"Starting...");
		}
		my start = 1; /* for my after() */
		my v_minimize ();
		if (monitor) {
			monitor_off (me);
		}
		if (my success) Melder_casual ("Minimizer_minimize: minimum %f reached \n"
			                               "after %ld iterations and %ld function calls.", my minimum,
			                               my iteration, my funcCalls);
	} catch (MelderError) {
		if (monitor) {
			monitor_off (me);    // temporarily until better monitor facilities
		}
		Melder_clearError(); // memory error in history mechanism is not fatal
	}
}