-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributions.py
36 lines (28 loc) · 1.37 KB
/
distributions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from core import *
def ideal_distribution(N):
""" Create the ideal soliton distribution.
In practice, this distribution gives not the best results
Cf. https://en.wikipedia.org/wiki/Soliton_distribution
"""
probabilities = [0, 1 / N]
probabilities += [1 / (k * (k - 1)) for k in range(2, N+1)]
probabilities_sum = sum(probabilities)
assert probabilities_sum >= 1 - EPSILON and probabilities_sum <= 1 + EPSILON, "The ideal distribution should be standardized"
return probabilities
def robust_distribution(N):
""" Create the robust soliton distribution.
This fixes the problems of the ideal distribution
Cf. https://en.wikipedia.org/wiki/Soliton_distribution
"""
# The choice of M is not a part of the distribution ; it may be improved
# We take the median and add +1 to avoid possible division by zero
M = N // 2 + 1
R = N / M
extra_proba = [0] + [1 / (i * M) for i in range(1, M)]
extra_proba += [math.log(R / ROBUST_FAILURE_PROBABILITY) / M] # Spike at M
extra_proba += [0 for k in range(M+1, N+1)]
probabilities = np.add(extra_proba, ideal_distribution(N))
probabilities /= np.sum(probabilities)
probabilities_sum = np.sum(probabilities)
assert probabilities_sum >= 1 - EPSILON and probabilities_sum <= 1 + EPSILON, "The robust distribution should be standardized"
return probabilities