Pallas Solver  0.1
C++ Global Optimization Algorithms
Classes | Public Member Functions | List of all members
pallas::Brute Class Reference

Minimizes an objective function by brute force, trying all possible combinations of specified parameter ranges and outputs the best solution found. More...

#include <brute.h>

Classes

struct  HistoryOutput
 Stores information about the state of the system for at a given iteration number. More...
 
struct  Options
 
struct  ParameterRange
 Range of values to test for the ith degree of freedom. More...
 
struct  Summary
 Contains a summary of the optimization. More...
 

Public Member Functions

 Brute ()
 Default constructor.
 
void Solve (const Brute::Options options, const GradientProblem &problem, const std::vector< Brute::ParameterRange > &parameter_ranges, double *parameters, Brute::Summary *global_summary)
 Minimizes the specified gradient problem. More...
 

Detailed Description

Minimizes an objective function by brute force, trying all possible combinations of specified parameter ranges and outputs the best solution found.

Example

#include "glog/logging.h"
// Each solver is defined in its own header file.
// include the solver you wish you use:
#include "pallas/brute.h"
// define a problem you wish to solve by inheriting
// from the pallas::GradientCostFunction interface
// and implementing the Evaluate and NumParameters methods.
class Rosenbrock : public pallas::GradientCostFunction {
public:
virtual ~Rosenbrock() {}
virtual bool Evaluate(const double* parameters,
double* cost,
double* gradient) const {
const double x = parameters[0];
const double y = parameters[1];
cost[0] = (1.0 - x) * (1.0 - x) + 100.0 * (y - x * x) * (y - x * x);
if (gradient != NULL) {
gradient[0] = -2.0 * (1.0 - x) - 200.0 * (y - x * x) * 2.0 * x;
gradient[1] = 200.0 * (y - x * x);
}
return true;
}
virtual int NumParameters() const { return 2; }
};
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
// define the starting point for the optimization
double parameters[2] = {-1.2, 0.0};
// set up global optimizer options only initialization
// is need to accept the default options
// initialize a summary object to hold the
// optimization details
// create a problem from your cost function
pallas::GradientProblem problem(new Rosenbrock());
// set up the subset of parameter space to test
std::vector<pallas::Brute::ParameterRange> ranges = {pallas::Brute::ParameterRange(-3.0, 3.0, 7),
// solve the problem and store the optimal position
// in parameters and the optimization details in
// the summary
pallas::Solve(options, problem, ranges, parameters, &summary);
std::cout << summary.FullReport() << std::endl;
std::cout << "Global minimum found at:" << std::endl;
std::cout << "\tx: " << parameters[0] << "\ty: " << parameters[1] << std::endl;
return 0;
}

Member Function Documentation

void pallas::Brute::Solve ( const Brute::Options  options,
const GradientProblem &  problem,
const std::vector< Brute::ParameterRange > &  parameter_ranges,
double *  parameters,
Brute::Summary global_summary 
)

Minimizes the specified gradient problem.

The specified options are used to setup a brute instance which is then used to minimize the GradientProblem. The optimal solution is stored in parameters and a summary of the global optimization can be found in summary.

Parameters
optionspallas::Brute::Options. Options used to configure the optimization.
problempallas::GradientProblem. The problem to optimize.
parametersdouble*. The starting point for further optimization.
summaryBrute::Summary*. Summary instance to store the optimization details.

Here is the caller graph for this function:


The documentation for this class was generated from the following files: