BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MinimizerUtils Namespace Reference

Functions

std::string toString (const std::vector< std::string > &v, const std::string &delim="")
 
std::map< int, std::string > gslErrorDescriptionMap ()
 
std::string gslErrorDescription (int errorCode)
 
bool numbersDiffer (double a, double b, double tol)
 
std::string sectionString (const std::string &sectionName="", size_t report_width=80)
 

Detailed Description

Utility functions for fit library.

Function Documentation

◆ toString()

std::string MinimizerUtils::toString ( const std::vector< std::string > &  v,
const std::string &  delim = "" 
)

Definition at line 21 of file MinimizerUtils.cpp.

22 {
23  std::stringstream s;
24  std::for_each(v.begin(), v.end(),
25  [&s, &delim](const std::string& elem) { s << elem << delim; });
26  return s.str();
27 }

Referenced by MinimizerCatalog::toString().

◆ gslErrorDescriptionMap()

std::map< int, std::string > MinimizerUtils::gslErrorDescriptionMap ( )

Returns translation of GSL error code to string.

Definition at line 31 of file MinimizerUtils.cpp.

32 {
33  std::map<int, std::string> result;
34 
35  result[0] = "OK, valid minimum";
36  result[-2] = "iteration has not converged";
37  result[1] = "input domain error, e.g sqrt(-1)";
38  result[2] = "output range error, e.g. exp(1e100)";
39  result[3] = "invalid pointer";
40  result[4] = "invalid argument supplied by user";
41  result[5] = "generic failure";
42  result[6] = "factorization failed";
43  result[7] = "sanity check failed - shouldn't happen";
44  result[8] = "malloc failed";
45  result[9] = "problem with user-supplied function";
46  result[10] = "iterative process is out of control";
47  result[11] = "exceeded max number of iterations";
48  result[12] = "tried to divide by zero";
49  result[13] = "user specified an invalid tolerance";
50  result[14] = "failed to reach the specified tolerance";
51  result[15] = "underflow";
52  result[16] = "overflow ";
53  result[17] = "loss of accuracy";
54  result[18] = "failed because of roundoff error";
55  result[19] = "matrix, vector lengths are not conformant";
56  result[20] = "matrix not square";
57  result[21] = "apparent singularity detected";
58  result[22] = "integral or series is divergent";
59  result[23] = "requested feature is not supported by the hardware";
60  result[24] = "requested feature not (yet) implemented";
61  result[25] = "cache limit exceeded";
62  result[26] = "table limit exceeded";
63  result[27] = "iteration is not making progress towards solution";
64  result[28] = "jacobian evaluations are not improving the solution";
65  result[29] = "cannot reach the specified tolerance in F";
66  result[30] = "cannot reach the specified tolerance in X";
67  result[31] = "cannot reach the specified tolerance in gradient";
68 
69  return result;
70 }

Referenced by gslErrorDescription().

◆ gslErrorDescription()

std::string MinimizerUtils::gslErrorDescription ( int  errorCode)

Definition at line 72 of file MinimizerUtils.cpp.

73 {
74  static std::map<int, std::string> errorDescription = gslErrorDescriptionMap();
75 
76  auto it = errorDescription.find(errorCode);
77  if (it != errorDescription.end())
78  return it->second;
79 
80  return "Unknown error";
81 }
std::map< int, std::string > gslErrorDescriptionMap()
Returns translation of GSL error code to string.

References gslErrorDescriptionMap().

Referenced by GSLLevenbergMarquardtMinimizer::statusToString(), and GSLMultiMinimizer::statusToString().

Here is the call graph for this function:

◆ numbersDiffer()

bool MinimizerUtils::numbersDiffer ( double  a,
double  b,
double  tol 
)

Definition at line 83 of file MinimizerUtils.cpp.

84 {
85  constexpr double eps = std::numeric_limits<double>::epsilon();
86  if (tol < 1)
87  throw std::runtime_error("MinimizerUtils::numbersDiffer() -> Error.Not intended for tol<1");
88  return std::abs(a - b) > eps * std::max(tol * eps, std::abs(b));
89 }

References anonymous_namespace{PolyhedralComponents.cpp}::eps.

◆ sectionString()

std::string MinimizerUtils::sectionString ( const std::string &  sectionName = "",
size_t  report_width = 80 
)

Returns horizontal line of 80 characters length with section name in it.

Definition at line 93 of file MinimizerUtils.cpp.

94 {
95  if (sectionName.empty())
96  return std::string(report_width, '-') + "\n";
97  // to make "--- SectionName ------------------------------"
98  std::string prefix(3, '-');
99  std::string body = std::string(" ") + sectionName + " ";
100  std::string postfix(report_width - body.size() - prefix.size(), '-');
101  std::ostringstream result;
102  result << prefix << body << postfix << std::endl;
103  return result.str();
104 }

Referenced by anonymous_namespace{MinimizerResultUtils.cpp}::reportOption(), MinimizerResultUtils::reportParameters(), anonymous_namespace{MinimizerResultUtils.cpp}::reportStatus(), MinimizerResultUtils::reportToString(), and Fit::MinimizerResult::toString().