probability

possible distributions and their probabilities after putting identical items into anonymous buckets

蹲街弑〆低调 提交于 2019-12-05 18:47:17
Apologies if the answer to this is readily found elsewhere. My math and stats are weak and thus I don't even know the search terms for what I'm trying to do . . . I have b anonymous indistinguishable buckets into which I'm putting i identical items. I want to know all possible distributions and their probabilities. For example, if I have 3 buckets and 3 items, the answer I want is: [3,0,0] -> 1/9 [2,1,0] -> 6/9 [1,1,1] -> 2/9 Notice that the buckets are anonymous and thus I want identical distributions to be combined as I have done above. For example, the [2,1,0] case is actually the sum of

Expected worst-case time complexity of chained hash table lookups?

这一生的挚爱 提交于 2019-12-05 18:36:39
When implementing a hash table using a good hash function (one where the probability of any two elements colliding is 1 / m, where m is the number of buckets), it is well-known that the average-case running time for looking up an element is Θ(1 + α), where α is the load factor. The worst-case running time is O(n), though, if all the elements end up put into the same bucket. I was recently doing some reading on hash tables and found this article which claims (on page 3) that if α = 1, the expected worst-case complexity is Θ(log n / log log n). By "expected worst-case complexity," I mean, on

Why am I getting dups with random.shuffle in Python?

∥☆過路亽.° 提交于 2019-12-05 14:38:26
For a list of 10 ints, there are 10! possible orders or permutations. Why does random.shuffle give duplicates after only 5000 tries? >>> L = range(10) >>> rL = list() >>> for i in range(5000): ... random.shuffle(L) ... rL.append(L[:]) ... >>> rL = [tuple(e) for e in rL] >>> len(set(rL)) 4997 >>> for i,t in enumerate(rL): ... if rL.count(t) > 1: ... print i,t ... 102 (7, 5, 2, 4, 0, 6, 9, 3, 1, 8) 258 (1, 4, 0, 2, 7, 3, 5, 9, 6, 8) 892 (1, 4, 0, 2, 7, 3, 5, 9, 6, 8) 2878 (7, 5, 2, 4, 0, 6, 9, 3, 1, 8) 4123 (5, 8, 0, 1, 7, 3, 2, 4, 6, 9) 4633 (5, 8, 0, 1, 7, 3, 2, 4, 6, 9) >>> 10*9*8*7*6*5*4*3*2

Python: Selecting numbers with associated probabilities [duplicate]

荒凉一梦 提交于 2019-12-05 10:35:59
This question already has answers here : Closed 8 years ago . Possible Duplicates: Random weighted choice Generate random numbers with a given (numerical) distribution I have a list of list which contains a series on numbers and there associated probabilities. prob_list = [[1, 0.5], [2, 0.25], [3, 0.05], [4, 0.01], [5, 0.09], [6, 0.1]] for example in prob_list[0] the number 1 has a probability of 0.5 associated with it. So you would expect 1 to show up 50% of the time. How do I add weight to the numbers when I select them? NOTE: the amount of numbers in the list can vary from 6 - 100 EDIT In

R: monte carlo integration using Importance Sampling

有些话、适合烂在心里 提交于 2019-12-05 10:26:02
I have an integral to evaluate "x^(-0.5)" ; x in [0.01,1] for which I am using Importance Sampling MC : The theory says that an approximate PDF has to be used to compute the expected value (which will almost surely converge to the mean - value of the integral) After plotting the given integral, and exponential PDF, based only on the plots, I chose the rexp and dexp to generate the PDF - and my code looks like this - #Without Importance Sampling set.seed(1909) X <- runif(1000,0.01,1) Y <- X^(-0.5) c( mean(Y), var(Y) ) #Importance sampling Monte Carlo w <- function(x) dunif(x, 0.01, 1)/dexp(x

Probability density function from a paper, implemented using C++, not working as intended

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:19:04
So i'm implementing a heuristic algorithm, and i've come across this function. I have an array of 1 to n (0 to n-1 on C, w/e). I want to choose a number of elements i'll copy to another array. Given a parameter y, (0 < y <= 1), i want to have a distribution of numbers whose average is (y * n). That means that whenever i call this function, it gives me a number, between 0 and n, and the average of these numbers is y*n. According to the author, "l" is a random number: 0 < l < n . On my test code its currently generating 0 <= l <= n. And i had the right code, but i'm messing with this for hours

Dice odds: Simulating a game of Craps

大憨熊 提交于 2019-12-05 01:59:36
My brother turns 21 in a couple of weeks and my parents and I are taking him to Las Vegas. For my 21st, I brought $200 to gamble in Vegas and came home with around $450, mostly from playing craps. I plan on bringing $200 again for this trip and before I go I thought I'd run some craps simulations to see if I can double my money again. I've read from several sources that the house has the smallest advantage in craps when placing a passline bet with maximum odds. From my memory, and as surveyed by Wizard of Odds , most casinos on the Strip are 3-4-5 odds with a $5 minimum. Taking this into

How to run statistics Cumulative Distribution Function and Probability Density Function using SciPy?

给你一囗甜甜゛ 提交于 2019-12-05 01:19:12
问题 I am new to Python and new to SciPy libraries. I wanted to take some ques from the experts here on the list before dive into SciPy world. I was wondering if some one could provide a rough guide about how to run two stats functions: Cumulative Distribution Function (CDF) and Probability Distribution Function (PDF). My use case is the following: I have a sampleSpaceList [] which have 1000 floating point values. When a new floating point value is generated in my program, I would like to run both

Fisher Yates variation

大城市里の小女人 提交于 2019-12-05 00:49:41
The classic Fisher Yates looks something like this: void shuffle1(std::vector<int>& vec) { int n = vec.size(); for (int i = n - 1; i > 0; --i) { std::swap(vec[i], vec[rand() % (i + 1)]); } } Yesterday, I implemented the iteration "backwards" by mistake: void shuffle2(std::vector<int>& vec) { int n = vec.size(); for (int i = 1; i < n; ++i) { std::swap(vec[i], vec[rand() % (i + 1)]); } } Is this version in any way worse (or better) than the first? Does it skew the resulting probabilities? Yes it's even distribution assuming rand() is. We will prove this by showing that each input can generate

Generate a matrix of all possible outcomes for throwing n dice (ignoring order)

送分小仙女□ 提交于 2019-12-05 00:30:05
问题 In cases where order does matter, it's rather easy to generate the matrix of all possible outcomes. One way for doing this is using expand.grid as shown here. What if it doesn't? If I'm right, the number of possible combinations is (S+N-1)!/S!(N-1)! , where S is the number of dice, each with N sides numbered 1 through N. (It is different from the well known combinations formula because it is possible for the same number to appear on more than one dice). For example, when throwing four six