DNF杂谈:模拟实验1000万次强化,测试1-10一次成的几率

作者:鹭死

概率是按照公布的+公会药,无宠物
——以下内容为我的一位不愿意透露姓名的富婆朋友分享——

(更新了)



# -*- coding: utf-8 -*-
"""
Created on Tue Feb 1 22:18:32 2022
@author: Yu
"""
PROBABILITY_Increase = [1, 1, 1, 1, 0.81,
0.71, 0.61, 0.71, 0.61, 0.51]
TRAILS_TIMES = 10000000 #试验次数
import numpy as np
import random
import matplotlib.pyplot as plt
from matplotlib import ticker
x = np.arange(1000)
y = np.zeros((1000,), dtype = int) # y[10]表示10次就上10的次数
sad_7_4 = 0 # 74惨案
sad_8_5 = 0
sad_9_6 = 0
total_Times = 0
best = 10 # 最黑的次数
def make_autopct(values):
def my_autopct(pct):
total = sum(values)
val = int(round(pct*total/100.0))
# 同时显示数值和占比的饼图
return '{p:.2f}% ({v:d})'.format(p=pct,v=val)
return my_autopct
for times in range(TRAILS_TIMES):
current_Times = 0 # 当前次数
current_Level = 0 # 当前等级
current_7_to_4 = 0 # 74惨案次数
current_8_to_5 = 0 # 85惨案次数
current_9_to_6 = 0 # 93惨案次数
while (current_Level < 10):
current_Times = current_Times + 1
if (random.random() < PROBABILITY_Increase[current_Level]): # 增肥成功
current_Level = current_Level + 1
else: #增肥失败
if current_Level == 9:
current_9_to_6 = current_9_to_6 + 1
current_Level = current_Level - 3
elif current_Level == 8:
current_8_to_5 = current_8_to_5 + 1
current_Level = current_Level - 3
elif current_Level == 7:
current_7_to_4 = current_7_to_4 + 1
current_Level = current_Level - 3
elif current_Level >= 4:
current_Level = current_Level - 1
#print(current_Level,end = "->")
#print("\n本次增肥花费次数: {}".format(current_Times))
#print("7-->4失败次数 : {}".format(current_7_to_4))
#print("8-->5失败次数 : {}".format(current_8_to_5))
#print("9-->6失败次数 : {}".format(current_9_to_6))
y[current_Times] = y[current_Times] + 1
sad_7_4 = sad_7_4 + current_7_to_4
sad_8_5 = sad_8_5 + current_8_to_5
sad_9_6 = sad_9_6 + current_9_to_6
total_Times = total_Times + current_Times
if best < current_Times:
best = current_Times
print("试验次数: {}".format(TRAILS_TIMES))
print("天选之人增肥的次数: {}".format(best))
print("平均增肥花费次数为: {}".format(total_Times / TRAILS_TIMES))
print("平均7上8失败次数为: {}".format(sad_7_4 / TRAILS_TIMES))
print("平均8上9失败次数为: {}".format(sad_8_5 / TRAILS_TIMES))
print("平均9上10失败次数为: {}".format(sad_9_6 / TRAILS_TIMES))
P_distribution = y/TRAILS_TIMES #转换为概率
res_10 = y[10]
res_11_to_20 = 0
for i in range(11,20+1):
res_11_to_20 = res_11_to_20 + y
res_21_to_30 = 0
for i in range(21,30+1):
res_21_to_30 = res_21_to_30 + y
res_31_to_40 = 0
for i in range(31,40+1):
res_31_to_40 = res_31_to_40 + y
res_41_to_50 = 0
for i in range(41,50+1):
res_41_to_50 = res_41_to_50 + y
res_51_to_60 = 0
for i in range(51,60+1):
res_51_to_60 = res_51_to_60 + y
res_61_to_80 = 0
for i in range(61,80+1):
res_61_to_80 = res_61_to_80 + y
res_81_to_100 = 0
for i in range(81,100+1):
res_81_to_100 = res_81_to_100 + y
res_101_to_150 = 0
for i in range(101,150+1):
res_101_to_150 = res_101_to_150 + y
res_best= 0
for i in range(151,best+100):
res_best = res_best + y
interval = np.array([res_10, res_11_to_20,
res_21_to_30,res_31_to_40,
res_41_to_50,res_51_to_60,
res_61_to_80,res_81_to_100,
res_101_to_150,res_best])
x_name = ['10','11-20','21-30','31-40','41-50','51-60','61-80','81-100','101-150','>150']
Area_distribution = interval/TRAILS_TIMES
fig1, axis1 = plt.subplots()
axis1.bar(x[0:best+1], P_distribution[0:best+1], label='Fatter! Samples Number : {}'.format(TRAILS_TIMES))
axis1.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=1, decimals=1)) #设置为百分比显示
plt.xlabel('Total Times')
plt.ylabel('Distribution')
plt.savefig('./axis1.jpg')
plt.legend()
fig2, axis2 = plt.subplots()
axis2.bar(x_name, Area_distribution, label='Fatter! Samples Number : {}'.format(TRAILS_TIMES))
axis2.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=1, decimals=1)) #设置为百分比显示
plt.xlabel('Total Times')
plt.ylabel('Distribution')
plt.legend()
fig3, axis3 = plt.subplots()
axis3.pie(Area_distribution, labels=x_name, autopct=make_autopct(Area_distribution))
plt.show()
代码分享如上,感兴趣的可以保存一下康康,我不太懂
联动一下最近的帖子,基数不够庞大、暗改几率什么的,得到以下结论:(点击就看)
结论:1-10一路连成不失败几率不到8%,平均需要37次,62.6%的人情况好于平均
