-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_clicks.py
42 lines (30 loc) · 1.23 KB
/
calc_clicks.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
37
38
39
40
41
42
# coding: utf-8
from math import factorial
import matplotlib.pyplot as plt
import numpy as np
def get_prob_of_conv_being_lower(converted, total, conversion):
prob = 0
for i in range(converted + 1):
set_probability = conversion**i * (1 - conversion)**(total - i)
mutation_count = (factorial(total) / factorial(total - i)) / factorial(i)
prob += set_probability * mutation_count
return prob
def get_prob_of_conv_being_between(conv1, conv2, converted, total):
prob1 = get_prob_of_conv_being_lower(converted, total, conv1)
prob2 = get_prob_of_conv_being_lower(converted, total, conv2)
return abs(prob1 - prob2)
def get_distribution(total, converted, resolution=100):
space = np.linspace(0, 1, num=resolution)
points = []
for i, val in enumerate(space[:-1]):
next_val = space[i + 1]
prob = get_prob_of_conv_being_between(val, next_val, converted, total)
points.append(prob)
return space[:-1], points
total = int(input('Кликов: '))
converted = int(input('Конверсий: '))
resolution = 1000
print get_prob_of_conv_being_between(0, 0.01, converted, total)
space, points = get_distribution(total, converted, resolution)
plt.plot(space, points)
plt.show()