BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MinimizerFactory Class Reference
Collaboration diagram for MinimizerFactory:

Static Public Member Functions

static IMinimizercreateMinimizer (const std::string &minimizerName, const std::string &algorithmType="", const std::string &optionString="")
 
static void printCatalog ()
 
static std::string catalogToString ()
 
static std::string catalogDetailsToString ()
 
static const MinimizerCatalogcatalog ()
 

Detailed Description

Factory to create minimizers.

Definition at line 26 of file MinimizerFactory.h.

Member Function Documentation

◆ createMinimizer()

IMinimizer * MinimizerFactory::createMinimizer ( const std::string &  minimizerName,
const std::string &  algorithmType = "",
const std::string &  optionString = "" 
)
static

Definition at line 28 of file MinimizerFactory.cpp.

31 {
32  IMinimizer* result(0);
33 
34  if (minimizerName == "Minuit2") {
35  result = new Minuit2Minimizer(algorithmType);
36  }
37 
38  else if (minimizerName == "GSLLMA") {
39  result = new GSLLevenbergMarquardtMinimizer();
40  }
41 
42  else if (minimizerName == "GSLSimAn") {
43  result = new SimAnMinimizer();
44  }
45 
46  else if (minimizerName == "GSLMultiMin") {
47  result = new GSLMultiMinimizer(algorithmType);
48  }
49 
50  else if (minimizerName == "Genetic") {
51  result = new GeneticMinimizer();
52  }
53 
54  else if (minimizerName == "Test") {
55  result = new TestMinimizer();
56  }
57 
58  if (!result) {
59  std::ostringstream ostr;
60  ostr << "MinimizerFactory::MinimizerFactory() -> Error! Can't create minimizer for given "
61  "collection name '"
62  << minimizerName << "' or algorithm '" << algorithmType << "'" << std::endl;
63  ostr << "Possible names are:" << std::endl;
64 
65  ostr << catalog().toString();
66  throw std::runtime_error(ostr.str());
67  }
68 
69  if (!optionString.empty())
70  result->setOptions(optionString);
71 
72  return result;
73 }
It's a facade to ROOT::Math::GSLNLSMinimizer which, in turn, is a facade to the actual GSL's gsl_mult...
Wrapper for the CERN ROOT facade of the GSL multi minimizer family (gradient descent based).
Wrapper for the CERN ROOT Genetic minimizer.
Pure virtual interface for all kind minimizers.
Definition: IMinimizer.h:31
std::string toString() const
Returns multiline string representing catalog content.
static const MinimizerCatalog & catalog()
Wrapper for the CERN ROOT facade of the Minuit2 minimizer.
Wrapper for the CERN ROOT facade of the GSL simmulated annealing minimizer.
A trivial minimizer that calls the objective function once. Used to test the whole chain.
Definition: TestMinimizer.h:23

References catalog(), IMinimizer::setOptions(), and MinimizerCatalog::toString().

Referenced by catalogDetailsToString(), and Fit::Kernel::setMinimizer().

Here is the call graph for this function:

◆ printCatalog()

void MinimizerFactory::printCatalog ( )
static

Definition at line 75 of file MinimizerFactory.cpp.

76 {
77  std::cout << catalogToString() << std::endl;
78 }
static std::string catalogToString()
Returns multi-line string representing catalog content: minimizer names and list of their algorithms.

References catalogToString().

Here is the call graph for this function:

◆ catalogToString()

std::string MinimizerFactory::catalogToString ( )
static

Returns multi-line string representing catalog content: minimizer names and list of their algorithms.

Definition at line 83 of file MinimizerFactory.cpp.

84 {
85  return catalog().toString();
86 }

References catalog(), and MinimizerCatalog::toString().

Referenced by printCatalog().

Here is the call graph for this function:

◆ catalogDetailsToString()

std::string MinimizerFactory::catalogDetailsToString ( )
static

Returns multi-line string representing detailed catalog content: minimizer names, list of their algorithms and description, list of minimizer options.

Definition at line 91 of file MinimizerFactory.cpp.

92 {
93  const int text_width = 80;
94  std::ostringstream result;
95  const std::string fmt("%-20s| %-65s\n");
96 
97  for (const auto& minimizerName : catalog().minimizerNames()) {
98  // general info
99  const MinimizerInfo& info = catalog().minimizerInfo(minimizerName);
100  result << std::string(text_width, '-') << "\n";
101  result << boost::format(fmt) % info.name() % info.description();
102  result << std::string(text_width, '-') << "\n";
103 
104  // algorithm names and description
105  result << "\nAlgorithm names\n";
106  auto algorithmNames = info.algorithmNames();
107  auto algorithmDescription = info.algorithmDescriptions();
108  for (size_t i = 0; i < algorithmNames.size(); ++i)
109  result << boost::format(fmt) % algorithmNames[i] % algorithmDescription[i];
110  if (algorithmNames.size() > 1)
111  result << boost::format(fmt) % "Default algorithm" % info.algorithmName();
112 
113  // list of minimizer options
114  std::unique_ptr<IMinimizer> minimizer(createMinimizer(minimizerName));
115  if (auto rootMinimizer = dynamic_cast<RootMinimizerAdapter*>(minimizer.get())) {
116  result << "\nOptions\n";
117  for (auto option : rootMinimizer->options()) {
118  std::ostringstream opt;
119  opt << std::setw(5) << std::left << option->value() << option->description();
120  result << boost::format(fmt) % option->name() % opt.str();
121  }
122  }
123 
124  result << "\n";
125  }
126 
127  return result.str();
128 }
const MinimizerInfo & minimizerInfo(const std::string &minimizerName) const
Returns info for minimizer with given name.
static IMinimizer * createMinimizer(const std::string &minimizerName, const std::string &algorithmType="", const std::string &optionString="")
Info about a minimizer, including list of defined minimization algorithms.
Definition: MinimizerInfo.h:45
std::string algorithmName() const
Definition: MinimizerInfo.h:59
std::vector< std::string > algorithmDescriptions() const
Returns list of string with description of all available algorithms.
std::string name() const
Definition: MinimizerInfo.h:56
std::string description() const
Definition: MinimizerInfo.h:57
std::vector< std::string > algorithmNames() const
Return list of defined algorithm names.
Pure virtual interface that adapts the CERN ROOT minimizer to our IMinimizer.

References MinimizerInfo::algorithmDescriptions(), MinimizerInfo::algorithmName(), MinimizerInfo::algorithmNames(), catalog(), createMinimizer(), MinimizerInfo::description(), MinimizerCatalog::minimizerInfo(), and MinimizerInfo::name().

Here is the call graph for this function:

◆ catalog()

const MinimizerCatalog & MinimizerFactory::catalog ( )
static

Definition at line 130 of file MinimizerFactory.cpp.

131 {
132  static MinimizerCatalog s_catalog;
133  return s_catalog;
134 }
Hard-coded information about all minimizers available.

Referenced by catalogDetailsToString(), catalogToString(), and createMinimizer().


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