【问题标题】:How do I compare a random 'x' to a 'getKeys' from a list如何将随机“x”与列表中的“getKeys”进行比较
【发布时间】:2015-12-15 22:41:21
【问题描述】:

在我的实验中,我展示了一个随机生成的刺激“x”,我需要将其与实验用户提供的密钥进行比较。 基本上,我有两个列表:

  • 一个有刺激的
  • 和一个有正确答案的人(他们应该给出的钥匙)

顺序是一样的,我的意思是刺激 1 应该得到答案列表中“位置 1”处的键。

我已经搜索了几个关于如何比较这两个列表的主题,但到目前为止还没有奏效。

这些是我尝试过的选项:

Answerruning = True
while Answerrunning:
    if event.getKeys(keyList):
      ReactionTime.getTime() 
      Keys = event.waitKeys()
      for givenKey in Keys:
          if givenKey == keyList:
              answer_stimulus = 2
              Answerrunning = False
              window.flip(clearBuffer = True)
    else:
      answer_stimulus = 0

还有这个选项,但我认为另一个更好:

keyList = []
givenKey = event.getKeys(keyList)
Answerrunning = True
while Answerrunning:
    for x in stimulus:
        if givenKey in keyList:
            ReactionTime.getTime()
            answer_stimulus = 2
            Answerrunning = False
            window.flip(clearBuffer = True)
        else:
            answer_stimulus = 0

我希望你们中的某个人能给我一个提示,告诉我如何比较这两个问题,从我的窗口中可以清楚地看到实验可以继续进行。

【问题讨论】:

    标签: python random compare psychopy


    【解决方案1】:

    您没有提到这一点,但您确实需要使用 TrialHandler 对象 http://www.psychopy.org/api/data.html 来为您处理变量,一次遍历您的条件文件(.xlsx 或 .csv)一行每次试验。即不要将刺激值和正确响应值放在列表中:将它们放在外部文件中,并让 PsychoPy 进行一次又一次的管理。

    如果您在该文件中有一个名为 correctResponse 的列,另一个名为 stimulusText 的列,以及一个名为 trials 的 TrialHandler,那么一些伪代码将如下所示:

    trialClock = core.Clock() # just create this once, & reset as needed
    
    # trials is a TrialHandler object, constructed by linking to an 
    # external file giving the details for each trial:
    for trial in trials:
        # update the stimulus for this trial.
        # the stimulusText variable is automatically populated
        # from the corresponding column in your conditions file:
        yourTextStimulus.setText(stimulusText)
    
        # start the next trial:
        trialClock.reset()
        answerGiven = False
    
        while not answerGiven:
    
            # refresh the stimuli and flip the window
            stimulus_1.draw() # and whatever other stimuli you have
            win.flip() # code pauses here until the screen is drawn
            # i.e. meaning we are checking for a keypress at say, 60 Hz
    
            response = event.getKeys() # returns a list
    
            if len(response) > 0: # if so, there was a response
                reactionTime = trialClock.getTime()
    
                # was it correct?
                if correctResponse in response:
                    answer = True
                else:
                    answer = False
    
                # store some data
                trials.addData('Keypress', response)
                trials.addData('KeypressRT', reactionTime) 
                trials.addData('KeypressCorrect', answer)
    
                # can now move on to next trial
                answerGiven = True
    

    PsychoPy 代码通常围绕每次刷新时绘制到屏幕的循环构建,因此上面的代码显示了在每次试验中,刺激物如何更新一次,但在每次刷新时重新绘制到屏幕上。在这个循环中,每次重绘屏幕时也会检查一次键盘。

    在您的代码中,您混合了getKeys(),它检查键盘的瞬时状态,和waitKeys(),它暂停直到给出响应(因此中断屏幕刷新周期)。所以通常避免后者。此外,当您使用getKeys() 时,您必须将结果分配给变量,因为此函数会清除缓冲区。上面,您使用getKeys(),然后再次检查键盘进行跟进。在这种情况下,初始响应将消失,因为它没有被存储。

    清如泥?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-27
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      相关资源
      最近更新 更多