source: src/RandomNumbers/RandomNumberDistribution_Encapsulation.hpp@ 1a6bda

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 1a6bda was 0275ad, checked in by Frederik Heber <heber@…>, 14 years ago

Final step in Random numbers is done ...

  • Property mode set to 100644
File size: 11.8 KB
Line 
1/*
2 * RandomNumberDistribution_Encapsulation.hpp
3 *
4 * Created on: Jan 01, 2011
5 * Author: heber
6 */
7
8#ifndef RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_
9#define RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include "CodePatterns/Assert.hpp"
17
18#include <typeinfo>
19
20#include <boost/nondet_random.hpp>
21#include <boost/random.hpp>
22#include <boost/random/bernoulli_distribution.hpp>
23#include <boost/random/binomial_distribution.hpp>
24#include <boost/random/cauchy_distribution.hpp>
25#include <boost/random/exponential_distribution.hpp>
26#include <boost/random/gamma_distribution.hpp>
27#include <boost/random/geometric_distribution.hpp>
28#include <boost/random/linear_congruential.hpp>
29#include <boost/random/lognormal_distribution.hpp>
30#include <boost/random/normal_distribution.hpp>
31#include <boost/random/poisson_distribution.hpp>
32#include <boost/random/triangle_distribution.hpp>
33#include <boost/random/uniform_01.hpp>
34#include <boost/random/uniform_int.hpp>
35#include <boost/random/uniform_on_sphere.hpp>
36#include <boost/random/uniform_real.hpp>
37#include <boost/random/uniform_smallint.hpp>
38
39#include "CodePatterns/ManipulableClone.hpp"
40#include "RandomNumberDistribution.hpp"
41
42#include "RandomNumberDistribution_Parameters.hpp"
43
44class RandomNumberDistributionFactory;
45
46/** Template class that encapsulates the random number distributions from
47 * random::boost.
48 *
49 *
50 * We need one template parameters:
51 * -# the distribution - generates uniform random numbers
52 */
53template <class distribution>
54class RandomNumberDistribution_Encapsulation :
55 public RandomNumberDistribution,
56 public ManipulableClone<RandomNumberDistribution, RandomNumberDistribution_Parameters>
57{
58 /**
59 * Factory is friend such that it can access private cstor when filling its
60 * table
61 */
62 friend class RandomNumberDistributionFactory;
63
64public:
65 /** Getter for the whole set of possible parameters.
66 *
67 * @return filled instance of RandomNumberDistribution_Parameters
68 */
69 RandomNumberDistribution_Parameters* getParameterSet() const
70 {
71 RandomNumberDistribution_Parameters *params = new RandomNumberDistribution_Parameters();
72 params->getParameters(this);
73 return params;
74 }
75
76 /** Getter for smallest value the uniform_... engines produces.
77 *
78 * @return smallest value
79 */
80 double min() const {
81 return RandomNumberDistribution_Parameters::noset_value;
82 }
83
84 /** Getter for largest value the uniform_... engines produces.
85 *
86 * @return largest value
87 */
88 double max() const {
89 return RandomNumberDistribution_Parameters::noset_value;
90 }
91
92 /** Getter for bernoulli_distribution's probability p.
93 *
94 * @return p
95 */
96 double p() const {
97 return RandomNumberDistribution_Parameters::noset_value;
98 }
99
100 /** Getter for binomial_distribution's parameter t.
101 *
102 * @return t
103 */
104 double t() const {
105 return RandomNumberDistribution_Parameters::noset_value;
106 }
107
108 /** Getter for cauchy_distribution parameter median.
109 *
110 * @return median
111 */
112 double median() const {
113 return RandomNumberDistribution_Parameters::noset_value;
114 }
115
116 /** Getter for cauchy_distribution parameter sigma.
117 *
118 * @return sigma
119 */
120 double sigma() const {
121 return RandomNumberDistribution_Parameters::noset_value;
122 }
123
124 /** Getter for gamma_distribution parameter alpha.
125 *
126 * @return alpha
127 */
128 double alpha() const {
129 return RandomNumberDistribution_Parameters::noset_value;
130 }
131
132 /** Getter for poisson_distribution's parameter mean.
133 *
134 * @return mean
135 */
136 double mean() const {
137 return RandomNumberDistribution_Parameters::noset_value;
138 }
139
140 /** Getter for triangle_distribution parameter a.
141 *
142 * @return a
143 */
144 double a() const {
145 return RandomNumberDistribution_Parameters::noset_value;
146 }
147
148 /** Getter for triangle_distribution parameter b.
149 *
150 * @return b
151 */
152 double b() const {
153 return RandomNumberDistribution_Parameters::noset_value;
154 }
155
156 /** Getter for triangle_distribution parameter c.
157 *
158 * @return c
159 */
160 double c() const {
161 return RandomNumberDistribution_Parameters::noset_value;
162 }
163
164 /** Getter for exponential_distribution parameter lambda.
165 *
166 * @return lambda
167 */
168 double lambda() const {
169 return RandomNumberDistribution_Parameters::noset_value;
170 }
171
172 /** Getter for the type name of the internal distribution.
173 *
174 */
175 std::string name() {
176 return typeid(distribution_type).name();
177 }
178
179 /** Getter for the distribution instance.
180 *
181 * @return reference to instance
182 */
183 distribution& getDistribution() {
184 return distribution_type;
185 }
186
187 /** Clones the current instance.
188 *
189 * Implementation of Clone pattern.
190 *
191 * @return interface reference to cloned instance
192 */
193 RandomNumberDistribution* clone() const {
194 RandomNumberDistribution* MyClone = NULL;
195 RandomNumberDistribution_Parameters *params = getParameterSet();
196 MyClone = new RandomNumberDistribution_Encapsulation<distribution>(*params);
197 delete params;
198 return MyClone;
199 }
200
201 /** Clones and manipulates the current instance.
202 *
203 * Implementation of ManipulableClone pattern.
204 *
205 * @param _params set of parameters to instantiate manipulated clone with
206 * @return interface reference to cloned&manipulated instance
207 */
208 ManipulableClone<RandomNumberDistribution, RandomNumberDistribution_Parameters>*
209 manipulatedclone(const RandomNumberDistribution_Parameters&_params) const
210 {
211 RandomNumberDistribution_Encapsulation<distribution>* newproto =
212 new RandomNumberDistribution_Encapsulation<distribution>(_params);
213 return newproto;
214 }
215
216protected:
217 /** Constructor that instantiates a specific random number generator and
218 * distribution.
219 * @param _distribution_type instance of the desired distribution
220 */
221 RandomNumberDistribution_Encapsulation()
222 {}
223
224 /** Constructor that instantiates a specific random number generator and
225 * distribution.
226 *
227 * @param _params set of parameters to instantiate manipulated clone with
228 * @param _distribution_type instance of the desired distribution
229 */
230 RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params)
231 {}
232
233 /** Destructor of the class.
234 *
235 */
236 virtual ~RandomNumberDistribution_Encapsulation() {}
237private:
238 distribution distribution_type;
239};
240
241// the following definitions prevents the compiler from instantiating the above
242// template member functions for the desired cases.
243
244/* ========= manipulatedclone() ================ */
245
246template <>
247RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::
248RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
249
250template <>
251RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::
252RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
253
254template <>
255RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::
256RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
257
258template <>
259RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::
260RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
261
262template <>
263RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::
264RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
265
266template <>
267RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::
268RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
269
270template <>
271RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::
272RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
273
274template <>
275RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::
276RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
277
278template <>
279RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::
280RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
281
282template <>
283RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::
284RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
285
286template <>
287RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::
288RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
289
290template <>
291RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::
292RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
293
294template <>
295RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::
296RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
297
298/* =============== min() ======================= */
299
300template <>
301double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::min() const;
302template <>
303double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::min() const;
304template <>
305double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::min() const;
306template <>
307double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::min() const;
308
309
310/* =============== max() ======================= */
311
312template <>
313double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::max() const;
314template <>
315double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::max() const;
316template <>
317double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::max() const;
318template <>
319double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::max() const;
320
321
322/* =============== p() ======================= */
323
324template <>
325double RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::p() const;
326template <>
327double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::p() const;
328template <>
329double RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::p() const;
330
331
332/* =============== t() ======================= */
333
334template <>
335double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::t() const;
336
337
338/* =============== median() ======================= */
339
340template <>
341double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::median() const;
342
343
344/* =============== sigma() ======================= */
345
346template <>
347double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::sigma() const;
348template <>
349double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::sigma() const;
350template <>
351double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::sigma() const;
352
353
354/* =============== alpha() ======================= */
355
356template <>
357double RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::alpha() const;
358
359
360/* =============== mean() ======================= */
361
362template <>
363double RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::mean() const;
364template <>
365double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::mean() const;
366template <>
367double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::mean() const;
368
369
370/* =============== a() ======================= */
371
372template <>
373double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::a() const;
374
375
376/* =============== b() ======================= */
377
378template <>
379double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::b() const;
380
381
382/* =============== c() ======================= */
383
384template <>
385double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::c() const;
386
387
388/* =============== lambda() ======================= */
389
390template <>
391double RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::lambda() const;
392
393
394
395#endif /* RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.