probability

Sampling from a discrete probability distribution in C++

自古美人都是妖i 提交于 2019-11-30 17:40:09
问题 I am new to C++ and extremely surprised by the lack of accessible, common probability manipulation tools (i.e. the lack of things in Boost and the standard library). I've done a lot of scientific programming in other languages, but the standard and/or ubiquitious third party add-ons always include a full range of probability tools. A friend billed up Boost to be the equivalent ubiquitous add-on for C++, but as I read the Boost documentation, even it seems to have a dearth of what I would

Different probability for ranges of random numbers

微笑、不失礼 提交于 2019-11-30 15:25:54
I'm looking for the best way of implementing random number generator, that will allow me to have control over probability from what range the generated number will be returned. To visualize what I'm trying to achieve I have a picture : So to summarize : Let's say that my range is 400. At the beginning I'd like to have 5% probability of getting number 0-20. But at some moment in time I'd like to have this probability increased up to 50%. Hope you get the idea. Hmm, working on your original I had a pretty simple algorithm to generate ranges in an array in the appropriate proportion, then

Effective Java Item 47: Know and use your libraries - Flawed random integer method example

半城伤御伤魂 提交于 2019-11-30 13:14:47
问题 In the example Josh gives of the flawed random method that generates a positive random number with a given upper bound n , I don't understand the two of the flaws he states. The method from the book is: private static final Random rnd = new Random(); //Common but deeply flawed static int random(int n) { return Math.abs(rnd.nextInt()) % n; } He says that if n is a small power of 2, the sequence of random numbers that are generated will repeat itself after a short period of time. Why is this

How do I simulate biased die in python?

陌路散爱 提交于 2019-11-30 13:09:20
I want to simulate N-sided biased die? def roll(N,bias): '''this function rolls N dimensional die with biasing provided''' # do something return result >> N=6 >> bias=( 0.20,0.20,0.15,0.15,0.14,0.16,) >> roll(N,bias) 2 Yuval Adam A little bit of math here. A regular die will give each number 1-6 with equal probability, namely 1/6 . This is referred to as uniform distribution (the discrete version of it, as opposed to the continuous version). Meaning that if X is a random variable describing the result of a single role then X~U[1,6] - meaning X is distributed equally against all possible

Generate random numbers with fix probability

余生颓废 提交于 2019-11-30 10:20:37
I red a lot in the forum about this, but all answers were so specific to the the asked question. The nearest one I found to my need was: Probability Random Number Generator by Alon Gubkin . The difference is that, Alon ask to give a one face (which is six) extra chance. In my case, I want to divide the chance for the six faces so that they add up to 100%. For example, face 1 has chance of 40%, face 2 has only 10%, face 3 has 25%, ... etc. How can I do that? The single probability check with linear probability can be easily done with: function checkWithProbability($probability=0.1, $length

Generating random integers within range with a probability distribution

て烟熏妆下的殇ゞ 提交于 2019-11-30 09:44:19
I have a problem where I want to generate a set of random integer values between 1 and 5 inclusive using a probability distribution. Poisson and Inverse Gamma are two distributions that show the characteristics I am after (majority at mean, less higher numbers) that I have found. I am looking at using Apache Commons Math but I wasn't sure how to generate the numbers I wanted using the distributions available. From your problem description, it sounds like you actually want a sample generated from a discrete probability distribution, and you can use EnumeratedIntegerDistribution for this purpose

Probability of finding the median with finite space

妖精的绣舞 提交于 2019-11-30 09:09:00
This is a spin off of this StackOverflow question . Assume that you have a fixed number k of storage locations, and space for two counters. You will receive n items in random order (all permutations of the n items are equally likely). After receiving each item you can either store it in one of the k locations (discarding one of the previously stored values), or discard the item. You can also increment or decrement either of the counters. Any discarded item cannot be retrieved. The questions are What is the strategy that maximizes your probability of finding the exact median? What is that

How to simulate bimodal distribution?

你说的曾经没有我的故事 提交于 2019-11-30 08:54:17
问题 I have the following code to generate bimodal distribution but when I graph the histogram. I don't see the 2 modes. I am wondering if there's something wrong with my code. mu1 <- log(1) mu2 <- log(10) sig1 <- log(3) sig2 <- log(3) cpct <- 0.4 bimodalDistFunc <- function (n,cpct, mu1, mu2, sig1, sig2) { y0 <- rlnorm(n,mean=mu1, sd = sig1) y1 <- rlnorm(n,mean=mu2, sd = sig2) flag <- rbinom(n,size=1,prob=cpct) y <- y0*(1 - flag) + y1*flag } bimodalData <- bimodalDistFunc(n=100,cpct,mu1,mu2, sig1

Python: Matplotlib - probability plot for several data set

不打扰是莪最后的温柔 提交于 2019-11-30 07:37:49
I have several data sets (distribution) as follows: set1 = [1,2,3,4,5] set2 = [3,4,5,6,7] set3 = [1,3,4,5,8] How do I plot a scatter plot with the data sets above with the y-axis being the probability (i.e. the percentile of the distribution in set: 0%-100% ) and the x-axis being the data set names? in JMP, it is called 'Quantile Plot'. Something like image attached: Please educate. Thanks. [EDIT] My data is in csv as such: Using JMP analysis tool, I'm able to plot the probability distribution plot (QQ-plot/Normal Quantile Plot as figure far below): I believe Joe Kington almost has my problem

Is Pythons random.randint statistically random?

青春壹個敷衍的年華 提交于 2019-11-30 07:35:23
问题 So I'm testing an calculating the probabilities of certain dice rolls, for a game. The base case if that rolling one 10sided die. I did a million samples of this, and ended up with the following proportions: Result 0 0.000000000000000% 1 10.038789961210000% 2 10.043589956410000% 3 9.994890005110000% 4 10.025289974710000% 5 9.948090051909950% 6 9.965590034409970% 7 9.990190009809990% 8 9.985490014509990% 9 9.980390019609980% 10 10.027589972410000% These should of course all be 10%. There is a