Changeset 081e5d for src/RandomNumbers


Ignore:
Timestamp:
Feb 3, 2011, 9:51:19 AM (14 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
6ff0c8
Parents:
15911c
git-author:
Frederik Heber <heber@…> (01/05/11 17:30:01)
git-committer:
Frederik Heber <heber@…> (02/03/11 09:51:19)
Message:

Implemented all possible parameter functions for engine and distribution in interface.

  • template member function has an ASSERT.
  • and then for each actually present parameter function of a specific engine or distribution there is a function specialization that passes on the request.
  • minimal use is made in the engine and distribution factory unit tests and everything is fine so far.
Location:
src/RandomNumbers
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • src/RandomNumbers/RandomNumberDistribution.hpp

    r15911c r081e5d  
    3737
    3838public:
     39  /** Getter for smallest value the engine produces.
     40   *
     41   * @return smallest value
     42   */
     43  virtual double min() const=0;
     44
     45  /** Getter for largest value the engine produces.
     46   *
     47   * @return largest value
     48   */
     49  virtual double max() const=0;
     50
     51
     52  /** Getter for bernoulli_distribution probability p.
     53   *
     54   * @return p
     55   */
     56  virtual double p() const=0;
     57
    3958  /** Getter for the type name of the internal distribution.
    4059   *
  • src/RandomNumbers/RandomNumberDistributionFactory.def

    r15911c r081e5d  
    77#define type_seq \
    88(uniform_smallint)\
    9 (uniform_int)
    10 
    11 /*
     9(uniform_int)\
    1210(uniform_01)\
    1311(uniform_real)\
     
    2119(exponential_distribution)\
    2220(normal_distribution)\
    23 (lognormal_distribution)\
     21(lognormal_distribution)
     22/*
    2423(uniform_on_sphere)
    2524*/
    26 
    2725#define FactoryNAME RandomNumberDistributionFactory
    2826#define Abstract_Interface_Class RandomNumberDistribution
  • src/RandomNumbers/RandomNumberDistribution_Encapsulation.hpp

    r15911c r081e5d  
    1313#include <config.h>
    1414#endif
     15
     16#include "CodePatterns/Assert.hpp"
    1517
    1618#include <typeinfo>
     
    6062public:
    6163
     64  /** Getter for smallest value the engine produces.
     65   *
     66   * @return smallest value
     67   */
     68  double min() const {
     69    ASSERT(0, "min() not implemented for "+name());
     70    return -1.;
     71  }
     72
     73  /** Getter for largest value the engine produces.
     74   *
     75   * @return largest value
     76   */
     77  double max() const {
     78    ASSERT(0, "max() not implemented for "+name());
     79    return -1.;
     80  }
     81
     82  /** Getter for bernoulli_distribution's probability p.
     83   *
     84   * @return p
     85   */
     86  double p() const {
     87    ASSERT(0, "p() not implemented for "+name());
     88    return -1.;
     89  }
     90
     91  /** Getter for binomial_distribution's parameter t.
     92   *
     93   * @return t
     94   */
     95  double t() const {
     96    ASSERT(0, "t() not implemented for "+name());
     97    return -1.;
     98  }
     99
     100  /** Getter for cauchy_distribution parameter median.
     101   *
     102   * @return median
     103   */
     104  double median() const {
     105    ASSERT(0, "median() not implemented for "+name());
     106    return -1.;
     107  }
     108
     109  /** Getter for cauchy_distribution parameter sigma.
     110   *
     111   * @return sigma
     112   */
     113  double sigma() const {
     114    ASSERT(0, "sigma() not implemented for "+name());
     115    return -1.;
     116  }
     117
     118  /** Getter for gamma_distribution parameter alpha.
     119   *
     120   * @return alpha
     121   */
     122  double alpha() const {
     123    ASSERT(0, "alpha() not implemented for "+name());
     124    return -1.;
     125  }
     126
     127  /** Getter for poisson_distribution's parameter mean.
     128   *
     129   * @return mean
     130   */
     131  double mean() const {
     132    ASSERT(0, "mean() not implemented for "+name());
     133    return -1.;
     134  }
     135
     136  /** Getter for triangle_distribution parameter a.
     137   *
     138   * @return a
     139   */
     140  double a() const {
     141    ASSERT(0, "a() not implemented for "+name());
     142    return -1.;
     143  }
     144
     145  /** Getter for triangle_distribution parameter b.
     146   *
     147   * @return b
     148   */
     149  double b() const {
     150    ASSERT(0, "b() not implemented for "+name());
     151    return -1.;
     152  }
     153
     154  /** Getter for triangle_distribution parameter c.
     155   *
     156   * @return c
     157   */
     158  double c() const {
     159    ASSERT(0, "c() not implemented for "+name());
     160    return -1.;
     161  }
     162
     163  /** Getter for exponential_distribution parameter lambda.
     164   *
     165   * @return lambda
     166   */
     167  double lambda() const {
     168    ASSERT(0, "lambda() not implemented for "+name());
     169    return -1.;
     170  }
     171
    62172  /** Getter for the type name of the internal distribution.
    63173   *
     
    103213};
    104214
     215// the following definitions prevents the compiler from instantiating the above
     216// template member functions for the desired cases.
     217
     218/* ===============  min() ======================= */
     219
     220template <>
     221double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::min() const;
     222template <>
     223double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::min() const;
     224template <>
     225double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::min() const;
     226template <>
     227double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::min() const;
     228
     229
     230/* ===============  max() ======================= */
     231
     232template <>
     233double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::max() const;
     234template <>
     235double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::max() const;
     236template <>
     237double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::max() const;
     238template <>
     239double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::max() const;
     240
     241
     242/* ===============  p() ======================= */
     243
     244template <>
     245double RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::p() const;
     246template <>
     247double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::p() const;
     248template <>
     249double RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::p() const;
     250
     251
     252/* ===============  t() ======================= */
     253
     254template <>
     255double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::t() const;
     256
     257
     258/* ===============  median() ======================= */
     259
     260template <>
     261double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::median() const;
     262
     263
     264/* ===============  sigma() ======================= */
     265
     266template <>
     267double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::sigma() const;
     268template <>
     269double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::sigma() const;
     270template <>
     271double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::sigma() const;
     272
     273
     274/* ===============  alpha() ======================= */
     275
     276template <>
     277double RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::alpha() const;
     278
     279
     280/* ===============  mean() ======================= */
     281
     282template <>
     283double RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::mean() const;
     284template <>
     285double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::mean() const;
     286template <>
     287double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::mean() const;
     288
     289
     290/* ===============  a() ======================= */
     291
     292template <>
     293double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::a() const;
     294
     295
     296/* ===============  b() ======================= */
     297
     298template <>
     299double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::b() const;
     300
     301
     302/* ===============  c() ======================= */
     303
     304template <>
     305double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::c() const;
     306
     307
     308/* ===============  lambda() ======================= */
     309
     310template <>
     311double RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::lambda() const;
     312
     313
     314
    105315#endif /* RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ */
  • src/RandomNumbers/RandomNumberEngine.hpp

    r15911c r081e5d  
    4343  virtual void seed(unsigned int _seed)=0;
    4444
     45  /** Getter for smallest value the engine produces.
     46   *
     47   * @return smallest value
     48   */
     49  virtual double min() const=0;
     50
     51  /** Getter for largest value the engine produces.
     52   *
     53   * @return largest value
     54   */
     55  virtual double max() const=0;
     56
    4557  /** Getter for the type name of the internal engine.
    4658   *
  • src/RandomNumbers/RandomNumberEngineFactory.def

    r15911c r081e5d  
    66 */
    77#define engine_seq \
    8 (minstd_rand0)
    9 
    10 /*
     8(minstd_rand0)\
    119(minstd_rand)\
    1210(rand48)\
     
    1715(mt11213b)\
    1816(mt19937)
    19 */
     17
    2018#define engine_seq_a \
    21 (lagged_fibonacci607)
    22 
    23 /*
     19(lagged_fibonacci607)\
    2420(lagged_fibonacci1279)\
    2521(lagged_fibonacci2281)\
     
    3834(ranlux64_3_01)\
    3935(ranlux64_4_01)
    40 */
    4136
    4237#define type_seq engine_seq engine_seq_a
  • src/RandomNumbers/RandomNumberEngine_Encapsulation.hpp

    r15911c r081e5d  
    7272  }
    7373
     74  /** Getter for smallest value the engine produces.
     75   *
     76   * @return smallest value
     77   */
     78  double min() const {
     79    return engine_type.min();
     80  }
     81
     82  /** Getter for largest value the engine produces.
     83   *
     84   * @return largest value
     85   */
     86  double max() const {
     87    return engine_type.max();
     88  }
     89
    7490  /** Getter for the type name of the internal engine.
    7591   *
  • src/RandomNumbers/RandomNumberGeneratorFactory.def

    r15911c r081e5d  
    77#define distribution_seq \
    88(uniform_smallint)\
    9 (uniform_int)
    10 
    11 /*
     9(uniform_int)\
    1210(uniform_01)\
    1311(uniform_real)\
     
    2119(exponential_distribution)\
    2220(normal_distribution)\
    23 (lognormal_distribution)\
     21(lognormal_distribution)
     22/*
    2423(uniform_on_sphere)
    2524*/
    26 
    2725/** BOOST_PP_SEQ of all random::boost engine types,
    2826 * see see http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/reference.html#boost_random.reference.concepts
    2927 */
    3028#define engine_seq \
    31 (minstd_rand0)
    32 
    33 /*
     29(minstd_rand0)\
    3430(minstd_rand)\
    3531(rand48)\
     
    4036(mt11213b)\
    4137(mt19937)
    42 */
     38
    4339#define engine_seq_a \
    44 (lagged_fibonacci607)
    45 
    46 /*
     40(lagged_fibonacci607)\
    4741(lagged_fibonacci1279)\
    4842(lagged_fibonacci2281)\
     
    6155(ranlux64_3_01)\
    6256(ranlux64_4_01)
    63 */
    6457
    6558#endif /* RANDOMNUMBERGENERATORFACTORY_DEF_ */
  • src/RandomNumbers/unittests/Makefile.am

    r15911c r081e5d  
    3737        RandomNumberDistributionFactoryUnitTest.cpp \
    3838        RandomNumberDistributionFactoryUnitTest.hpp \
     39        $(srcdir)/../RandomNumberDistribution_Encapsulation.cpp \
     40        $(srcdir)/../RandomNumberDistribution_Encapsulation.hpp \
    3941        $(srcdir)/../RandomNumberDistributionFactory.cpp \
    4042        $(srcdir)/../RandomNumberDistributionFactory.hpp
     
    4446        RandomNumberEngineFactoryUnitTest.cpp \
    4547        RandomNumberEngineFactoryUnitTest.hpp \
     48        $(srcdir)/../RandomNumberEngine_Encapsulation.cpp \
     49        $(srcdir)/../RandomNumberEngine_Encapsulation.hpp \
    4650        $(srcdir)/../RandomNumberEngineFactory.cpp \
    4751        $(srcdir)/../RandomNumberEngineFactory.hpp
     
    5155        RandomNumberGeneratorFactoryUnitTest.cpp \
    5256        RandomNumberGeneratorFactoryUnitTest.hpp \
     57        $(srcdir)/../RandomNumberDistribution_Encapsulation.cpp \
     58        $(srcdir)/../RandomNumberDistribution_Encapsulation.hpp \
    5359        $(srcdir)/../RandomNumberDistributionFactory.cpp \
    5460        $(srcdir)/../RandomNumberDistributionFactory.hpp \
     61        $(srcdir)/../RandomNumberEngine_Encapsulation.cpp \
     62        $(srcdir)/../RandomNumberEngine_Encapsulation.hpp \
    5563        $(srcdir)/../RandomNumberEngineFactory.cpp \
    5664        $(srcdir)/../RandomNumberEngineFactory.hpp \
     
    6371        RandomNumberGeneratorUnitTest.cpp \
    6472        RandomNumberGeneratorUnitTest.hpp \
     73        $(srcdir)/../RandomNumberDistribution_Encapsulation.cpp \
     74        $(srcdir)/../RandomNumberDistribution_Encapsulation.hpp \
    6575        $(srcdir)/../RandomNumberDistributionFactory.cpp \
    6676        $(srcdir)/../RandomNumberDistributionFactory.hpp \
     77        $(srcdir)/../RandomNumberEngine_Encapsulation.cpp \
     78        $(srcdir)/../RandomNumberEngine_Encapsulation.hpp \
    6779        $(srcdir)/../RandomNumberEngineFactory.cpp \
    6880        $(srcdir)/../RandomNumberEngineFactory.hpp \
  • src/RandomNumbers/unittests/RandomNumberDistributionFactoryUnitTest.cpp

    r15911c r081e5d  
    108108      rndA->name()
    109109  );
     110
     111  // check min and max of uniform_smallint
     112  CPPUNIT_ASSERT_EQUAL( 0., rndA->min() );
     113  CPPUNIT_ASSERT_EQUAL( 9., rndA->max() );
    110114}
    111115
  • src/RandomNumbers/unittests/RandomNumberEngineFactoryUnitTest.cpp

    r15911c r081e5d  
    112112      rndA->name()
    113113  );
     114
     115  // range of minstd_rand0 with c=0 is [1,m)
     116  CPPUNIT_ASSERT_EQUAL( 1., rndA->min() );
    114117}
    115118
Note: See TracChangeset for help on using the changeset viewer.