import numpy as np
from scipy.stats import bernoulli
import matplotlib.pyplot as plt
T = 20 # 刺激呈现的帧数
D = 10 # 刺激中点的数量
f = 0.55 # 正确点所占的比例
N_correct = 0 # 正确点的计数器
N_wrong = 0 # 错误点的计数器
delta = np.empty(T+1) # 计算每帧中的数量差
delta[0] = 0
#
for t in range(T): # 循环每一帧
dir = bernoulli.rvs(f, size=1)
N_correct = N_correct + dir # 正确点数量+1
N_wrong = N_wrong + (1-dir) # 错误点数量+1
# 数完这一帧中点的数量之后,计算并保存他们的差值
delta[t+1] = N_correct - N_wrong
fig = plt.figure(figsize=(4,4))
plt.plot(range(T+1), delta)
plt.ylabel('Running difference')
plt.xlabel('# of frame')
B = 40 # 一个固定的决策边界
D = 10 # 刺激中的总点数
f = 0.55 # 正确点所占的比例
N_correct = 0 # 正确点的计数器
N_wrong = 0 # 错误点的计数器
delta = [] # 将delta定义为一个列表
delta.append(N_correct - N_wrong)
i = 0
while np.abs(delta[i]) < B: # 循环,直至决策变量到达决策边界
dir = bernoulli.rvs(f, size=1)[0]
N_correct = N_correct + dir # 正确点数量+1
N_wrong = N_wrong + (1-dir) # 错误点数量+1
# 更新帧数
i = i + 1
# 计算并保存感觉差异
delta.append(N_correct - N_wrong)
# 所积累的感觉证据的符号决定了最中的决策
if delta[-1] > 0:
print('The answer is correct in this trial')
else:
print('The answer is wrong in this trial')
RT = i
print(f'Reaction time in this trial is {RT} frames')