Questions tagged [probability]

Consider if your question would be better at stats.stackexchange.com. Probability touches upon uncertainty, random phenomena, random numbers, random variables, probability distributions, sampling, combinatorics.

See also https://statistics.stackexchange.com

Probability theory is a branch of mathematics that studies uncertainty and random phenomena. It operates by introducing a sample space (a set), and associating probabilities (numbers between 0 and 1, inclusive) to certain subsets of this set, in a manner that satisfies some sensible axioms. If the sample space can be thought of as the real line, we obtain random variables; if it is a Euclidean space, we obtain random vectors. Random variables and random vectors have associated probability distributions, which can be characterized by probability density functions, cumulative density functions, moments, characteristic or moment generating functions.

Typically, questions with this tag will deal with computing (exactly or approximately) probabilities of certain events (from winning a lottery to server outages), drawing random samples, approximating distributions, etc. There might be an overlap with statistics and/or statistical packages (R, SAS, Stata).

Synonym: probability-theory

4021 questions
30
votes
9 answers

How to do weighted random sample of categories in python

Given a list of tuples where each tuple consists of a probability and an item I'd like to sample an item according to its probability. For example, give the list [ (.3, 'a'), (.4, 'b'), (.3, 'c')] I'd like to sample 'b' 40% of the time. What's the…
John
  • 303
  • 1
  • 3
  • 5
30
votes
5 answers

Create Bayesian Network and learn parameters with Python3.x

I'm searching for the most appropriate tool for python3.x on Windows to create a Bayesian Network, learn its parameters from data and perform the inference. The network structure I want to define myself as follows: It is taken from this paper. All…
30
votes
5 answers

What are probabilistic data structures?

I have read about "probabilistic" data structures like bloom filters and skip lists. What are the common characteristics of probabilistic data structures and what are they used for?
free_easy
  • 5,061
  • 3
  • 25
  • 39
30
votes
2 answers

Plotting probability density function by sample with matplotlib

I want to plot an approximation of probability density function based on a sample that I have; The curve that mimics the histogram behaviour. I can have samples as big as I want.
Cupitor
  • 11,007
  • 19
  • 65
  • 91
29
votes
8 answers

Distributed probability random number generator

I want to generate a number based on a distributed probability. For example, just say there are the following occurrences of each numbers: Number| Count 1 | 150 2 | 40 3 | 15 4 | 3 …
Mark Conway
  • 483
  • 1
  • 5
  • 10
29
votes
7 answers

Generate random integers with probabilities

I'm a bit confused about how to generate integer values with probabilities. As an example, I have four integers with their probability values: 1|0.4, 2|0.3, 3|0.2, 4|0.1 How can I generate these four numbers taking into account their probabilities?
Headshota
  • 21,021
  • 11
  • 61
  • 82
29
votes
4 answers

How to generate random numbers biased towards one value in a range?

Say, if I wanted to generate an unbiased random number between min and max, I'd do: var rand = function(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }; But what if I want to generate a random number between min and max…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
29
votes
9 answers

Random boolean with weight or bias

I need to generate some random booleans. However I need to be able to specify the probability of returning true. As a results doing: private Random random = new Random(); random.nextBoolean(); will not work. One possible solution would…
diestl
  • 2,020
  • 4
  • 23
  • 37
27
votes
6 answers

How much can you truncate a SHA1 hash and be reasonably sure of having an unique ID?

I am making an application that stores documents and gives each one a UID based on a SHA1 digest of a few things including the timestamp. The digest has a lot of characters, and I want to allow users to identify the documents by using the first x…
dan
  • 43,914
  • 47
  • 153
  • 254
27
votes
1 answer

Why eigenvector & eigenvalue in LDA become zero?

I'd like to implement fast PLDA (Probabilistic Linear Discriminant Analysis) in OpenCV. in this, LINK fast PLDA have been implemented in Matlab and Python. One of the parts of PLDA is LDA. I've written following code for implementing LDA in…
Saeid
  • 508
  • 1
  • 4
  • 20
27
votes
3 answers

Defining a white noise process in Python

I need to draw samples from a white noise process in order to implement a particular integral numerically. How do I generate this with Python (i.e., numpy, scipy, etc.)?
abcd
  • 10,215
  • 15
  • 51
  • 85
26
votes
3 answers

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

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…
Andrew
  • 36,541
  • 13
  • 67
  • 93
26
votes
3 answers

Fastest primality test

Could you suggest a fast, deterministic method that is usable in practice, for testing if a large number is prime or not? Also, I would like to know how to use non-deterministic primality tests correctly. For example, if I'm using such a method,…
user500944
26
votes
9 answers

What's the best way to unit test code that generates random output?

Specifically, I've got a method picks n items from a list in such a way that a% of them meet one criterion, and b% meet a second, and so on. A simplified example would be to pick 5 items where 50% have a given property with the value 'true', and 50%…
Flynn1179
  • 11,925
  • 6
  • 38
  • 74
26
votes
8 answers

Game Design/theory, Loot Drop Chance/Spawn Rate

I have a very specific and long-winded question for you all. This question is both about programming and game-theory. I recently added spawnable ore to my Turn Based Strategy Game: http://imgur.com/gallery/0F5D5Ij (For those of you that look please…
Krythic
  • 4,184
  • 5
  • 26
  • 67