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