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

Public Types

using parameters_t = std::vector< Parameter >
 
using const_iterator = parameters_t::const_iterator
 
using iterator = parameters_t::iterator
 
using corr_matrix_t = std::vector< std::vector< double > >
 

Public Member Functions

 Parameters ()=default
 
void add (const Parameter &par)
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
size_t size () const
 
std::vector< double > values () const
 
void setValues (const std::vector< double > &values)
 
std::vector< double > errors () const
 
void setErrors (const std::vector< double > &errors)
 
const Parameteroperator[] (const std::string &name) const
 
const Parameteroperator[] (size_t index) const
 
corr_matrix_t correlationMatrix () const
 
void setCorrelationMatrix (const corr_matrix_t &matrix)
 
size_t freeParameterCount () const
 

Private Member Functions

bool exists (const std::string &parameter_name) const
 
void check_array_size (const std::vector< double > &values) const
 
size_t check_index (size_t index) const
 

Private Attributes

parameters_t m_parameters
 
corr_matrix_t m_corr_matrix
 

Detailed Description

A collection of fit parameters.

Definition at line 27 of file Parameters.h.

Member Typedef Documentation

◆ parameters_t

Definition at line 30 of file Parameters.h.

◆ const_iterator

using Fit::Parameters::const_iterator = parameters_t::const_iterator

Definition at line 31 of file Parameters.h.

◆ iterator

using Fit::Parameters::iterator = parameters_t::iterator

Definition at line 32 of file Parameters.h.

◆ corr_matrix_t

using Fit::Parameters::corr_matrix_t = std::vector<std::vector<double> >

Definition at line 33 of file Parameters.h.

Constructor & Destructor Documentation

◆ Parameters()

Fit::Parameters::Parameters ( )
default

Member Function Documentation

◆ add()

void Parameters::add ( const Parameter par)

Definition at line 22 of file Parameters.cpp.

23 {
24  if (exists(par.name()))
25  throw std::runtime_error("Parameters::add() -> Error. Parameter with the name '"
26  + par.name() + "' already exists.");
27 
28  m_parameters.push_back(par);
29 }
std::string name() const
Definition: Parameter.cpp:41
bool exists(const std::string &parameter_name) const
Definition: Parameters.cpp:141
parameters_t m_parameters
Definition: Parameters.h:66

References exists(), m_parameters, and Fit::Parameter::name().

Referenced by MinimizerTestPlan::parameters().

Here is the call graph for this function:

◆ begin() [1/2]

Parameters::const_iterator Parameters::begin ( ) const

Definition at line 31 of file Parameters.cpp.

32 {
33  return m_parameters.begin();
34 }

References m_parameters.

◆ end() [1/2]

Parameters::const_iterator Parameters::end ( ) const

Definition at line 36 of file Parameters.cpp.

37 {
38  return m_parameters.end();
39 }

References m_parameters.

◆ begin() [2/2]

Parameters::iterator Parameters::begin ( )

Definition at line 41 of file Parameters.cpp.

42 {
43  return m_parameters.begin();
44 }

References m_parameters.

◆ end() [2/2]

Parameters::iterator Parameters::end ( )

Definition at line 46 of file Parameters.cpp.

47 {
48  return m_parameters.end();
49 }

References m_parameters.

◆ size()

◆ values()

std::vector< double > Parameters::values ( ) const

Definition at line 56 of file Parameters.cpp.

57 {
58  std::vector<double> result;
59  for (const auto& par : m_parameters)
60  result.push_back(par.value());
61  return result;
62 }

References m_parameters.

Referenced by check_array_size(), and setValues().

◆ setValues()

void Parameters::setValues ( const std::vector< double > &  values)

Definition at line 64 of file Parameters.cpp.

65 {
67 
68  size_t index = 0;
69  for (auto& par : m_parameters) {
70  if (std::isnan(values[index]))
71  throw std::runtime_error("Parameters::setValues() -> Error."
72  " Attempt to set nan '"
73  + par.name() + "'.");
74  if (std::isinf(values[index]))
75  throw std::runtime_error("Parameters::setValues() -> Error. Attempt to set inf '"
76  + par.name() + "'.");
77  par.setValue(values[index]);
78  ++index;
79  }
80 }
std::vector< double > values() const
Definition: Parameters.cpp:56
void check_array_size(const std::vector< double > &values) const
Definition: Parameters.cpp:149

References check_array_size(), m_parameters, and values().

Referenced by Fit::ResidualFunctionAdapter::get_residuals(), RootMinimizerAdapter::propagateResults(), and Fit::ScalarFunctionAdapter::rootObjectiveFunction().

Here is the call graph for this function:

◆ errors()

