BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
FitPrintService Class Reference

Description

Prints fit statistics to standard output during minimizer iterations.

Definition at line 30 of file FitPrintService.h.

Collaboration diagram for FitPrintService:
[legend]

Public Member Functions

 FitPrintService ()
 
void print (const FitObjective &objective)
 

Private Member Functions

std::string fitResultString (const FitObjective &objective)
 
std::string iterationHeaderString (const FitObjective &objective)
 
std::string parameterString (const FitObjective &objective)
 
std::string wallTimeString ()
 

Private Attributes

WallclockTimer m_last_call_time
 
WallclockTimer m_run_time
 

Constructor & Destructor Documentation

◆ FitPrintService()

FitPrintService::FitPrintService ( )
default

Member Function Documentation

◆ fitResultString()

std::string FitPrintService::fitResultString ( const FitObjective objective)
private

Definition at line 98 of file FitPrintService.cpp.

99 {
100  std::ostringstream result;
101 
102  m_run_time.stop();
103 
104  result << "This was the last iteration." << std::endl;
105  result << "Total time spend: " << std::fixed << std::setprecision(2) << m_run_time.runTime()
106  << " sec."
107  << "\n\n";
108 
109  result << objective.minimizerResult().toString();
110  return result.str();
111 }
mumufit::MinimizerResult minimizerResult() const
WallclockTimer m_run_time
double runTime() const
Returns run time in sec.
std::string toString() const
Returns multi-line string representing minimization results.

References m_run_time, FitObjective::minimizerResult(), WallclockTimer::runTime(), WallclockTimer::stop(), and mumufit::MinimizerResult::toString().

Referenced by print().

Here is the call graph for this function:

◆ iterationHeaderString()

std::string FitPrintService::iterationHeaderString ( const FitObjective objective)
private

Definition at line 59 of file FitPrintService.cpp.

60 {
61  std::ostringstream result;
62 
63  result << "FitPrintService::update() -> Info."
64  << " NCall:" << objective.iterationInfo().iterationCount() << " Chi2:" << std::scientific
65  << std::setprecision(8) << objective.iterationInfo().chi2() << "\n";
66 
67  return result.str();
68 }
IterationInfo iterationInfo() const
unsigned iterationCount() const
Returns current number of minimizer iterations.
double chi2() const
std::string scientific(T value, int n=10)
Returns scientific string representing given value of any numeric type.
Definition: StringUtils.h:75

References IterationInfo::chi2(), IterationInfo::iterationCount(), FitObjective::iterationInfo(), and BaseUtils::String::scientific().

Referenced by print().

Here is the call graph for this function:

◆ parameterString()

std::string FitPrintService::parameterString ( const FitObjective objective)
private

Definition at line 82 of file FitPrintService.cpp.

83 {
84  std::ostringstream result;
85 
86  const auto params = objective.iterationInfo().parameters();
87  const auto length = length_of_longest_name(params);
88 
89  for (const auto& par : params) {
90  result << BaseUtils::String::padRight(par.name(), length) << std::scientific
91  << std::setprecision(6) << " " << par.startValue() << " " << par.limits().toString()
92  << " " << par.value() << "\n";
93  }
94 
95  return result.str();
96 }
mumufit::Parameters parameters() const
std::string padRight(const std::string &name, size_t length)
Returns string right-padded with blanks.
Definition: StringUtils.cpp:21

References FitObjective::iterationInfo(), BaseUtils::String::padRight(), IterationInfo::parameters(), and BaseUtils::String::scientific().

Referenced by print().

Here is the call graph for this function:

◆ print()

void FitPrintService::print ( const FitObjective objective)

Definition at line 40 of file FitPrintService.cpp.

41 {
42  std::ostringstream ostr;
43 
44  if (objective.isFirstIteration()) {
45  m_run_time.start();
47  }
48 
49  ostr << iterationHeaderString(objective);
50  ostr << wallTimeString();
51  ostr << parameterString(objective);
52 
53  if (objective.isCompleted())
54  ostr << fitResultString(objective);
55 
56  std::cout << ostr.str() << "\n";
57 }
bool isFirstIteration() const
bool isCompleted() const
WallclockTimer m_last_call_time
std::string parameterString(const FitObjective &objective)
std::string fitResultString(const FitObjective &objective)
std::string iterationHeaderString(const FitObjective &objective)
std::string wallTimeString()

References fitResultString(), FitObjective::isCompleted(), FitObjective::isFirstIteration(), iterationHeaderString(), m_last_call_time, m_run_time, parameterString(), WallclockTimer::start(), and wallTimeString().

Here is the call graph for this function:

◆ wallTimeString()

std::string FitPrintService::wallTimeString ( )
private

Definition at line 70 of file FitPrintService.cpp.

71 {
72  std::ostringstream result;
73 
75  result << "Wall time since last call:" << std::fixed << std::setprecision(2)
76  << m_last_call_time.runTime() << "\n";
78 
79  return result.str();
80 }

References m_last_call_time, WallclockTimer::runTime(), WallclockTimer::start(), and WallclockTimer::stop().

Referenced by print().

Here is the call graph for this function:

Member Data Documentation

◆ m_last_call_time

WallclockTimer FitPrintService::m_last_call_time
private

Definition at line 43 of file FitPrintService.h.

Referenced by print(), and wallTimeString().

◆ m_run_time

WallclockTimer FitPrintService::m_run_time
private

Definition at line 42 of file FitPrintService.h.

Referenced by fitResultString(), and print().


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