28#include "../kernel.hpp"
45static double getParameterValue(
const std::string& sCmd,
const std::string& sLongVersion,
const std::string& sShortVersion,
Parser& _parser,
double defaultVal)
52 nPos =
findParameter(sCmd, sLongVersion,
'=')+sLongVersion.length();
54 nPos =
findParameter(sCmd, sShortVersion,
'=')+sShortVersion.length();
57 return _parser.
Eval().real();
96 static double dSeedBase = 1.0;
97 std::string sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_GAUSS");
99 double dRandomNumber = 0.0;
100 std::default_random_engine randomGenerator(dSeedBase * time(0));
106 double dDistributionWidth = fabs(
getParameterValue(sCmd,
"width",
"w", _parser, 1.0));
125 if (sDistrib ==
"gauss" || sDistrib ==
"normal")
127 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_GAUSS");
130 else if (sDistrib ==
"poisson")
132 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_POISSON");
135 else if (sDistrib ==
"gamma")
137 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_GAMMA");
140 else if (sDistrib ==
"uniform")
142 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_UNIFORM");
145 else if (sDistrib ==
"binomial")
147 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_BINOMIAL");
150 else if (sDistrib ==
"student")
152 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_STUDENT");
157 sDistrib =
_lang.
get(
"RANDOM_DISTRIB_TYPE_GAUSS");
169 std::normal_distribution<double> normalDistribution(dDistributionMean, dDistributionWidth);
170 std::poisson_distribution<int> poissonDistribution(dDistributionMean);
171 std::gamma_distribution<double> gammaDistribution(dShape, dScale);
172 std::uniform_real_distribution<double> uniformDistribution(dDistributionMean-0.5*dDistributionWidth, dDistributionMean+0.5*dDistributionWidth);
173 std::binomial_distribution<int> binomialDistribution(nUpperBound, dProbability);
174 std::student_t_distribution<double> studentTDistribution(nFreedoms);
177 for (
long long int i = 0; i < nDataPoints; i++)
179 for (
long long int j = 0; j < nDataRows; j++)
181 switch (nDistribution)
184 dRandomNumber = normalDistribution(randomGenerator);
187 dRandomNumber = poissonDistribution(randomGenerator);
190 dRandomNumber = gammaDistribution(randomGenerator);
193 dRandomNumber = uniformDistribution(randomGenerator);
196 dRandomNumber = binomialDistribution(randomGenerator);
199 dRandomNumber = studentTDistribution(randomGenerator);
206 if ((!i && !j) || dSeedBase == 0.0)
208 if (dSeedBase == dRandomNumber)
211 dSeedBase = dRandomNumber;
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class represents the central memory managing instance. It will handle all tables and clusters,...
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
MemoryManager & getMemoryManager()
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
This class manages the setting values of the internal (kernel) settings of this application.
Common exception class for all exceptions thrown in NumeRe.
static size_t invalid_position
size_t size() const
This member function returns the size of the indices stored in this class.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
Mathematical expressions parser.
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
string evaluateTargetOptionInCommand(string &sCmd, const string &sDefaultTarget, Indices &_idx, Parser &_parser, MemoryManager &_data, const Settings &_option)
This function evaluates the "target=TABLE()" expression and creates the target table,...
void plugin_random(std::string &sCmd)
This function is the implementation of the random command.
RandomDistribution
This enumeration defines all available random distributions.
static double getParameterValue(const std::string &sCmd, const std::string &sLongVersion, const std::string &sShortVersion, Parser &_parser, double defaultVal)
This static function unifies the parameter detection of the random command implementation.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
This structure is central for managing the indices of a table or cluster read or write data access....
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
std::string toString(int)
Converts an integer to a string without the Settings bloat.