probability

Selecting nodes with probability proportional to trust

Does anyone know of an algorithm or data structure relating to selecting items, with a probability of them being selected proportional to some attached value? In other words: http://en.wikipedia.org/wiki/Sampling_%28statistics%29#Probability_proportional_to_size_sampling The context here is a decentralized reputation system and the atta...

Miller-Rabin scheme implementation unpredictable output

Greetings everyone, I am new to scheme. I have tried and implemented probabilistic variant of rabin-miller algorithm using plt scheme. I know it is probabilistic and all, but I am getting the wrong results most of the time. I have implemented the same thing using C, and it worked well(never failed a try). I get the expect...

A Knockout tournament - no of possible combinations

What are the no of combinations in which 8 persons taking part in a knockout tornament play? Total no of matches played would be 7 but I also need the number of combinations that can for this set ...

What is the optimal winning strategy for this modified blackjack game?

Questions Is there a best value to stay on so that I win the greatest percentage of games possible? If so, what is it? Edit: Is there an exact probability of winning that can be calculated for a given limit, independent of whatever the opponent does? (I haven't done probability & statistics since college). I'd be interested in seeing t...

Dice odds: Simulating a game of Craps

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...

How to formally prove that Geometric distribution is the discrete analogous of the Exponential one?

How to formally prove that Geometric distribution is the discrete analogous of the Exponential one? ...

How to generate correlated binary variables

Dear All: I need to generate a series of N random binary variables with a given correlation function. Let x = {xi} be a series of binary variables (taking the value 0 or 1, i running from 1 to N). The marginal probability is given Pr(xi = 1) = p, and the variables should be correlated in the following way: Corr[ xi xj ] = const |ij| (...

Python - Is a dictionary slow to find frequency of each character?

I am trying to find a frequency of each symbol in any given text using an algorithm of O(n) complexity. My algorithm looks like: s = len(text) P = 1.0/s freqs = {} for char in text: try: freqs[char]+=P except: freqs[char]=P but I doubt that this dictionary-method is fast enough, because it depends on the ...

Combinatorics, probability, dice

A friend of mine asked: if I have two dice and I throw both of them, what is the most frequent sum (of the two dice' numbers)? I wrote a small script: from random import randrange d = dict((i, 0) for i in range(2, 13)) for i in xrange(100000): d[randrange(1, 7) + randrange(1, 7)] += 1 print d Which prints: 2: 2770, 3: 5547, 4:...

Cosmic Rays: what is the probability they will affect a program?

Once again I was in a design review, and encountered the claim that the probability of a particular scenario was "less than the risk of cosmic rays" affecting the program, and it occurred to me that I didn't have the faintest idea what that probability is. "Since 1/2^128 is 1 out of 340282366920938463463374607431768211456, I think we...

Rewrite probabilities as boolean algebra

I'm given three binary random variables: X, Y, and Z. I'm also given the following: P(Z | X) P(Z | Y) P(X) P(Y) I'm then supposed to determine whether or not it is possible to find P(Z | Y, X). I've tried rewriting the solution in the form of Bayes' Theorem and have gotten nowhere. Given that these are boolean random variables, is i...

How to set probability for the sprite in shooting game ?

My game is a small shooting game in cocos2d. The enemy generates the bullets to shoot player at intervals of time. I have created a random y , so that bullets touch the opposite edge at random heights. If the bullet touches the player the enemy wins. But, I need to set probability for the enemy accuracy. If the probability of enemy is gi...

Generating all unique combinations for "drive ya nuts" puzzle

A while back I wrote a simple python program to brute-force the single solution for the drive ya nuts puzzle. The puzzle consists of 7 hexagons with the numbers 1-6 on them, and all pieces must be aligned so that each number is adjacent to the same number on the next piece. The puzzle has ~1.4G non-unique possibilities: you have 7! o...

Probability question: Estimating the number of attempts needed to exhaustively try all possible placements in a word search.

Would it be reasonable to systematically try all possible placements in a word search? Grids commonly have dimensions of 15*15 (15 cells wide, 15 cells tall) and contain about 15 words to be placed, each of which can be placed in 8 possible directions. So in general it seems like you can calculate all possible placements by the followin...

reservoir sampling problem

This MSDN article proves the correctness of Reservoir Sampling algorithm as follows: Base case is trivial. For the k+1st case, the probability a given element i with position <= k is in R is s/k. The probability i is replaced is the probability k+1st element is chosen multiplied by i being chosen to be replaced, which is: s/(k+1) * 1...

How do I solve this conditional probabilities problem with MATLAB?

If P( cj | xi ) are already known, where i=1,2,...n; j=1,2,...k; How do I calculate/estimate: P( cj | xl , xm , xn ), where j=1,2,...k; l,m,n {1,2,...n} ? ...

How many times can you randomly generate a GUID before you risk duplicates? (.NET)

Mathematically I suppose it's possible that even two random GUIDs generated using the built in method in the .NET framework are identical, but roughly how likely are they to clash if you generate hundreds or thousands? If you generated one for every copy of Windows in the world, would they clash? The reason I ask is because I have a pr...

C++ function for picking from a list where each element has a distinct probability

I have an array of structs and one of the fields in the struct is a float. I want to pick one of the structs where the probability of picking it is relative to the value of the float. ie struct s{ float probability; ... } s sArray[50]; What is the fastest way to decide which s to pick? Is there a function for this? If I knew ...

Fitting Gaussian KDE in numpy/scipy in Python

I am fitting a Gaussian kernel density estimator to a variable that is the difference of two vectors, called "diff", as follows: gaussian_kde_covfact(diff, smoothing_param) -- where gaussian_kde_covfact is defined as: class gaussian_kde_covfact(stats.gaussian_kde): def __init__(self, dataset, covfact = 'scotts'): self.covfac...

Calculating odds distribution with 6-sided dice

I'm trying to calculate the odds distribution of a changing number of 6-sided die rolls. For example, 3d6 ranges from 3 to 18 as follows: 3:1, 4:3, 5:6, 6:10, 7:15, 8:21, 9:25, 10:27, 11:27, 12:25, 13:21, 14:15, 15:10, 16:6, 17:3, 18:1 I wrote this php program to calculate it: function distributionCalc($numberDice,$sides=6) { for ( $...