我正在嘗試創建注意力網絡任務的Python版本。將此作爲參考(第3頁):http://www.researchgate.net/publication/7834908_The_Activation_of_Attentional_NetworksPython因素級別組合
我總共有216個試驗。其中一半將是「一致的」,一半是「不一致的」。此外,216的三分之一將是「nocue」,另外三分之一將是「中心」,並且最後三分之一將是「空間的」。這216個試驗中的每一個將是上述的一些組合(例如全等 - 空間的,不一致的,無)
這是我如何創造這些試驗現在:
import pandas as pd
import numpy as np
import random
#set number of trials
numTrials = 216
numCongruent = numTrials/2
numCue = numTrials/3
#create shuffled congruency conditions
congruent = ["congruent"] * numCongruent
incongruent = ["incongruent"] * numCongruent
congruentConditions = congruent + incongruent
random.shuffle(congruentConditions)
#create shuffled cue conditions
noCue = ["none"] * numCue
centerCue = ["center"] * numCue
spatialCue = ["spatial"] * numCue
cueConditions = noCue + centerCue + spatialCue
random.shuffle(cueConditions)
#put everything into a dataframe
df = pd.DataFrame()
congruentArray = np.asarray(congruentConditions)
cueArray = np.asarray(cueConditions)
df["congruent"] = congruentArray
df["cue"] = cueArray
print df
2個問題...
- 現在,這個工作,但其中重要的一點是確保均勻分配水平的重刑。
例如,我需要確保所有的「一致」試驗有相同數量的「nocue」,「中心」和「空間」試驗。相反,例如,所有的「nocue」試驗都需要半數的「一致」和「不一致」試驗。
鑑於我隨機洗牌的條件,目前無法保證。這甚至會超過無限的樣本量,但這不是這種情況。
我該如何確保平等分配?
我已經採取了看笛卡爾乘積(https://docs.python.org/2/library/itertools.html#itertools.product),但我不完全,這將有助於我實現平等問題
- 一旦上述已然後我需要確保在最後的洗牌列表中,每個試驗類型(例如全等空間)在列表順序中遵循相同次數的相同次數
我一直在困惑你的問題的第二部分,這是一個更深入(和更有趣!)的問題。這取決於你,但是我認爲如果你把它作爲一個單獨的問題發佈,你會有更好的機會得到一個好的答案。理想情況下,你可以用更一般的方式來構成它(例如*「我怎樣才能生成隨機序列,其中每個獨特的項目跟隨彼此獨特的項目相同的次數?」*)。 –
好點。我會把這個問題分解成一個單獨的問題 – Simon