-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrialGenerator.R
More file actions
128 lines (98 loc) · 5.32 KB
/
TrialGenerator.R
File metadata and controls
128 lines (98 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
library(data.table)
## MAKE SAMPLE FROM EXPERIMENT
fileList <- list.files("C:/Users/ccdl/Downloads/Charlotte",pattern=".txt")
# Read all the files and create a FileName column to store filenames
DT <- rbindlist( sapply(paste("~/Downloads/Charlotte/",fileList, sep=""), fread, simplify = FALSE),
use.names = TRUE, idcol = "FileName" )
DT <- DT[DT$Execution.RT != 0,] # Remove execution times of 0 ms
randomSample <- DT[sample(1:nrow(DT),40)]
randomStimuliExperiment <- data.frame(
operatorTask1 = randomSample$Operator2, operatorTask2 = randomSample$Operator3, operatorTask3 = randomSample$Operator1,
x = randomSample$X, y = randomSample$Y, probe = randomSample$Probe)
# Example format: ((double third add) (5 9) 13))
exportStimuli <- paste("((", randomStimuliExperiment$operatorTask1, randomStimuliExperiment$operatorTask2, randomStimuliExperiment$operatorTask3, ")","(",randomStimuliExperiment$x,randomStimuliExperiment$y,")",randomStimuliExperiment$probe,")")
# write(exportStimuli,"~/Documents/GitHub/ACTR_RITL",ncolumns=1) # Permission denied
write(exportStimuli,"trials",ncolumns=1)
## MAKE DATA FROM SCRATCH
unary <- c("DOUBLE","TRIPLE","INCREMENT", "DECREMENT","THIRD", "HALF")
binary <- c("TIMES","DIVIDE","ADD", "SUBTRACT")
#Define functions
DECREMENT <- function(x) {x-1}
THIRD <- function(x) {x/3}
INCREMENT <- function(x) {x+1}
TRIPLE <- function(x) {x*3}
HALF <- function(x) {x/2}
DOUBLE <- function(x) {x*2}
SUBTRACT <- function(x, y) {x-y}
TIMES <- function(x,y) {x*y}
DIVIDE <- function(x,y) {x/y}
ADD <- function(x,y) {x+y}
generatePracticeTrials <- function(numPracticedCombinations = 2) {
practiceInst <- data.frame(
operatorTask1 = rep(sample(unary,1),10), operatorTask2 = rep(sample(unary,1),10), operatorTask3 = rep(sample(binary,1),10),
x = sample(1:9,10,T), y = sample(1:9,10,T), probe = 0, stringsAsFactors = F)
while (nrow(practiceInst)/10 != numPracticedCombinations) {
practiceInst <- rbind(practiceInst,data.frame(
operatorTask1 = rep(sample(unary,1),10), operatorTask2 = rep(sample(unary,1),10), operatorTask3 = rep(sample(binary,1),10),
x = 0, y = 0, probe = 0, stringsAsFactors = F))
}
# Solve operations
for (i in 1:length(practiceInst$probe)) {
while((1>practiceInst$probe[i]) | (practiceInst$probe[i]>49)) {
practiceInst$x[i] <- sample(1:9,1)
practiceInst$y[i] <- sample(1:9,1)
tempX <- match.fun(practiceInst$operatorTask1[i])(practiceInst$x[i])
tempY <- match.fun(practiceInst$operatorTask2[i])(practiceInst$y[i])
while (!floor(tempX)) {
practiceInst$x[i] <- sample(1:9,1)
tempX <- match.fun(practiceInst$operatorTask1[i])(practiceInst$x[i])
}
while (!floor(tempY)) {
practiceInst$y[i] <- sample(1:9,1)
tempY <- match.fun(practiceInst$operatorTask2[i])(practiceInst$y[i])
}
practiceInst$probe[i] <- floor(match.fun(practiceInst$operatorTask3[i])(tempX,tempY))
}
}
# Add mistakes (-1 or +1) and randomize
mistakeRows <- sample(nrow(practiceInst),nrow(practiceInst)/2)
practiceInst$probe[mistakeRows] <- practiceInst$probe[mistakeRows]-1
practiceInst[practiceInst$probe == 0,"probe"] <- practiceInst[practiceInst$probe == 0,"probe"]+2 # If the probe becomes 0, make it 2
practiceInst <- practiceInst[sample(nrow(practiceInst),nrow(practiceInst)),]
return(practiceInst)
}
session1Trials <- generatePracticeTrials()
generateSession2Trials <- function(numPracticedCombinations = 2, practiceInst = session1Trials) {
# WARNING: Chances are that filler items are identical to practiced trials
practiceInst <- rbind(practiceInst,data.frame(
operatorTask1 = sample(unary,numPracticedCombinations*10,T), operatorTask2 = sample(unary,numPracticedCombinations*10,T), operatorTask3 = sample(binary,numPracticedCombinations*10,T),
x = 0, y = 0, probe = 0, stringsAsFactors = F))
# Solve operations
for (i in 1:length(practiceInst$probe)) {
while((1>practiceInst$probe[i]) | (practiceInst$probe[i]>49)) {
practiceInst$x[i] <- sample(1:9,1)
practiceInst$y[i] <- sample(1:9,1)
tempX <- match.fun(practiceInst$operatorTask1[i])(practiceInst$x[i])
tempY <- match.fun(practiceInst$operatorTask2[i])(practiceInst$y[i])
while (!floor(tempX)) {
practiceInst$x[i] <- sample(1:9,1)
tempX <- match.fun(practiceInst$operatorTask1[i])(practiceInst$x[i])
}
while (!floor(tempY)) {
practiceInst$y[i] <- sample(1:9,1)
tempY <- match.fun(practiceInst$operatorTask2[i])(practiceInst$y[i])
}
practiceInst$probe[i] <- floor(match.fun(practiceInst$operatorTask3[i])(tempX,tempY))
}
}
# Add mistakes (-1 or +1) and randomize
mistakeRows <- sample(nrow(practiceInst),nrow(practiceInst)/2)
practiceInst$probe[mistakeRows] <- practiceInst$probe[mistakeRows]-1
practiceInst[practiceInst$probe == 0,"probe"] <- practiceInst[practiceInst$probe == 0,"probe"]+2 # If the probe becomes 0, make it 2
practiceInst <- practiceInst[sample(nrow(practiceInst),nrow(practiceInst)),]
return(practiceInst)
}
session2Trials <- generateSession2Trials()
modelTrials <- rbind(session1Trials,session2Trials)
exportStimuli <- paste("((", modelTrials$operatorTask1, modelTrials$operatorTask2, modelTrials$operatorTask3, ")","(",modelTrials$x,modelTrials$y,")",modelTrials$probe,")")
write(exportStimuli,"trials",ncolumns=1)