BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DistributionHandler.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Param/Distrib/DistributionHandler.h
6 //! @brief Defines class DistributionHandler.
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 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_PARAM_DISTRIB_DISTRIBUTIONHANDLER_H
21 #define BORNAGAIN_PARAM_DISTRIB_DISTRIBUTIONHANDLER_H
22 
24 #include <functional>
25 #include <map>
26 #include <vector>
27 
28 //! Provides the functionality to average over parameter distributions with weights.
30 public:
33 
34  //! add a sampled parameter distribution
35  void addParameterDistribution(const std::string& param_name,
36  const IDistribution1D& distribution, size_t nbr_samples,
37  double sigma_factor = 0.0,
38  const RealLimits& limits = RealLimits());
39 
40  void addParameterDistribution(const ParameterDistribution& par_distr);
41 
42  //! get the total number of parameter value combinations (product
43  //! of the individual sizes of each parameter distribution
44  size_t getTotalNumberOfSamples() const;
45 
46  //! set the parameter values of the simulation object to a specific
47  //! combination of values, determined by the index (which must be smaller
48  //! than the total number of combinations) and returns the weight
49  //! associated with this combination of parameter values.
50  //! initParameterLinks() has to be called before this!
51  double setParameterValues(size_t index);
52 
53  const std::vector<ParameterDistribution>& getDistributions() const;
54 
56  std::function<void(double)> fn);
57 
58 private:
60  std::vector<ParameterDistribution> m_distributions;
61  std::map<const ParameterDistribution*, std::function<void(double)>> m_setValueFunctions;
62  std::vector<std::vector<ParameterSample>> m_cached_samples;
63 };
64 
65 #endif // BORNAGAIN_PARAM_DISTRIB_DISTRIBUTIONHANDLER_H
66 #endif // USER_API
Defines class ParameterDistribution.
Provides the functionality to average over parameter distributions with weights.
void addParameterDistribution(const std::string &param_name, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0, const RealLimits &limits=RealLimits())
add a sampled parameter distribution
double setParameterValues(size_t index)
set the parameter values of the simulation object to a specific combination of values,...
virtual ~DistributionHandler()
std::map< const ParameterDistribution *, std::function< void(double)> > m_setValueFunctions
const std::vector< ParameterDistribution > & getDistributions() const
void defineCallbackForDistribution(const ParameterDistribution *distribution, std::function< void(double)> fn)
size_t getTotalNumberOfSamples() const
get the total number of parameter value combinations (product of the individual sizes of each paramet...
std::vector< std::vector< ParameterSample > > m_cached_samples
std::vector< ParameterDistribution > m_distributions
Interface for one-dimensional distributions.
Definition: Distributions.h:33
A parametric distribution function, for use with any model parameter.
Limits for a real fit parameter.
Definition: RealLimits.h:24