BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParameterDistribution.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Param/Distrib/ParameterDistribution.cpp
6 //! @brief Implements class ParameterDistribution.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
16 #include "Base/Types/Exceptions.h"
18 
20  const IDistribution1D& distribution,
21  size_t nbr_samples, double sigma_factor,
22  const RealLimits& limits)
23  : IParameterized("ParameterDistribution"), m_name(par_name), m_nbr_samples(nbr_samples),
24  m_sigma_factor(sigma_factor), m_limits(limits), m_xmin(1.0), m_xmax(-1.0)
25 {
26  mP_distribution.reset(distribution.clone());
27  if (m_sigma_factor < 0.0)
29  "ParameterDistribution::ParameterDistribution() -> Error."
30  "sigma factor cannot be negative");
31  if (nbr_samples == 0)
33  "ParameterDistribution::ParameterDistribution() -> Error."
34  "Number of samples can't be zero.");
35 }
36 
38  const IDistribution1D& distribution,
39  size_t nbr_samples, double xmin, double xmax)
40  : IParameterized("ParameterDistribution"), m_name(par_name), m_nbr_samples(nbr_samples),
41  m_sigma_factor(0.0), m_xmin(xmin), m_xmax(xmax)
42 {
43  mP_distribution.reset(distribution.clone());
44  if (m_sigma_factor < 0.0) {
46  "ParameterDistribution::ParameterDistribution() -> Error."
47  "sigma factor cannot be negative");
48  }
49  if (nbr_samples == 0) {
51  "ParameterDistribution::ParameterDistribution() -> Error."
52  "Number of samples can't be zero.");
53  }
54  if (xmin >= xmax) {
56  "ParameterDistribution::ParameterDistribution() -> Error."
57  "xmin>=xmax");
58  }
59 }
60 
62  : IParameterized("ParameterDistribution"), m_name(other.m_name),
63  m_nbr_samples(other.m_nbr_samples), m_sigma_factor(other.m_sigma_factor),
64  m_linked_par_names(other.m_linked_par_names), m_limits(other.m_limits), m_xmin(other.m_xmin),
65  m_xmax(other.m_xmax)
66 {
67  mP_distribution.reset(other.mP_distribution->clone());
68 }
69 
71 
73 {
74  if (this != &other) {
75  this->m_name = other.m_name;
78  mP_distribution.reset(other.mP_distribution->clone());
80  m_limits = other.m_limits;
81  m_xmin = other.m_xmin;
82  m_xmax = other.m_xmax;
83  }
84  return *this;
85 }
86 
88 {
89  m_linked_par_names.push_back(par_name);
90  return *this;
91 }
92 
94 {
95  if (mP_distribution && mP_distribution->isDelta())
96  return 1;
97  return m_nbr_samples;
98 }
99 
100 std::vector<ParameterSample> ParameterDistribution::generateSamples() const
101 {
102  if (m_xmin < m_xmax)
103  return mP_distribution->equidistantSamplesInRange(m_nbr_samples, m_xmin, m_xmax);
104  else
105  return mP_distribution->equidistantSamples(m_nbr_samples, m_sigma_factor, m_limits);
106 }
107 
109 {
110  return mP_distribution.get();
111 }
112 
114 {
115  return mP_distribution.get();
116 }
Defines classes representing one-dimensional distributions.
Defines many exception classes in namespace Exceptionss.
Defines class ParameterDistribution.
Interface for one-dimensional distributions.
Definition: Distributions.h:33
virtual IDistribution1D * clone() const =0
Manages a local parameter pool, and a tree of child pools.
A parametric distribution function, for use with any model parameter.
ParameterDistribution & operator=(const ParameterDistribution &other)
Overload assignment operator.
size_t getNbrSamples() const
get number of samples for this distribution
std::unique_ptr< IDistribution1D > mP_distribution
const IDistribution1D * getDistribution() const
ParameterDistribution(const std::string &par_name, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0, const RealLimits &limits=RealLimits())
ParameterDistribution & linkParameter(std::string par_name)
std::vector< ParameterSample > generateSamples() const
generate list of sampled values with their weight
std::vector< std::string > m_linked_par_names
virtual ~ParameterDistribution()
Limits for a real fit parameter.
Definition: RealLimits.h:25