|
SDDS ToolKit Programs and Libraries for C and Python
|
Functions for performing grid search and random search minimization on an N-dimensional function.
This file provides several methods for locating the minimum of a function that may be expensive or complicated to evaluate. The methods include:
Definition in file gridopt.c.
#include "mdb.h"Go to the source code of this file.
Functions | |
| long | optimAbort (long abort) |
| Set or query the abort condition for optimization routines. | |
| long | grid_search_min (double *best_result, double *xReturn, double *lower, double *upper, double *step, long n_dimen, double target, double(*func)(double *x, long *invalid)) |
| Perform a grid search to find the minimum of a given function. | |
| long | grid_sample_min (double *best_result, double *xReturn, double *lower, double *upper, double *step, long n_dimen, double target, double(*func)(double *x, long *invalid), double sample_fraction, double(*random_f)(long iseed)) |
| Perform a partial (sampled) grid search to find the minimum of a function. | |
| long | randomSampleMin (double *best_result, double *xReturn, double *lower, double *upper, long n_dimen, double target, double(*func)(double *x, long *invalid), long nSamples, double(*random_f)(long iseed)) |
| Randomly sample the parameter space to find a minimum. | |
| long | randomWalkMin (double *best_result, double *xReturn, double *lower, double *upper, double *stepSize, long n_dimen, double target, double(*func)(double *x, long *invalid), long nSamples, double(*random_f)(long iseed)) |
| Perform a random walk starting from a given point to find a function minimum. | |
| long grid_sample_min | ( | double * | best_result, |
| double * | xReturn, | ||
| double * | lower, | ||
| double * | upper, | ||
| double * | step, | ||
| long | n_dimen, | ||
| double | target, | ||
| double(* | func )(double *x, long *invalid), | ||
| double | sample_fraction, | ||
| double(* | random_f )(long iseed) ) |
Perform a partial (sampled) grid search to find the minimum of a function.
This routine performs a grid-based search similar to grid_search_min(), but only evaluates a fraction of the points, chosen randomly. It returns the best found minimum and updates xReturn with the coordinates of that minimum.
| best_result | Pointer to a double that will store the best function value found. |
| xReturn | Pointer to an array that will be updated with the coordinates of the minimum. |
| lower | Array specifying the lower bounds of each dimension. |
| upper | Array specifying the upper bounds of each dimension. |
| step | Array specifying the step sizes for each dimension. |
| n_dimen | The number of dimensions. |
| target | The target function value to achieve or surpass. |
| func | The function to minimize. |
| sample_fraction | The fraction or number of points to sample from the grid. |
| random_f | Optional random function for generating samples (default random_1). |
Definition at line 154 of file gridopt.c.
| long grid_search_min | ( | double * | best_result, |
| double * | xReturn, | ||
| double * | lower, | ||
| double * | upper, | ||
| double * | step, | ||
| long | n_dimen, | ||
| double | target, | ||
| double(* | func )(double *x, long *invalid) ) |
Perform a grid search to find the minimum of a given function.
Given ranges and steps for each dimension, this function systematically evaluates the target function over a grid of points. It returns the best found minimum and updates xReturn with the coordinates of that minimum.
| best_result | Pointer to a double that will store the best function value found. |
| xReturn | Pointer to an array that will be updated with the coordinates of the minimum. |
| lower | Array specifying the lower bounds of each dimension. |
| upper | Array specifying the upper bounds of each dimension. |
| step | Array specifying the step sizes for each dimension. |
| n_dimen | The number of dimensions in the parameter space. |
| target | The target function value to achieve or surpass. |
| func | A pointer to the function to minimize, taking coordinates and returning a value and validity flag. |
Definition at line 64 of file gridopt.c.
| long optimAbort | ( | long | abort | ) |
Set or query the abort condition for optimization routines.
When called with a non-zero parameter, this function sets an internal flag that signals the optimization routines to abort their search. When called with zero, it returns the current state of the abort flag.
| abort | If non-zero, sets the abort condition. If zero, simply queries it. |
Definition at line 39 of file gridopt.c.
| long randomSampleMin | ( | double * | best_result, |
| double * | xReturn, | ||
| double * | lower, | ||
| double * | upper, | ||
| long | n_dimen, | ||
| double | target, | ||
| double(* | func )(double *x, long *invalid), | ||
| long | nSamples, | ||
| double(* | random_f )(long iseed) ) |
Randomly sample the parameter space to find a minimum.
This routine randomly samples points in the given parameter space (defined by lower and upper bounds) for a specified number of samples. It returns the best found minimum and updates xReturn with its coordinates.
| best_result | Pointer to a double that will store the best function value found. |
| xReturn | Pointer to an array that will be updated with the coordinates of the minimum. |
| lower | Array specifying the lower bounds of each dimension. |
| upper | Array specifying the upper bounds of each dimension. |
| n_dimen | The number of dimensions. |
| target | The target function value. |
| func | The function to minimize. |
| nSamples | The number of random samples to try. |
| random_f | Optional random function for sampling (default random_1). |
Definition at line 256 of file gridopt.c.
| long randomWalkMin | ( | double * | best_result, |
| double * | xReturn, | ||
| double * | lower, | ||
| double * | upper, | ||
| double * | stepSize, | ||
| long | n_dimen, | ||
| double | target, | ||
| double(* | func )(double *x, long *invalid), | ||
| long | nSamples, | ||
| double(* | random_f )(long iseed) ) |
Perform a random walk starting from a given point to find a function minimum.
This function starts at a user-supplied point and randomly perturbs it within given bounds and step sizes. It evaluates the function at each new point, seeking improvements. If a better minimum is found, xReturn is updated.
| best_result | Pointer to a double that will store the best found function value. |
| xReturn | Pointer to an array with the starting coordinates, updated on success. |
| lower | Array specifying the lower bounds for each dimension. |
| upper | Array specifying the upper bounds for each dimension. |
| stepSize | Array specifying the maximum step size for random perturbations in each dimension. |
| n_dimen | The number of dimensions. |
| target | The target function value. |
| func | The function to minimize. |
| nSamples | The number of random steps to take. |
| random_f | Optional random function (default random_1). |
Definition at line 321 of file gridopt.c.