-
Notifications
You must be signed in to change notification settings - Fork 2
/
summation_test_conditioned_inhibition.Rmd
281 lines (250 loc) · 7.24 KB
/
summation_test_conditioned_inhibition.Rmd
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
---
title: "Summation test for conditioned inhibition"
author: "Deniz Tuzsus"
date: "12 November 2019"
output: html_document
---
```{r}
# setup constant variables over all simulations
n_features <- 120
cue_features <- 1:100
a <- b <- c <- d <- context <- outcome <- rep(0, n_features)
# setup stimuli
a[1:20] <- b [21:40] <- c[41:60] <- d[61:80] <- 1
context[81:100] <- 1
outcome[101:120] <- 1
# number of replications
n_replications <- 100
# learning rates
p_encode <- c(0.33, 0.67, 1)
# specify models
model = "Minerva AL"
```
```{r}
# specify events
training_ax_event <- a + context + outcome
training_ab_event <- a + b + context
training_cx_event <- c + context + outcome
probe_a <- a + context
probe_b <- b + context
probe_ab <- a + b + context
probe_bc <- b + c + context
probe_cd <- c + d + context
probe_c <- c + context
# setup trial number
n_trials <- 150
# prepare results object as matrix[n_trials, n_replications]
sim_results_xbc <- matrix(0, ncol = n_replications, nrow = length(p_encode))
sim_results_xcd <- matrix(0, ncol = n_replications, nrow = length(p_encode))
sim_results_xc <- matrix(0, ncol = n_replications, nrow = length(p_encode))
# specify object for normalized echo for every trial as 3D array[p_encode, n_trials, n_replications]
# with cells containing normalized echo vector
normalized_echos <- array(list(rep(NA, n_features)), dim = c(length(p_encode), n_trials, n_replications))
```
```{r}
#--------------- execute simulations--------------#
for (m in 1:length(model)){
for (r in 1:n_replications) {
for(i in 1:length(p_encode)) {
# Memory is empty on first trial
normalized_echo <- probe_memory(probe_ab, NULL, cue_features, model = model[m])
memory <- learn(
normalized_echo
, training_ab_event
, p_encode[i]
, NULL
, model = model[m]
)
normalized_echos[[i,1,r]] <- normalized_echo
# A -> X trials on every even number
for(j in 2:100) {
if (j %% 2 == 0){
normalized_echo <- probe_memory(probe_a, memory, cue_features, model = model[m])
memory <- learn(
normalized_echo
, training_ax_event
, p_encode[i]
, memory
, model = model[m]
)
normalized_echos[[i,j,r]] <- normalized_echo
}
else {
# AB trials on every odd number
normalized_echo <- probe_memory(probe_ab, memory, cue_features, model = model[m])
memory <- learn(
normalized_echo
, training_ab_event
, p_encode[i]
, memory
, model = model[m]
)
normalized_echos[[i,j,r]] <- normalized_echo
}
}
# CX trials
for(j in 101:150) {
normalized_echo <- probe_memory(probe_c, memory, cue_features, model = model[m])
memory <- learn(
normalized_echo
, training_cx_event
, p_encode[i]
, memory
, model = model[m]
)
normalized_echos[[i,j,r]] <- normalized_echo
}
normalized_echo_bc <- probe_memory(probe_bc, memory, cue_features, model = model[m])
normalized_echo_cd <- probe_memory(probe_cd, memory, cue_features, model = model[m])
normalized_echo_c <- probe_memory(probe_c, memory, cue_features, model = model[m])
sim_results_xbc[i,r] <- expect_event(outcome = outcome, normalized_echo = normalized_echo_bc)
sim_results_xcd[i,r] <- expect_event(outcome = outcome, normalized_echo = normalized_echo_cd)
sim_results_xc[i,r] <- expect_event(outcome = outcome, normalized_echo = normalized_echo_c)
}
}
}
```
```{r}
res_mat <- matrix(NA, nrow = 3, ncol = 3)
#compute means over replications
x <- rowMeans(sim_results_xbc)
#compute standard errors over replications
y <- apply(sim_results_xbc, 1, FUN = std_err)
for (i in 1:length(p_encode)){
res_mat[1,i] <- table_fun(x[i], y[i])
}
#compute means over replications
x <- rowMeans(sim_results_xcd)
#compute standard errors over replications
y <- apply(sim_results_xcd, 1, FUN = std_err)
for (i in 1:length(p_encode)){
res_mat[2,i] <- table_fun(x[i], y[i])
}
#compute means over replications
x <- rowMeans(sim_results_xc)
#compute standard errors over replications
y <- apply(sim_results_xc, 1, FUN = std_err)
for (i in 1:length(p_encode)){
res_mat[3,i] <- table_fun(x[i], y[i])
}
#Reproduction of Table 3
knitr::kable(cbind(Condition = c("Summation", "Control (1)", "Control (2)"), res_mat), col.names = c("Condition", round(p_encode, 2)), caption = "Reproduction of Table 3")
#Table 3 as reported by Jamieson et al. (2012)
data <- c("0.13 (.02)","0.18 (.02)","0.05 (.07)","0.93 (.01)","0.92 (.01)","0.89 (.02)", "0.99 (.00)", "0.99 (.00)", "1.0 (.00)")
res_mat2 <- matrix(data = data, nrow = 3, ncol = 3, byrow = TRUE)
knitr::kable(cbind(Condition = c("Summation", "Control (1)", "Control (2)"), res_mat2), col.names = c("Condition", round(p_encode, 2)), caption = "Table 3 as reported by Jamieson et al. (2012)")
```
```{r}
#----- diagnostic plots ------#
# par(mfrow=c(2,2))
#
# # memory encoding of the outcome over the trials
# plot(
# 1:n_trials
# , memory[, 101]
# , type = "l"
# , col = scales::alpha("black", 0.3)
# , ylim = c(-2, 2)
# , xlab = "Trial"
# , ylab = "Feature encoding"
# , main = "Features of outcome X"
# , las = 1
# )
# for(i in 102:120) {
# lines(
# 1:n_trials
# , memory[, i]
# , col = scales::alpha("black", 0.3)
# )
# }
#
# # memory encoding of cue A over the trials
# plot(
# 1:n_trials
# , memory[, 1]
# , type = "l"
# , col = scales::alpha("black", 0.3)
# , ylim = c(-2, 2)
# , xlab = "Trial"
# , ylab = "Feature encoding"
# , main = "Features of Cue A"
# , las = 1
# )
# for(i in 2:20) {
# lines(
# 1:n_trials
# , memory[, i]
# , col = scales::alpha("black", 0.3)
# )
# }
#
# # memory encoding of cue B over the trials
# plot(
# 1:n_trials
# , memory[, 21]
# , type = "l"
# , col = scales::alpha("black", 0.3)
# , ylim = c(-2, 2)
# , xlab = "Trial"
# , ylab = "Feature encoding"
# , main = "Features of Cue B"
# , las = 1
# )
# for(i in 21:40) {
# lines(
# 1:n_trials
# , memory[, i]
# , col = scales::alpha("black", 0.3)
# )
# }
#
# # memory encoding of cue C over the trials
# plot(
# 1:n_trials
# , memory[, 41]
# , type = "l"
# , col = scales::alpha("black", 0.3)
# , ylim = c(-2, 2)
# , xlab = "Trial"
# , ylab = "Feature encoding"
# , main = "Features of Cue C"
# , las = 1
# )
# for(i in 41:60) {
# lines(
# 1:n_trials
# , memory[, i]
# , col = scales::alpha("black", 0.3)
# )
# }
```
```{r}
# normalized echos over the trials
# libraries:
# library(ggplot2)
# library(gganimate)
#
#
# echos <- vector()
# for (i in 1:n_trials){
# echos <- c(echos,normalized_echos[[3,i,1]])
# }
#
# data <- data.frame(Stimuli = c(1:n_features), Echo = echos, frame = rep(1:n_trials, each = n_features))
#
#
# # Make an animated boxplot
# p <- ggplot(data, aes(x=Stimuli, y=Echo, fill=Stimuli)) +
# geom_bar(stat='identity') +
# theme_bw() +
# # gganimate specific bits:
# transition_states(
# states = frame,
# transition_length = 1,
# state_length = 1,
# wrap = TRUE
# )
#
# p <- p + ggtitle('Now showing Trial:{closest_state}')
# animate(p, nframes = 2*n_trials)
```