关于37%结论的探索(最优停止理论,如何最优选择停止观望时机)

未得出相符结论,也许是我的算法有问题。。。。

from random import choice
from random import sample

import random
import pygal

points = []
results = []
def get_results():
	#随机生成一个长度为100,各元素为1到100之间的整数的列表
	#用来模拟100个备选项
	t = 1
	array = []
	while t<= 100:
		array.append(random.randint(1,100))
		t = t+1
	max_num = max(array)

	#将列表切片,分为两部分
	#切点模拟“停止观察,开始准备下手”的时刻
	for j in range(1,100):
		refused = max(array[0:j])
		remains = max(array[j:100])
		if refused >= max_num-1:
			if remains >= refused:
				results.append(j)
	return results

for i in range(10000):
	get_results()
	point = int((results[0]+results[-1]) / 2)
	points.append(point)
	
points.sort()


#统计结果的次数,输出为字典
def count_point(points):
	frequency = {}
	for i in set(points):
		frequency[i] = points.count(i)
	return frequency

frequency=count_point(points)



#绘制直方图,观察抉择点获得好结果的频率

hist = pygal.Bar()
hist.x_labels = frequency.keys()
hist.add("best_choosen",frequency.values())

hist.x_title = "All Choose Time"
hist.y_title = "Good Time"
hist.title = "The Time of Best Time To Choose"

hist.render_to_file('best_all_in.svg')

我的结果,与最优选择先随观时间增加而增加,到50——60为峰值,随后减小(图表右边刻度大概到65):

关于37%结论的探索(最优停止理论,如何最优选择停止观望时机)_第1张图片

你可能感兴趣的:(算法探索)