BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FitPrintService Class Reference

Prints fit statistics to standard output during minimizer iterations. More...

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
 

Detailed Description

Prints fit statistics to standard output during minimizer iterations.

Definition at line 30 of file FitPrintService.h.

Constructor & Destructor Documentation

◆ FitPrintService()

FitPrintService::FitPrintService ( )
default

Member Function Documentation

◆ fitResultString()

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

Definition at line 96 of file FitPrintService.cpp.

97 {
98  std::ostringstream result;
99 
100  m_run_time.stop();
101 
102  result << "This was the last iteration." << std::endl;
103  result << "Total time spend: " << std::fixed << std::setprecision(2) << m_run_time.runTime()
104  << " sec."
105  << "\n\n";
106 
107  result << objective.minimizerResult().toString();
108  return result.str();
109 }
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 57 of file FitPrintService.cpp.

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

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

Referenced by print().

Here is the call graph for this function:

◆ parameterString()

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

Definition at line 80 of file FitPrintService.cpp.

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

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

Referenced by print().

Here is the call graph for this function:

◆ print()

void FitPrintService::print ( const FitObjective objective)

Definition at line 38 of file FitPrintService.cpp.

39 {
40  std::ostringstream ostr;
41 
42  if (objective.isFirstIteration()) {
43  m_run_time.start();
45  }
46 
47  ostr << iterationHeaderString(objective);
48  ostr << wallTimeString();
49  ostr << parameterString(objective);
50 
51  if (objective.isCompleted())
52  ostr << fitResultString(objective);
53 
54  std::cout << ostr.str() << "\n";
55 }
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 68 of file FitPrintService.cpp.

69 {
70  std::ostringstream result;
71 
73  result << "Wall time since last call:" << std::fixed << std::setprecision(2)
74  << m_last_call_time.runTime() << "\n";
76 
77  return result.str();
78 }

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: