Questions tagged [sampling]

Creating samples from a well-specified population using a probabilistic method and/or producing random numbers from a specified distribution.

119 questions
58
votes
5 answers

Why is the Mersenne Twister regarded as good?

The Mersenne Twister is widely regarded as good. Heck, the CPython source says that it "is one of the most extensively tested generators in existence." But what does this mean? When asked to list properties of this generator, most of what I can…
Veedrac
  • 992
  • 1
  • 7
  • 16
36
votes
6 answers

Uniform sampling from a simplex

I am looking for an algorithm to generate an array of N random numbers, such that the sum of the N numbers is 1, and all numbers lie within 0 and 1. For example, N=3, the random point (x, y, z) should lie within the triangle: x + y + z = 1 0 < x <…
Ruofeng
  • 463
  • 1
  • 4
  • 4
24
votes
3 answers

Is rejection sampling the only way to get a truly uniform distribution of random numbers?

Suppose that we have a random generator that outputs numbers in the range $[0..R-1]$ with uniform distribution and we need to generate random numbers in the range $[0..N-1]$ with uniform distribution. Suppose that $N < R$ and $N$ does not evenly…
Vor
  • 12,743
  • 1
  • 31
  • 62
22
votes
11 answers

How to simulate a die given a fair coin

Suppose that you're given a fair coin and you would like to simulate the probability distribution of repeatedly flipping a fair (six-sided) die. My initial idea is that we need to choose appropriate integers $k,m$, such that $2^k = 6m$. So after…
probability_guy
  • 223
  • 1
  • 2
  • 4
15
votes
2 answers

Sampling perfect matching uniformly at random

Suppose I have a graph $G$ with $M(G)$ the (unknown) set of perfect matchings of $G$. Suppose this set is non-empty, then how difficult is it to sample uniformly at random from $M(G)$? What if I am okay with a distribution that is close to uniform,…
Artem Kaznatcheev
  • 4,872
  • 2
  • 28
  • 57
14
votes
3 answers

Efficiently sampling shortest $s$-$t$ paths uniformly and independently at random

Let $G$ be a graph, and let $s$ and $t$ be two vertices of $G$. Can we efficiently sample a shortest $s$-$t$ path uniformly and independently at random from the set of all shortest paths between $s$ and $t$? For simplicity, we can assume $G$ is…
Juho
  • 22,905
  • 7
  • 63
  • 117
13
votes
2 answers

Efficient algorithm to generate two diffuse, deranged permutations of a multiset at random

Background $\newcommand\ms[1]{\mathsf #1}\def\msD{\ms D}\def\msS{\ms S}\def\mfS{\mathfrak…
13
votes
1 answer

Generate scale-free networks with power-law degree distributions using Barabasi-Albert

I'm trying to reproduce the synthetic networks (graphs) described in some papers. It is stated that the Barabasi-Albert model was used to create "scale-free networks with power-law degree distributions, $P_A(k) ∝ k^{-λ}$". $P_A$ is a probability…
Agostino
  • 347
  • 1
  • 5
  • 11
10
votes
3 answers

Random sampling in a polygon

I would like to sample a uniformly random point in a polygon... If sample a large number they'd be equally likely to fall into two regions if they have the same area. This would be quite simple if it were a square since I would take two random…
john mangual
  • 1,951
  • 1
  • 21
  • 27
8
votes
3 answers

Constructing a random Hamiltonian Cycle (Secret Santa)

I was programming a little Secret Santa tool for my extended family's gift exchange. We had a few constraints: No recipients within the immediate family Nobody should get who they got last year The whole thing should be a cycle (Sandy gives to…
8
votes
3 answers

Efficient sampling from all positive integers to find the largest integer below a transition for f(n)

Let's say we want to find the smallest positive integer x for which some property A holds. We know that such an integer exists. However, we have no knowledge about the scale of x (i.e. x could be 7 or 5'142 or 17 Quadrillion or whatever). We have a…
Blupper
  • 183
  • 4
7
votes
3 answers

How to select a binary tree node uniformly at random

The exercise I'm trying to solve is You are implementing a binary search tree class from scratch, which, in addition, to insert, find and delete, has a method getRandomNode() which returns a random node from the tree. All nodes should be equally…
justin
  • 71
  • 1
  • 4
7
votes
1 answer

Algorithms for graph generation using given properties

There may be a large number of algorithms proposed for generating graphs satisfying some common properties (e.g., clustering coefficient, average shortest path length, degree distribution, etc). My question concerns a specific case: I want to…
skyork
  • 193
  • 1
  • 5
7
votes
3 answers

What's a uniform shuffle?

What does it mean exactly a "uniform shuffle" algorithm ? Is this method considered a uniform shuffle ? public void shuffle(Comparable[] a) { int n = a.length; int k, j; for (int i = 0; i < n; i++) { k = StdRandom.uniform(n); //…
morfioce
  • 255
  • 3
  • 5
7
votes
1 answer

Sampling a uniform distribution of fixed size strings containing no forbidden substrings

Given a list of "forbidden" words (substrings), an alphabet, and a desired output string length, how would I efficiently sample output strings containing no forbidden word? For short output strings with few forbidden words, I would use simple…
1
2 3 4 5 6 7 8