回答編集履歴

1

サンプルコード追加

2020/05/05 02:32

投稿

magichan
magichan

スコア15898

test CHANGED
@@ -1 +1,99 @@
1
1
  現状の結果のどの部分に問題を感じているのか不明なのですが、現状の分布でシミュレートすると、99.9パーセンタイル値が `539000` あたりに、99.95パーセンタイル値でさえも `553000` あたりとなるので、たかだか 10000個のサンプルで最大値が `577256` となるのは妥当なのではないでしょうか。
2
+
3
+
4
+
5
+ ---
6
+
7
+ 【コメントを受けてソースコードの変更】
8
+
9
+ ```Pyhon
10
+
11
+
12
+
13
+ # Monte Carlo
14
+
15
+ import pandas as pd
16
+
17
+ import numpy as np
18
+
19
+ from scipy import stats
20
+
21
+ import matplotlib.pyplot as plt
22
+
23
+ import seaborn as sns
24
+
25
+ import statistics
26
+
27
+ sns.set_style('darkgrid')
28
+
29
+
30
+
31
+ # Properties
32
+
33
+ trials = 10000000
34
+
35
+ A = np.random.uniform(0.1, 0.3, trials)
36
+
37
+ B = np.random.uniform(500, 700, trials)
38
+
39
+ C = np.random.triangular(10, 20, 30, trials) # 三角分布
40
+
41
+ D = 100
42
+
43
+
44
+
45
+ x = A * B * C * D
46
+
47
+
48
+
49
+ x = x.astype(int)
50
+
51
+
52
+
53
+ fig, ax = plt.subplots()
54
+
55
+ ax.hist(x, bins=18, density=False, rwidth=0.6, Color="steelblue")
56
+
57
+ ax.set_title('Test')
58
+
59
+ ax.set_xlabel('x')
60
+
61
+ ax.set_ylabel('Frequency')
62
+
63
+ # plt.show()
64
+
65
+
66
+
67
+ mean = np.mean(x)
68
+
69
+ std = np.std(x)
70
+
71
+ mode, _ = stats.mode(x)
72
+
73
+ p0,p10,p50,p90,p100 = np.percentile(x, q=[0,10,50,90,100])
74
+
75
+
76
+
77
+ print(f'P90: {p90:.0f}')
78
+
79
+ print(f'P50: {p50:.0f}')
80
+
81
+ print(f'P10: {p10:.0f}')
82
+
83
+ print(f'Mean: {mean:.0f}')
84
+
85
+ print(f'Stdv: {std:.0f}')
86
+
87
+ print(f'Mode: {mode[0]:.0f}')
88
+
89
+
90
+
91
+ # 基本統計量だけならば下記のコードでも良い(MODEはないけど)
92
+
93
+ print(pd.Series(x).describe())
94
+
95
+ # scipy.stats を使って基本統計量を出した場合は歪度と尖度も出る
96
+
97
+ print(stats.describe(x))
98
+
99
+ ```