好的 - 以防萬一任何人對我的答案版本感興趣。使用下面的參考了我對我的約束威布爾結果集的目標:
https://stats.stackexchange.com/questions/30303/how-to-simulate-data-that-satisfy-specific-constraints-such-as-having-specific-m
以下鏈接也是得心應手:
http://en.wikipedia.org/wiki/Weibull_distribution
http://mathworld.wolfram.com/WeibullDistribution.html
到底我js代碼如下所示:
var desiredMin = 1; //the desired minimum random result
var desiredMax = 50; //the desired maximum random result
var scale = 1; //Weibul scale parameter (1 provides an inverse result set)
var shape = 10; //Weibul shape parameter (how skewed the result set is)
//given an possible random range of {0,1} value calculate the minimum and maximum Weibull distribution values given current shape and scale parameters
var weibullMin = Math.pow((shape*scale), (-1*shape)) * Math.pow(.000001, shape -1) * Math.exp(Math.pow((.000001/scale), shape));
var weibullMax = Math.pow((shape*scale), (-1*shape)) * Math.pow(.999999, shape -1) * Math.exp(Math.pow((.999999/scale), shape));
//simulate 1000 random weibull values and write results to file
fileStream.once('open', function(fd) {
for(var i = 1; i <= 1000; i++) {
var r = Math.random();
var weibullRandom = Math.pow((shape*scale), (-1*shape)) * Math.pow(r, shape-1) * Math.exp(Math.pow((r/scale), shape)); //generate Weibull random value
var weibullRandomAdjusted = desiredMin + (desiredMax - desiredMin)*((weibullRandom-weibullMin)/(weibullMax - weibullMin)); //adjust Weibull random value so that it constrained into the desired min/max range
fileStream.write(weibullRandomAdjusted + "\n");
};
fileStream.end();
});
我已經運行了不同的'形狀'值的代碼,它提供給我完全我需要的結果。
威布爾分佈定義從0到無窮大。你覺得你如何適應[1..100]? – alex
爲什麼不寫一些函數輸出一系列隨機值(如75-100),並使用另一個隨機數來選擇要使用的範圍。如果你最稀有的百分比是5%,那麼產生一個從1到20的數字; 1-16 =大,17 = <20,18 + 19 + 20 = 50-74等... – dandavis