probability

Probability in Java

时光总嘲笑我的痴心妄想 提交于 2019-12-17 17:39:38
问题 I was curious to know, how do I implement probability in Java? For example, if the chances of a variable showing is 1/25, then how would I implement that? Or any other probability? Please point me in the general direction. 回答1: You'd use Random to generate a random number, then test it against a literal to match the probability you're trying to achieve. So given: boolean val = new Random().nextInt(25)==0; val will have a 1/25 probability of being true (since nextInt() has an even probability

How do I calculate the probability for a given quantile in R?

五迷三道 提交于 2019-12-17 15:44:53
问题 Using R, it is trivial to calculate the quantiles for given probabilities in a sampled distribution: x <- rnorm(1000, mean=4, sd=2) quantile(x, .9) # results in 6.705755 However, I can't find an easy way to do the inverse—calculate the probability for a given quantile in the sample x . The closest I've come is to use pnorm() with the same mean and standard deviation I used when creating the sample: pnorm(5, mean=4, sd=2) # results in 0.6914625 However, because this is calculating the

Algorithm to generate Poisson and binomial random numbers?

*爱你&永不变心* 提交于 2019-12-17 08:53:22
问题 i've been looking around, but i'm not sure how to do it. i've found this page which, in the last paragraph, says: A simple generator for random numbers taken from a Poisson distribution is obtained using this simple recipe: if x 1 , x 2 , ... is a sequence of random numbers with uniform distribution between zero and one, k is the first integer for which the product x 1 · x 2 · ... · x k+1 < e -λ i've found another page describing how to generate binomial numbers, but i think it is using an

Nth Combination

喜夏-厌秋 提交于 2019-12-17 04:00:53
问题 Is there a direct way of getting the Nth combination of an ordered set of all combinations of nCr? Example: I have four elements: [6, 4, 2, 1]. All the possible combinations by taking three at a time would be: [[6, 4, 2], [6, 4, 1], [6, 2, 1], [4, 2, 1]]. Is there an algorithm that would give me e.g. the 3rd answer, [6, 2, 1], in the ordered result set, without enumerating all the previous answers? 回答1: Note you can generate the sequence by recursively generating all combinations with the

Choosing n numbers with fixed sum

て烟熏妆下的殇ゞ 提交于 2019-12-17 02:49:29
问题 In some code I want to choose n random numbers in [0,1) which sum to 1 . I do so by choosing the numbers independently in [0,1) and normalizing them by dividing each one by the total sum: numbers = [random() for i in range(n)] numbers = [n/sum(numbers) for n in numbers] My "problem" is, that the distribution I get out is quite skew. Choosing a million numbers not a single one gets over 1/2 . By some effort I've calculated the pdf, and it's not nice. Here is the weird looking pdf I get for 5

How to predict probability in logistic regression in SAS?

泪湿孤枕 提交于 2019-12-14 03:15:40
问题 I am very new to SAS and trying to predict probabilities using logistic regression in SAS. I got the code below from SAS Support web site: data vaso; length Response $12; input Volume Rate Response @@; LogVolume=log(Volume); LogRate=log(Rate); datalines; 3.70 0.825 constrict 3.50 1.09 constrict 1.25 2.50 constrict 0.75 1.50 constrict 0.80 3.20 constrict 0.70 3.50 constrict 0.60 0.75 no_constrict 1.10 1.70 no_constrict 0.90 0.75 no_constrict 0.90 0.45 no_constrict 0.80 0.57 no_constrict 0.55 2

Does rand() ever return zero on OSX?

佐手、 提交于 2019-12-14 01:42:40
问题 I have been running this code for almost ten hours with no love: while ( true ) { int r = rand(); assert( r != 0 ); } I expect rand() to eventually roll a zero and thus trigger the assert. Am I doing something wrong or does rand() never return zero? Or have I not been waiting long enough to expect to see it? I'm on 2012-vintage 2GHz i7. 回答1: If this link is the definition of Mac OS X rand() , then 0 will never be produced. It's not a very good pseudo random number generator, IMHO. Amongst its

How do you generate a random number with equal probability using Math.random() in Java [duplicate]

泪湿孤枕 提交于 2019-12-13 19:16:01
问题 This question already has answers here : How do I generate random integers within a specific range in Java? (65 answers) Closed 6 years ago . I'm currently working through an exercise where I am required to generate a random number which can be one of 4 values. (note I'm only allowed to use Math.random()) 0 1 2 or 3 Currently I am using this: randno = (int) (Math.random()*4); // range 0-3 However, the outcome MUST have equal probability. My tests so far (although the method is lacking) shows

multivariate normal distribution given mean vector and covariance matrix

浪尽此生 提交于 2019-12-13 18:12:17
问题 I admit I am being lazy here but is anyone aware of a free math .net library which gives me the output of a normal distribution given a mean vector and a covariance matrix? Thanks. 回答1: Math.NET might work for you. http://www.mathdotnet.com/ http://numerics.mathdotnet.com/probability-distributions/ Multivariate Distributions Dirichlet Inverse Wishart Matrix Normal Multinomial NormalGamma Wishart Function Reference: http://api.mathdotnet.com/Numerics/MathNet.Numerics.Distributions/MatrixNormal

How to find probability in R [closed]

有些话、适合烂在心里 提交于 2019-12-13 11:25:35
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . How could you use the prob argument in the sample command in R so that it covers conditional probability as well? For example, the letters of the alphabet: the probability of generating the letter 'b' depends on the previous letter generated. Thanks! 回答1: The question is still a bit difficult to