std::vector< double > Parameters::errors ( ) const

Definition at line 82 of file Parameters.cpp.

83 {
84  std::vector<double> result;
85  for (const auto& par : m_parameters)
86  result.push_back(par.error());
87  return result;
88 }

References m_parameters.

Referenced by setErrors().

◆ setErrors()

void Parameters::setErrors ( const std::vector< double > &  errors)

Definition at line 90 of file Parameters.cpp.

91 {
93  size_t index = 0;
94  for (auto& par : m_parameters)
95  par.setError(errors[index++]);
96 }
std::vector< double > errors() const
Definition: Parameters.cpp:82

References check_array_size(), errors(), and m_parameters.

Referenced by RootMinimizerAdapter::propagateResults().

Here is the call graph for this function:

◆ operator[]() [1/2]

const Parameter & Parameters::operator[] ( const std::string &  name) const

Definition at line 98 of file Parameters.cpp.

99 {
100  for (const auto& par : m_parameters)
101  if (par.name() == name)
102  return par;
103 
104  std::ostringstream ostr;
105  ostr << "Parameters::operator[] -> Error. No parameter with name '" << name << "'. ";
106  ostr << "Existing names:\n";
107  for (const auto& par : m_parameters)
108  ostr << par.name() << "\n";
109  throw std::runtime_error(ostr.str());
110 }

References m_parameters, and Fit::Parameter::name().

Here is the call graph for this function:

◆ operator[]() [2/2]

const Parameter & Parameters::operator[] ( size_t  index) const

Definition at line 112 of file Parameters.cpp.

113 {
114  return m_parameters[check_index(index)];
115 }
size_t check_index(size_t index) const
Definition: Parameters.cpp:160

References check_index(), and m_parameters.

Here is the call graph for this function:

◆ correlationMatrix()

Parameters::corr_matrix_t Parameters::correlationMatrix ( ) const

Definition at line 117 of file Parameters.cpp.

118 {
119  return m_corr_matrix;
120 }
corr_matrix_t m_corr_matrix
correlation matrix
Definition: Parameters.h:67

References m_corr_matrix.

Referenced by MinimizerResultUtils::reportParameters().

◆ setCorrelationMatrix()

void Parameters::setCorrelationMatrix ( const corr_matrix_t matrix)

Definition at line 122 of file Parameters.cpp.

123 {
124  if (matrix.size() != size())
125  throw std::runtime_error("Parameters::setCorrelationMatrix() -> Error. Wrong "
126  "dimension of correlation matrix.");
127  m_corr_matrix = matrix;
128 }
size_t size() const
Definition: Parameters.cpp:51

References m_corr_matrix, and size().

Referenced by RootMinimizerAdapter::propagateResults().

Here is the call graph for this function:

◆ freeParameterCount()

size_t Parameters::freeParameterCount ( ) const

Returns number of free parameters.

Definition at line 132 of file Parameters.cpp.

133 {
134  size_t result(0);
135  for (const auto& par : m_parameters)
136  if (!par.limits().isFixed())
137  result++;
138  return result;
139 }

References m_parameters.

Referenced by Fit::ResidualFunctionAdapter::chi2().

◆ exists()

bool Parameters::exists ( const std::string &  parameter_name) const
private

Definition at line 141 of file Parameters.cpp.

142 {
143  for (const auto& par : m_parameters)
144  if (par.name() == name)
145  return true;
146  return false;
147 }

References m_parameters.

Referenced by add().

◆ check_array_size()

void Parameters::check_array_size ( const std::vector< double > &  values) const
private

Definition at line 149 of file Parameters.cpp.

150 {
151  if (values.size() != m_parameters.size()) {
152  std::ostringstream ostr;
153  ostr << "Parameters::check_array_size() -> Error. Size of input array " << values.size()
154  << " doesn't mach number of fit parameters " << m_parameters.size() << "."
155  << std::endl;
156  throw std::runtime_error(ostr.str());
157  }
158 }

References m_parameters, and values().

Referenced by setErrors(), and setValues().

Here is the call graph for this function:

◆ check_index()

size_t Parameters::check_index ( size_t  index) const
private

Definition at line 160 of file Parameters.cpp.

161 {
162  if (index >= m_parameters.size())
163  throw std::runtime_error("Parameters::check_index() -> Index out of bounds");
164  return index;
165 }

References m_parameters.

Referenced by operator[]().

Member Data Documentation

◆ m_parameters

parameters_t Fit::Parameters::m_parameters
private

◆ m_corr_matrix

corr_matrix_t Fit::Parameters::m_corr_matrix
private

correlation matrix

Definition at line 67 of file Parameters.h.

Referenced by correlationMatrix(), and setCorrelationMatrix().


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