/** * @file Core.h * @author bab2min (bab2min@gmail.com) * @brief * @version 0.2.0 * @date 2020-06-22 * * @copyright Copyright (c) 2020 * */ #ifndef EIGENRAND_CORE_H #define EIGENRAND_CORE_H #include #include #include #include #include namespace Eigen { /** * @brief namespace for EigenRand * */ namespace Rand { template using RandBitsType = CwiseNullaryOp, const Derived>; /** * @brief generates integers with random bits * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const RandBitsType randBits(Index rows, Index cols, Urng&& urng) { return { rows, cols, internal::scalar_randbits_op(std::forward(urng)) }; } /** * @brief generates integers with random bits * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @return a random matrix expression of the same shape as `o` */ template inline const RandBitsType randBitsLike(Derived& o, Urng&& urng) { return { o.rows(), o.cols(), internal::scalar_randbits_op(std::forward(urng)) }; } template using UniformIntType = CwiseNullaryOp, const Derived>; /** * @brief generates integers with a given range `[min, max]` * * @tparam Derived a type of Eigen::DenseBase * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param min, max the range of integers being generated * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const UniformIntType uniformInt(Index rows, Index cols, Urng&& urng, typename Derived::Scalar min, typename Derived::Scalar max) { return { rows, cols, internal::scalar_uniform_int_op(std::forward(urng), min, max) }; } /** * @brief generates integers with a given range `[min, max]` * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param min, max the range of integers being generated * @return a random matrix expression of the same shape as `o` */ template inline const UniformIntType uniformIntLike(Derived& o, Urng&& urng, typename Derived::Scalar min, typename Derived::Scalar max) { return { o.rows(), o.cols(), internal::scalar_uniform_int_op(std::forward(urng), min, max) }; } template using BalancedType = CwiseNullaryOp, const Derived>; /** * @brief generates reals in a range `[-1, 1]` * * @tparam Derived a type of Eigen::DenseBase * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const BalancedType balanced(Index rows, Index cols, Urng&& urng) { return { rows, cols, internal::scalar_balanced_op(std::forward(urng)) }; } /** * @brief generates reals in a range `[-1, 1]` * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @return a random matrix expression of the same shape as `o` */ template inline const BalancedType balancedLike(const Derived& o, Urng&& urng) { return { o.rows(), o.cols(), internal::scalar_balanced_op(std::forward(urng)) }; } template using UniformRealType = CwiseNullaryOp, const Derived>; /** * @brief generates reals in a range `[0, 1)` * * @tparam Derived a type of Eigen::DenseBase * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const UniformRealType uniformReal(Index rows, Index cols, Urng&& urng) { return { rows, cols, internal::scalar_uniform_real_op(std::forward(urng)) }; } /** * @brief generates reals in a range `[0, 1)` * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @return a random matrix expression of the same shape as `o` */ template inline const UniformRealType uniformRealLike(Derived& o, Urng&& urng) { return { o.rows(), o.cols(), internal::scalar_uniform_real_op(std::forward(urng)) }; } template using NormalType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on a standard normal distribution (`mean` = 0, `stdev`=1) * * @tparam Derived a type of Eigen::DenseBase * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const NormalType normal(Index rows, Index cols, Urng&& urng) { return { rows, cols, internal::scalar_norm_dist_op(std::forward(urng)) }; } /** * @brief generates reals on a standard normal distribution (`mean` = 0, `stdev`=1) * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @return a random matrix expression of the same shape as `o` */ template inline const NormalType normalLike(Derived& o, Urng&& urng) { return { o.rows(), o.cols(), internal::scalar_norm_dist_op(std::forward(urng)) }; } template using Normal2Type = CwiseNullaryOp, const Derived>; /** * @brief generates reals on a normal distribution with arbitrary `mean` and `stdev`. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param mean a mean value of the distribution * @param stdev a standard deviation value of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const Normal2Type normal(Index rows, Index cols, Urng&& urng, typename Derived::Scalar mean, typename Derived::Scalar stdev = 1) { return { rows, cols, internal::scalar_norm_dist2_op(std::forward(urng), mean, stdev) }; } /** * @brief generates reals on a normal distribution with arbitrary `mean` and `stdev`. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param mean a mean value of the distribution * @param stdev a standard deviation value of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const Normal2Type normalLike(Derived& o, Urng&& urng, typename Derived::Scalar mean, typename Derived::Scalar stdev = 1) { return { o.rows(), o.cols(), internal::scalar_norm_dist2_op(std::forward(urng), mean, stdev) }; } template using LognormalType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on a lognormal distribution with arbitrary `mean` and `stdev`. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param mean a mean value of the distribution * @param stdev a standard deviation value of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const LognormalType lognormal(Index rows, Index cols, Urng&& urng, typename Derived::Scalar mean = 0, typename Derived::Scalar stdev = 1) { return { rows, cols, internal::scalar_lognorm_dist_op(std::forward(urng), mean, stdev) }; } /** * @brief generates reals on a lognormal distribution with arbitrary `mean` and `stdev`. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param mean a mean value of the distribution * @param stdev a standard deviation value of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const LognormalType lognormalLike(Derived& o, Urng&& urng, typename Derived::Scalar mean = 0, typename Derived::Scalar stdev = 1) { return { o.rows(), o.cols(), internal::scalar_lognorm_dist_op(std::forward(urng), mean, stdev) }; } template using StudentTType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the Student's t distribution with arbirtrary degress of freedom. * * @tparam Derived a type of Eigen::DenseBase * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param n degrees of freedom * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const StudentTType studentT(Index rows, Index cols, Urng&& urng, typename Derived::Scalar n = 1) { return { rows, cols, internal::scalar_student_t_dist_op(std::forward(urng), n) }; } /** * @brief generates reals on the Student's t distribution with arbirtrary degress of freedom. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param n degrees of freedom * @return a random matrix expression of the same shape as `o` */ template inline const StudentTType studentTLike(Derived& o, Urng&& urng, typename Derived::Scalar n = 1) { return { o.rows(), o.cols(), internal::scalar_student_t_dist_op(std::forward(urng), n) }; } template using ExponentialType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on an exponential distribution with arbitrary scale parameter. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param lambda a scale parameter of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const ExponentialType exponential(Index rows, Index cols, Urng&& urng, typename Derived::Scalar lambda = 1) { return { rows, cols, internal::scalar_exp_dist_op(std::forward(urng), lambda) }; } /** * @brief generates reals on an exponential distribution with arbitrary scale parameter. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param lambda a scale parameter of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const ExponentialType exponentialLike(Derived& o, Urng&& urng, typename Derived::Scalar lambda = 1) { return { o.rows(), o.cols(), internal::scalar_exp_dist_op(std::forward(urng), lambda) }; } template using GammaType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on a gamma distribution with arbitrary shape and scale parameter. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param alpha a shape parameter of the distribution * @param beta a scale parameter of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const GammaType gamma(Index rows, Index cols, Urng&& urng, typename Derived::Scalar alpha = 1, typename Derived::Scalar beta = 1) { return { rows, cols, internal::scalar_gamma_dist_op(std::forward(urng), alpha, beta) }; } /** * @brief generates reals on a gamma distribution with arbitrary shape and scale parameter. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param alpha a shape parameter of the distribution * @param beta a scale parameter of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const GammaType gammaLike(Derived& o, Urng&& urng, typename Derived::Scalar alpha = 1, typename Derived::Scalar beta = 1) { return { o.rows(), o.cols(), internal::scalar_gamma_dist_op(std::forward(urng), alpha, beta) }; } template using WeibullType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on a Weibull distribution with arbitrary shape and scale parameter. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param a a shape parameter of the distribution * @param b a scale parameter of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const WeibullType weibull(Index rows, Index cols, Urng&& urng, typename Derived::Scalar a = 1, typename Derived::Scalar b = 1) { return { rows, cols, internal::scalar_weibull_dist_op(std::forward(urng), a, b) }; } /** * @brief generates reals on a Weibull distribution with arbitrary shape and scale parameter. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param a a shape parameter of the distribution * @param b a scale parameter of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const WeibullType weibullLike(Derived& o, Urng&& urng, typename Derived::Scalar a = 1, typename Derived::Scalar b = 1) { return { o.rows(), o.cols(), internal::scalar_weibull_dist_op(std::forward(urng), a, b) }; } template using ExtremeValueType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on an extreme value distribution * (a.k.a Gumbel Type I, log-Weibull, Fisher-Tippett Type I) with arbitrary shape and scale parameter. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param a a location parameter of the distribution * @param b a scale parameter of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const ExtremeValueType extremeValue(Index rows, Index cols, Urng&& urng, typename Derived::Scalar a = 0, typename Derived::Scalar b = 1) { return { rows, cols, internal::scalar_extreme_value_dist_op(std::forward(urng), a, b) }; } /** * @brief generates reals on an extreme value distribution * (a.k.a Gumbel Type I, log-Weibull, Fisher-Tippett Type I) with arbitrary shape and scale parameter. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param a a location parameter of the distribution * @param b a scale parameter of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const ExtremeValueType extremeValueLike(Derived& o, Urng&& urng, typename Derived::Scalar a = 0, typename Derived::Scalar b = 1) { return { o.rows(), o.cols(), internal::scalar_extreme_value_dist_op(std::forward(urng), a, b) }; } template using ChiSquaredType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the Chi-squared distribution with arbitrary degrees of freedom. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param n the degrees of freedom of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const ChiSquaredType chiSquared(Index rows, Index cols, Urng&& urng, typename Derived::Scalar n = 1) { return { rows, cols, internal::scalar_chi_squared_dist_op(std::forward(urng), n) }; } /** * @brief generates reals on the Chi-squared distribution with arbitrary degrees of freedom. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param n the degrees of freedom of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const ChiSquaredType chiSquaredLike(Derived& o, Urng&& urng, typename Derived::Scalar n = 1) { return { o.rows(), o.cols(), internal::scalar_chi_squared_dist_op(std::forward(urng), n) }; } template using CauchyType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the Cauchy distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param a a location parameter of the distribution * @param b a scale parameter of the distribution * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const CauchyType cauchy(Index rows, Index cols, Urng&& urng, typename Derived::Scalar a = 0, typename Derived::Scalar b = 1) { return { rows, cols, internal::scalar_cauchy_dist_op(std::forward(urng), a, b) }; } /** * @brief generates reals on the Cauchy distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param a a location parameter of the distribution * @param b a scale parameter of the distribution * @return a random matrix expression of the same shape as `o` */ template inline const CauchyType cauchyLike(Derived& o, Urng&& urng, typename Derived::Scalar a = 0, typename Derived::Scalar b = 1) { return { o.rows(), o.cols(), internal::scalar_cauchy_dist_op(std::forward(urng), a, b) }; } template using FisherFType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the Fisher's F distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param m degrees of freedom * @param n degrees of freedom * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const FisherFType fisherF(Index rows, Index cols, Urng&& urng, typename Derived::Scalar m = 1, typename Derived::Scalar n = 1) { return { rows, cols, internal::scalar_fisher_f_dist_op(std::forward(urng), m, n) }; } /** * @brief generates reals on the Fisher's F distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param m degrees of freedom * @param n degrees of freedom * @return a random matrix expression of the same shape as `o` */ template inline const FisherFType fisherFLike(Derived& o, Urng&& urng, typename Derived::Scalar m = 1, typename Derived::Scalar n = 1) { return { o.rows(), o.cols(), internal::scalar_fisher_f_dist_op(std::forward(urng), m, n) }; } template using BetaType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the beta distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param a,b shape parameter * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const BetaType beta(Index rows, Index cols, Urng&& urng, typename Derived::Scalar a = 1, typename Derived::Scalar b = 1) { return { rows, cols, internal::scalar_beta_dist_op(std::forward(urng), a, b) }; } /** * @brief generates reals on the beta distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param a,b shape parameter * @return a random matrix expression of the same shape as `o` */ template inline const BetaType betaLike(Derived& o, Urng&& urng, typename Derived::Scalar a = 1, typename Derived::Scalar b = 1) { return { o.rows(), o.cols(), internal::scalar_beta_dist_op(std::forward(urng), a, b) }; } template using DiscreteFType = CwiseNullaryOp, const Derived>; /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is float(23bit precision). * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param first, last the range of elements defining the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const DiscreteFType discreteF(Index rows, Index cols, Urng&& urng, RealIter first, RealIter last) { return { rows, cols, internal::scalar_discrete_dist_op(std::forward(urng), first, last) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is float(23bit precision). * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param first, last the range of elements defining the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression of the same shape as `o` */ template inline const DiscreteFType discreteFLike(Derived& o, Urng&& urng, RealIter first, RealIter last) { return { o.rows(), o.cols(), internal::scalar_discrete_dist_op(std::forward(urng), first, last) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is float(23bit precision). * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param il an instance of `initializer_list` containing the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const DiscreteFType discreteF(Index rows, Index cols, Urng&& urng, const std::initializer_list& il) { return { rows, cols, internal::scalar_discrete_dist_op(std::forward(urng), il.begin(), il.end()) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is float(23bit precision). * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param il an instance of `initializer_list` containing the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression of the same shape as `o` */ template inline const DiscreteFType discreteFLike(Derived& o, Urng&& urng, const std::initializer_list& il) { return { o.rows(), o.cols(), internal::scalar_discrete_dist_op(std::forward(urng), il.begin(), il.end()) }; } template using DiscreteDType = CwiseNullaryOp, const Derived>; /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is double(52bit precision). * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param first, last the range of elements defining the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const DiscreteDType discreteD(Index rows, Index cols, Urng&& urng, RealIter first, RealIter last) { return { rows, cols, internal::scalar_discrete_dist_op(std::forward(urng), first, last) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is double(52bit precision). * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param first, last the range of elements defining the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression of the same shape as `o` */ template inline const DiscreteDType discreteDLike(Derived& o, Urng&& urng, RealIter first, RealIter last) { return { o.rows(), o.cols(), internal::scalar_discrete_dist_op(std::forward(urng), first, last) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is double(52bit precision). * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param il an instance of `initializer_list` containing the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const DiscreteDType discreteD(Index rows, Index cols, Urng&& urng, const std::initializer_list& il) { return { rows, cols, internal::scalar_discrete_dist_op(std::forward(urng), il.begin(), il.end()) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is double(52bit precision). * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param il an instance of `initializer_list` containing the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression of the same shape as `o` */ template inline const DiscreteDType discreteDLike(Derived& o, Urng&& urng, const std::initializer_list& il) { return { o.rows(), o.cols(), internal::scalar_discrete_dist_op(std::forward(urng), il.begin(), il.end()) }; } template using DiscreteType = CwiseNullaryOp, const Derived>; /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is int32(32bit precision). * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param first, last the range of elements defining the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const DiscreteType discrete(Index rows, Index cols, Urng&& urng, RealIter first, RealIter last) { return { rows, cols, internal::scalar_discrete_dist_op(std::forward(urng), first, last) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is int32(32bit precision). * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param first, last the range of elements defining the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression of the same shape as `o` */ template inline const DiscreteType discreteLike(Derived& o, Urng&& urng, RealIter first, RealIter last) { return { o.rows(), o.cols(), internal::scalar_discrete_dist_op(std::forward(urng), first, last) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is int32(32bit precision). * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param il an instance of `initializer_list` containing the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const DiscreteType discrete(Index rows, Index cols, Urng&& urng, const std::initializer_list& il) { return { rows, cols, internal::scalar_discrete_dist_op(std::forward(urng), il.begin(), il.end()) }; } /** * @brief generates random integers on the interval `[0, n)`, where the probability of each individual integer `i` is proportional to `w(i)`. * The data type used for calculation of probabilities is int32(32bit precision). * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param il an instance of `initializer_list` containing the numbers to use as weights. The type of the elements referred by `RealIter` must be convertible to `double`. * @return a random matrix expression of the same shape as `o` */ template inline const DiscreteType discreteLike(Derived& o, Urng&& urng, const std::initializer_list& il) { return { o.rows(), o.cols(), internal::scalar_discrete_dist_op(std::forward(urng), il.begin(), il.end()) }; } template using PoissonType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the Poisson distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param mean rate parameter * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const PoissonType poisson(Index rows, Index cols, Urng&& urng, double mean = 1) { return { rows, cols, internal::scalar_poisson_dist_op(std::forward(urng), mean) }; } /** * @brief generates reals on the Poisson distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param mean rate parameter * @return a random matrix expression of the same shape as `o` */ template inline const PoissonType poissonLike(Derived& o, Urng&& urng, double mean = 1) { return { o.rows(), o.cols(), internal::scalar_poisson_dist_op(std::forward(urng), mean) }; } template using BinomialType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the binomial distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param trials the number of trials * @param p probability of a trial generating true * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const BinomialType binomial(Index rows, Index cols, Urng&& urng, typename Derived::Scalar trials = 1, double p = 0.5) { return { rows, cols, internal::scalar_binomial_dist_op(std::forward(urng), trials, p) }; } /** * @brief generates reals on the binomial distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param trials the number of trials * @param p probability of a trial generating true * @return a random matrix expression of the same shape as `o` */ template inline const BinomialType binomialLike(Derived& o, Urng&& urng, typename Derived::Scalar trials = 1, double p = 0.5) { return { o.rows(), o.cols(), internal::scalar_binomial_dist_op(std::forward(urng), trials, p) }; } template using NegativeBinomialType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the negative binomial distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param trials the number of trial successes * @param p probability of a trial generating true * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const NegativeBinomialType negativeBinomial(Index rows, Index cols, Urng&& urng, typename Derived::Scalar trials = 1, double p = 0.5) { return { rows, cols, internal::scalar_negative_binomial_dist_op(std::forward(urng), trials, p) }; } /** * @brief generates reals on the negative binomial distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param trials the number of trial successes * @param p probability of a trial generating true * @return a random matrix expression of the same shape as `o` */ template inline const NegativeBinomialType negativeBinomialLike(Derived& o, Urng&& urng, typename Derived::Scalar trials = 1, double p = 0.5) { return { o.rows(), o.cols(), internal::scalar_negative_binomial_dist_op(std::forward(urng), trials, p) }; } template using GeometricType = CwiseNullaryOp, const Derived>; /** * @brief generates reals on the geometric distribution. * * @tparam Derived * @tparam Urng * @param rows the number of rows being generated * @param cols the number of columns being generated * @param urng c++11-style random number generator * @param p probability of a trial generating true * @return a random matrix expression with a shape (`rows`, `cols`) */ template inline const GeometricType geometric(Index rows, Index cols, Urng&& urng, double p = 0.5) { return { rows, cols, internal::scalar_geometric_dist_op(std::forward(urng), p) }; } /** * @brief generates reals on the geometric distribution. * * @tparam Derived * @tparam Urng * @param o an instance of any type of Eigen::DenseBase * @param urng c++11-style random number generator * @param p probability of a trial generating true * @return a random matrix expression of the same shape as `o` */ template inline const GeometricType geometricLike(Derived& o, Urng&& urng, double p = 0.5) { return { o.rows(), o.cols(), internal::scalar_geometric_dist_op(std::forward(urng), p) }; } } } #endif