【发布时间】:2014-08-30 09:20:54
【问题描述】:
有没有一种方法可以让随机数生成满足用户确定的分布函数。在 MATLAB 中,我发现了仅具有均匀分布和正态分布函数的随机数生成器。
【问题讨论】:
-
你想如何指定这个“用户确定的分布函数”?也是离散的还是连续的?
-
丹,你最后的评论很有用
有没有一种方法可以让随机数生成满足用户确定的分布函数。在 MATLAB 中,我发现了仅具有均匀分布和正态分布函数的随机数生成器。
【问题讨论】:
Statistics Toolbox 具有大量具有预定义分布的随机数生成器。希望您需要的都包含在列表中:
Random Number Generators. betarnd - Beta random numbers. binornd - Binomial random numbers. chi2rnd - Chi square random numbers. evrnd - Extreme value random numbers. exprnd - Exponential random numbers. frnd - F random numbers. gamrnd - Gamma random numbers. geornd - Geometric random numbers. gevrnd - Generalized extreme value random numbers. gprnd - Generalized Pareto inverse random numbers. hygernd - Hypergeometric random numbers. iwishrnd - Inverse Wishart random matrix. johnsrnd - Random numbers from the Johnson system of distributions. lognrnd - Lognormal random numbers. mhsample - Metropolis-Hastings algorithm. mnrnd - Multinomial random vectors. mvnrnd - Multivariate normal random vectors. mvtrnd - Multivariate t random vectors. nbinrnd - Negative binomial random numbers. ncfrnd - Noncentral F random numbers. nctrnd - Noncentral t random numbers. ncx2rnd - Noncentral Chi-square random numbers. normrnd - Normal (Gaussian) random numbers. pearsrnd - Random numbers from the Pearson system of distributions. poissrnd - Poisson random numbers. randg - Gamma random numbers (unit scale). random - Random numbers from specified distribution. randsample - Random sample from finite population. raylrnd - Rayleigh random numbers. slicesample - Slice sampling method. trnd - T random numbers. unidrnd - Discrete uniform random numbers. unifrnd - Uniform random numbers. wblrnd - Weibull random numbers. wishrnd - Wishart random matrix.
您也可以使用random,它基本上根据分发的名称调用上述函数之一:
RANDOM Generate random arrays from a specified distribution. R = RANDOM(NAME,A) returns an array of random numbers chosen from the one-parameter probability distribution specified by NAME with parameter values A. [...] NAME can be: 'beta' or 'Beta', 'bino' or 'Binomial', 'chi2' or 'Chisquare', 'exp' or 'Exponential', 'ev' or 'Extreme Value', 'f' or 'F', 'gam' or 'Gamma', 'gev' or 'Generalized Extreme Value', 'gp' or 'Generalized Pareto', 'geo' or 'Geometric', 'hyge' or 'Hypergeometric', 'logn' or 'Lognormal', 'nbin' or 'Negative Binomial', 'ncf' or 'Noncentral F', 'nct' or 'Noncentral t', 'ncx2' or 'Noncentral Chi-square', 'norm' or 'Normal', 'poiss' or 'Poisson', 'rayl' or 'Rayleigh', 't' or 'T', 'unif' or 'Uniform', 'unid' or 'Discrete Uniform', 'wbl' or 'Weibull'.
【讨论】:
您始终可以将randsample 与加权采样一起使用。假设您想以概率p 对1:n 范围内的k 数字进行采样(其中p 是长度为n 的非负向量)然后
randsample( n, k, true, p );
【讨论】: