probability

DistributionFitTest[] for custom distributions in Mathematica

删除回忆录丶 提交于 2019-12-09 16:22:13
问题 I have PDFs and CDFs for two custom distributions, a means of generating RandomVariates for each, and code for fitting parameters to data. Some of this code I've posted previously at: Calculating expectation for a custom distribution in Mathematica Some of it follows: nlDist /: PDF[nlDist[alpha_, beta_, mu_, sigma_], x_] := (1/(2*(alpha + beta)))*alpha* beta*(E^(alpha*(mu + (alpha*sigma^2)/2 - x))* Erfc[(mu + alpha*sigma^2 - x)/(Sqrt[2]*sigma)] + E^(beta*(-mu + (beta*sigma^2)/2 + x))* Erfc[(

Returning a random value from array with probability proportional to it's value

安稳与你 提交于 2019-12-09 11:00:43
问题 I have an array like $keywords = array('apple'=>10,'orange'=>2,'grape'=>12); I want to randomly pick one of the "Key" from the array. However the probability distribution should be such that probability of picking an element should be proportional to it's value. 回答1: Add all values (10+2+12 is 24); get a random number in the range [0, 24), and pick the corresponding element depending on whether the number lies in [0, 10), [10, 12), or [12, 24). 回答2: I'd do it like this: $probabilities = array

Shuffle elements of an array/n numbers uniformly randomly. Possibley in expected O(n) time

十年热恋 提交于 2019-12-09 01:04:18
问题 Is it possible to shuffle elements of an n-sized array uniformly, i.e. the probability of any of the n! combinations occurring is the same, in expected O(n) time. How so? I have to shuffle elements of A to a new array B The first thing that comes to my mind when I'm trying to do this is just picking a random number i from 1 to n, see if A[i] has already been picked, if so, then repeat, otherwise put A[i] in the first available position in B . However, this coupon collector problem has

R : function to generate a mixture distribution

心不动则不痛 提交于 2019-12-08 21:24:41
问题 I need to generate samples from a mixed distribution 40% samples come from Gaussian(mean=2,sd=8) 20% samples come from Cauchy(location=25,scale=2) 40% samples come from Gaussian(mean = 10, sd=6) To do this, i wrote the following function : dmix <- function(x){ prob <- (0.4 * dnorm(x,mean=2,sd=8)) + (0.2 * dcauchy(x,location=25,scale=2)) + (0.4 * dnorm(x,mean=10,sd=6)) return (prob) } And then tested with: foo = seq(-5,5,by = 0.01) vector = NULL for (i in 1:1000){ vector[i] <- dmix(foo[i]) }

Using one probability set to generate another [duplicate]

落花浮王杯 提交于 2019-12-08 19:36:44
This question already has answers here : Expand a random range from 1–5 to 1–7 (77 answers) Closed 5 years ago . How can I generate a bigger probability set from a smaller probability set? This is from Algorithm Design Manual -Steven Skiena Q: Use a random number generator (rng04) that generates numbers from {0,1,2,3,4} with equal probability to write a random number generator that generates numbers from 0 to 7 (rng07) with equal probability? I tried for around 3 hours now, mostly based on summing two rng04 outputs. The problem is that in that case the probability of each value is different -

Generate a list of random weighted tuples from a list

萝らか妹 提交于 2019-12-08 15:07:32
问题 Given a tuple list a : a =[(23, 11), (10, 16), (13, 11), (12, 3), (4, 15), (10, 16), (10, 16)] We can count how many appearances of each tuple we have using Counter : >>> from collections import Counter >>> b = Counter(a) >>> b Counter({(4, 15): 1, (10, 16): 3, (12, 3): 1, (13, 11): 1, (23, 11): 1} Now, the idea is to select 3 random tuples from the list, without repetition , such that the count determines the probability that a particular tuple is chosen. For instance, (10, 16) is more

Extract probabilities and most likely parse tree from cyk

回眸只為那壹抹淺笑 提交于 2019-12-08 13:50:37
问题 In order to understand cyk algorithm I've worked through example on : https://www.youtube.com/watch?v=VTH1k-xiswM&feature=youtu.be . The result of which is : How do I extract the probabilities associated with each parse and extract the most likely parse tree ? 回答1: These are two distinct problems for PCFG: recognition : does the sentence belong to the language generated by the CFG? (output: yes or no) parsing : what is the highest scoring tree for this sentence? (output: parse tree) The CKY

Exponential-decay-like-random-distribution and Discretization of continuous distributions

拥有回忆 提交于 2019-12-08 10:02:52
问题 sadly I'm not really experienced in using random numbers in programming, despite the use of uniform integers in range. Therefore i have to questions regarding this topic. Question 1 (more specific): I'm looking for a way to chose array elements (dynamic size, but known) according to a probability distribution similar to the curve of "exponential decay" (http://en.wikipedia.org/wiki/Exponential_decay). Meaning: i want to prefer to chose the first elements rather than the others. I want an

Using one probability set to generate another [duplicate]

断了今生、忘了曾经 提交于 2019-12-08 05:38:44
问题 This question already has answers here : Expand a random range from 1–5 to 1–7 (77 answers) Closed 5 years ago . How can I generate a bigger probability set from a smaller probability set? This is from Algorithm Design Manual -Steven Skiena Q: Use a random number generator (rng04) that generates numbers from {0,1,2,3,4} with equal probability to write a random number generator that generates numbers from 0 to 7 (rng07) with equal probability? I tried for around 3 hours now, mostly based on

Birthday Paradox: How to programmatically estimate the probability of 3, and N, people sharing a birthday

拜拜、爱过 提交于 2019-12-08 05:14:07
问题 There are extensive resources on the internet discussing the famous Birthday Paradox . It is clear to me how you calculate the probability of two people sharing a birthday i.e. P(same) = 1 - P(different) . However if I ask myself something apparently more simple I stall: firstly, let's say I generate two random birthdays. Getting the same birthday is like tossing a coin. Either the two persons share a birthday (Heads) or they don't share a birthday (Tail). Run this 500 times and the end