-
Notifications
You must be signed in to change notification settings - Fork 7
/
problem2.py
78 lines (65 loc) · 2.34 KB
/
problem2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy.random as l
import numpy as n
import matplotlib.pyplot as p
mean = 3
sigma = 1
count_of_elements = 8
# квантиль уровня P (X<x)=0.4750 для N(0,1)
# TODO это нужно только для 1 варианта, мб вам нужно тут что-то поменять
cvantil0025gaussian = 1.96
def test(m=mean, c=count_of_elements):
global h_one_true, h_two_true
# of course sum is 10000
h_one_true = 0
h_two_true = 0
for i in range(10000):
# TODO поменять тут на своё распределение
array_of_elements_from_distribution = l.normal(m, sigma, c)
average = sum(array_of_elements_from_distribution) / c
right = average + (cvantil0025gaussian * sigma / n.sqrt(c))
left = average - (cvantil0025gaussian * sigma / n.sqrt(c))
if left < mean < right:
h_one_true += 1
else:
h_two_true += 1
return h_one_true, h_two_true
test()
print("result is :\n"
"hypnosis than mean is 3 was true {0} times\n"
"hypnosis than mean isn't 3 was true {1} times\n"
"оценка вероятности ошибки первого рода {2} "
.format(h_one_true, h_two_true, h_two_true / 10000)
)
"""
result is :
hypnosis than mean is 3 was true 9454 times
hypnosis than mean isn't 3 was true 546 times
оценка вероятности ошибки первого рода 0.0546
"""
counter = 1
array_of_points = []
array_of_counters = []
for i in range(9):
test(counter)
array_of_points.append(h_two_true / 10000)
array_of_counters.append(counter)
counter += 0.5
p.plot(array_of_counters, array_of_points,
linewidth=3,
color='r')
counter = 1
array_of_points = []
array_of_counters = []
for i in range(9):
test(counter, 50)
array_of_points.append(h_two_true / 10000)
array_of_counters.append(counter)
counter += 0.5
p.plot(array_of_counters, array_of_points,
linewidth=3,
color='g')
p.xlabel("Мат ожидание генерируемой выборки(настоящее)")
p.ylabel("Вероятость отвергнуть основную гипотезу")
p.text(2.3, 0.9, "Выборка из 50 элементов", rotation=300, color='g')
p.text(1, 0.85, "Выборка из 8 элементов", rotation=300, color='r')
p.show()