-
Notifications
You must be signed in to change notification settings - Fork 4
/
.Rhistory
180 lines (180 loc) · 6.04 KB
/
.Rhistory
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
require("gganim")
install.packages("gganim")
install.packages("gganimate")
require(pso)
#source("fit.R")
source("graphics.R")
order_dir = "orderings/"
model_dir = "models/"
data_dir = "data/"
# load lists of many trial orderings (and some means of human performance):
load(paste(order_dir,"master_orders.RData",sep='')) # orders
load(paste(order_dir,"asymmetric_conditions.RData",sep='')) # conds
print(names(orders))
print(names(conds))
load(paste(data_dir,"asym_master.RData",sep='')) # raw
run_model <- function(cond, model_name, parameters, print_perf=F) {
require(pso) # or require(DEoptim)
source(paste(model_dir,model_name,".R",sep=''))
mod = model(parameters, ord=cond$train)
if(print_perf) print(mod$perf)
return(mod)
}
View(animate_trajectory)
models
require(pso)
#source("fit.R")
source("graphics.R")
order_dir = "orderings/"
model_dir = "models/"
data_dir = "data/"
# load lists of many trial orderings (and some means of human performance):
load(paste(order_dir,"master_orders.RData",sep='')) # orders
load(paste(order_dir,"asymmetric_conditions.RData",sep='')) # conds
print(names(orders))
print(names(conds))
load(paste(data_dir,"asym_master.RData",sep='')) # raw
run_model <- function(cond, model_name, parameters, print_perf=F) {
require(pso) # or require(DEoptim)
source(paste(model_dir,model_name,".R",sep=''))
mod = model(parameters, ord=cond$train)
if(print_perf) print(mod$perf)
return(mod)
}
animate_trajectories <- function(models, conds, condnames, params) {
for(m in models) {
for(cname in condnames) {
mod = run_model(conds[[cname]], m, params, print_perf=T)
animate_trajectory(mod, m, cname)
}
}
}
models = c("kachergis", "strength", "uncertainty", "novelty", "Bayesian_decay", "rescorla_wagner")
condnames = c("orig_3x3","freq369-3x3hiCD","freq369-3x3loCD")
models = c("kachergis","fazly","rescorla-wagner")
params = list("kachergis"=c(0.02470323,0.4890386,0.977897), "fazly"=c(0.01557498,20000,0.1003937), "rescorla-wagner"=c(0.08853654,0.9636937,6.48722)) # best from cond 207 (arbitrarily) 4x4 + 2 w/o
animate_trajectories(models, orders, condnames, params)
mod = run_model(conds[["201"]], "kachergis", c(1,3,.97), print_perf=T)
mod
mod$matrix
mod$traj
n <- 9
z <- 6
trial_data <- rep(0:1, times = c(n - z, z))
d <-
d %>%
mutate(likelihood = bernoulli_likelihood(theta = theta,
data = trial_data))
require(tidyverse)
n <- 9
z <- 6
trial_data <- rep(0:1, times = c(n - z, z))
d <-
d %>%
mutate(likelihood = bernoulli_likelihood(theta = theta,
data = trial_data))
df <- read.csv(here('observed_data.csv'))
powerlaw <- function(t,u,a,c){
# assumes c<0
return(u - a *(t**c))
}
demo_learning_curve <- function() {
t = 1:20
u = 1
a = 1 # assume initial performance is 0
# (guessing on training trial would be 1-1/c; on test trial = 1-1/M)
c = -.30 # 'modest' learning rate
perf = u - a*t^c
plot(t, perf)
}
demo_learning_curve()
5^-.3
9^-.3
expression(fit~italic(y)~"="~italic(u - ax)^italic(c))
library(pso)
ord1 = as.matrix(read.table("orderings/TR1-hiCD.txt"))
load("orderings/master_orders.Rdata")
orders[[1]]
names(orders)
ord1 = as.matrix(read.table("orderings/3_x8_369_4x4.txt"))
ord2 = as.matrix(read.table("orderings/freq369-3x3loCD.txt"))
ord3 = as.matrix(read.table("orderings/freq369_36mx.txt"))
ord4 = as.matrix(read.table("orderings/freq369_39mx.txt"))
source("models/kachergis.R") # base_model
INIT_PAR = c(0.227, 1.176, 0.963) # filtering: SSE=0.177
lower = c(.001, .01, .1)
upper = c(40, 15, 1)
controls = list(maxit=200, max.restart=2, reltol=.001)
multinomial_likelihood_perfect <- function(par, ord) {
M = model(par, ord=ord)
pOgW = diag(M) / rowSums(M) # p(o|w)
lik = sum(log(pOgW))
return(-lik) # 18*log(1/18) = -52.02669 for AFC guessing; -16.63 for 8AFC
}
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect, ord=ord1, lower=lower, upper=upper, control=controls)
names(orders)
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect,
ord=orders[["3_x8_369_4x4"]],
lower=lower, upper=upper, control=controls)
model(INIT_PAR, ord=orders[[1]])
orders[[1]]$train
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect,
ord=orders[["3_x8_369_4x4"]]$train,
lower=lower, upper=upper, control=controls)
M = model(fit$par, ord=orders[["3_x8_369_4x4"]]$train) # maximal learning rate (60), lambda of ~2.6, high decay (alpha=.6)
M = model(INIT_PAR, ord=orders[["3_x8_369_4x4"]]$train) # maximal learning rate (60), lambda of ~2.6, high decay (alpha=.6)
M
M$matrix
M$perf
diag(M$matrix) / rowSums(M$matrix)
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect,
ord=orders[["3_x8_369_4x4"]]$train,
lower=lower, upper=upper, control=controls)
multinomial_likelihood_perfect <- function(par, ord) {
#M = model(par, ord=ord)
pOgW = diag(M) / rowSums(M) # p(o|w)
pOgW = M$perf
lik = sum(log(pOgW))
return(-lik) # 18*log(1/18) = -52.02669 for AFC guessing; -16.63 for 8AFC
}
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect,
ord=orders[["3_x8_369_4x4"]]$train,
lower=lower, upper=upper, control=controls)
INIT_PAR = c(0.227, 1.176, 0.963) # filtering: SSE=0.177
lower = c(.001, .01, .1)
upper = c(40, 15, 1)
controls = list(maxit=200, max.restart=2, reltol=.001)
multinomial_likelihood_perfect <- function(par, ord) {
M = model(par, ord=ord)
#pOgW = diag(M) / rowSums(M)
pOgW = M$perf # p(o|w)
lik = sum(log(pOgW))
return(-lik) # 18*log(1/18) = -52.02669 for AFC guessing; -16.63 for 8AFC
}
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect,
ord=orders[["3_x8_369_4x4"]]$train,
lower=lower, upper=upper, control=controls)
M = model(fit$par, ord=orders[["3_x8_369_4x4"]]$train) # maximal learning rate (60), lambda of ~2.6, high decay (alpha=.6)
mean(M$perf)
M
fit$par
require(tidyverse)
M
fit$par
high_perf = tibble()
for(o in names(orders)) {
fit <- psoptim(INIT_PAR, multinomial_likelihood_perfect,
ord=orders[[o]]$train,
lower=lower, upper=upper, control=controls)
M = model(fit$par, ord=orders[[o]]$train)
high_perf <- high_perf %>%
bind_rows(bind_cols(cond = o, perf = mean(M$perf),
chi=fit$par[1], lambda=fit$par[2], alpha=fit$par[3]))
}
high_perf
upper
View(high_perf)
INIT_PAR = c(0.227, 1.176, 0.963) # filtering: SSE=0.177
lower = c(.001, .01, .1)
upper = c(10, 15, 1)
controls = list(maxit=200, max.restart=2, reltol=.001)