GridOptimizer
core/OPT/optimizers/Grid.h Extends: -
Template class to optimize a given ScalarField over an N-dimensional grid of equidistant nodes.
The class simulates the construction of an N-dimensional rectangle splitted along each interval according to a given grid step (the grid step can possibly differ for each dimension). The search is performed using an exhaustive search over the N-dimensional grid.
Warning
Since this optimization algorithm applies just an exhaustive search without any heuristic the resulting time complexity is exponential in the dimension of the grid N. The method can be very slow for values of N bigger than 2.
Methods
GridOptimizer(std::array<std::pair<double,double>, N> domain, std::array<double, N> steps,
const ScalarField<N>& objective_)
Constructor. It sets the shape of the domain where to search for the optimum of the objective as well as the grid step for each dimension.
Args | Description |
---|---|
std::array<std::pair<double,double>,N> |
An array of exactly N pairs where pair represents infimum and superior limit of the interval along the -th dimension |
std::array<double,N> steps |
An array of exactly N doubles where the -th element defines the grid step along the -th dimension |
const ScalarField<N>& objective_ |
The objective function to optimize |
Apply the search strategy to the objective passed as argument. Returns std::pair<SVector<N>,double>
where the first element is the point in the grid where the minimum is reached while the second one is the actual minimum value reached by the objective.
Info
During the search no grid is actually stored in memory making the call at least memory efficient.
Examples
The following code finds the minimum of function over a grid of points defined in with grid step 0.01 for each dimension